-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
145 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.devlive.lightcall.annotation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Documented | ||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Post | ||
{ | ||
String value() default ""; | ||
} |
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
src/main/java/org/devlive/lightcall/processor/PostProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.devlive.lightcall.processor; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.extern.slf4j.Slf4j; | ||
import okhttp3.HttpUrl; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import okhttp3.RequestBody; | ||
import org.devlive.lightcall.RequestContext; | ||
import org.devlive.lightcall.annotation.Post; | ||
import org.devlive.lightcall.error.ErrorHandler; | ||
import org.devlive.lightcall.interceptor.Interceptor; | ||
|
||
import java.util.List; | ||
|
||
@Slf4j | ||
public class PostProcessor | ||
extends AbstractMethodProcessor<Post> | ||
{ | ||
private PostProcessor(OkHttpClient client, ObjectMapper objectMapper, List<Interceptor> interceptors, List<ErrorHandler> errorHandlers) | ||
{ | ||
super(client, objectMapper, interceptors, errorHandlers); | ||
} | ||
|
||
public static PostProcessor create(OkHttpClient client, ObjectMapper objectMapper, List<Interceptor> interceptors, List<ErrorHandler> errorHandlers) | ||
{ | ||
return new PostProcessor(client, objectMapper, interceptors, errorHandlers); | ||
} | ||
|
||
@Override | ||
public Class<Post> getAnnotationType() | ||
{ | ||
return Post.class; | ||
} | ||
|
||
@Override | ||
protected String getPath(Post annotation) | ||
{ | ||
return annotation.value(); | ||
} | ||
|
||
@Override | ||
protected Request buildRequest(HttpUrl url, RequestContext context) | ||
{ | ||
return context.getRequestBuilder() | ||
.url(url) | ||
.post(RequestBody.create(null, "")) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
...evlive/lightcall/example/PostService.java → ...ive/lightcall/example/get/GetService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...e/lightcall/example/LightCallGetTest.java → ...lightcall/example/get/GetServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/test/java/org/devlive/lightcall/example/post/PostService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.devlive.lightcall.example.post; | ||
|
||
import org.devlive.lightcall.annotation.Post; | ||
|
||
public interface PostService | ||
{ | ||
@Post("/posts") | ||
org.devlive.lightcall.example.Post createPost(org.devlive.lightcall.example.Post post); | ||
} |
22 changes: 22 additions & 0 deletions
22
src/test/java/org/devlive/lightcall/example/post/PostServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.devlive.lightcall.example.post; | ||
|
||
import org.devlive.lightcall.LightCall; | ||
import org.devlive.lightcall.config.LightCallConfig; | ||
import org.devlive.lightcall.example.Post; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class PostServiceTest | ||
{ | ||
private final LightCallConfig config = LightCallConfig.create("https://jsonplaceholder.typicode.com"); | ||
private final PostService service = LightCall.create(PostService.class, config); | ||
|
||
@Test | ||
void createPost() | ||
{ | ||
Post post = Post.create() | ||
.title("测试创建新的数据") | ||
.userId(1L) | ||
.body("这是测试数据"); | ||
System.out.println(service.createPost(post)); | ||
} | ||
} |