Skip to content

Commit

Permalink
Merge pull request #33 from sashirestela/release_0_12
Browse files Browse the repository at this point in the history
Release 0.12.0
  • Loading branch information
sashirestela authored Dec 28, 2023
2 parents 3dc431e + f36f50f commit b8a44de
Show file tree
Hide file tree
Showing 36 changed files with 770 additions and 745 deletions.
26 changes: 26 additions & 0 deletions .devfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
schemaVersion: 2.2.2
metadata:
attributes:
metadata-name-field: generateName
metadata-name-original-value: cleverclient
name: cleverclient
namespace: sashirestela-dev
attributes:
che-theia.eclipse.org/sidecar-policy: mergeImage
projects:
- name: cleverclient
git:
remotes:
origin: https://github.com/sashirestela/cleverclient.git
components:
- name: universal-developer-image
container:
image: quay.io/devfile/universal-developer-image:ubi8-latest
volumeMounts:
- name: m2
path: /home/user/.m2
mountSources: true
- name: m2
volume:
size: 5Gi
commands: []
3 changes: 3 additions & 0 deletions .sdkmanrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Enable auto-env through the sdkman_auto_env config
# Add key=value pairs of SDKs to use below
java=11.0.15-tem
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.sashirestela</groupId>
<artifactId>cleverclient</artifactId>
<version>0.11.1</version>
<version>0.12.0</version>
<packaging>jar</packaging>

<name>cleverclient</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public static void main(String[] args) {
.build());
System.out.println(editPost);

showTitle("Example Patch Post");
var patchPost = postService.patchPost(postId, Post.builder()
.title("Godbye")
.build());
System.out.println(patchPost);

showTitle("Example Delete Post");
postService.deletePost(postId);
System.out.println("Post was deleted");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.github.sashirestela.cleverclient.example.jsonplaceholder;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -9,6 +12,7 @@
@AllArgsConstructor
@Builder
@Data
@JsonInclude(Include.NON_NULL)
public class Post {
private Integer id;
private String title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.github.sashirestela.cleverclient.annotation.Body;
import io.github.sashirestela.cleverclient.annotation.DELETE;
import io.github.sashirestela.cleverclient.annotation.GET;
import io.github.sashirestela.cleverclient.annotation.PATCH;
import io.github.sashirestela.cleverclient.annotation.POST;
import io.github.sashirestela.cleverclient.annotation.PUT;
import io.github.sashirestela.cleverclient.annotation.Path;
Expand All @@ -26,6 +27,9 @@ public interface PostService {
@PUT("/{postId}")
Post updatePost(@Path("postId") Integer postId, @Body Post post);

@PATCH("/{postId}")
Post patchPost(@Path("postId") Integer postId, @Body Post post);

@DELETE("/{postId}")
Post deletePost(@Path("postId") Integer postId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,29 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;
import lombok.Singular;

@Getter
public class CleverClient {
private static Logger logger = LoggerFactory.getLogger(CleverClient.class);

@NonNull
private String urlBase;

private List<String> headers;
private HttpClient httpClient;
private HttpProcessor httpProcessor;

@Builder
public CleverClient(String urlBase, List<String> headers, HttpClient httpClient, String endOfStream) {
public CleverClient(@NonNull String urlBase, @Singular List<String> headers, HttpClient httpClient,
String endOfStream) {
this.urlBase = urlBase;
this.headers = Optional.ofNullable(headers).orElse(List.of());
this.httpClient = Optional.ofNullable(httpClient).orElse(HttpClient.newHttpClient());
CleverClientSSE.setEndOfStream(endOfStream);
this.httpProcessor = new HttpProcessor(this.httpClient, this.urlBase, this.headers);
logger.debug("CleverClient has been created.");
}

public <T> T create(Class<T> interfaceClass) {
var httpProcessor = new HttpProcessor(this.httpClient, this.urlBase, this.headers);
return httpProcessor.createProxy(interfaceClass);
return this.httpProcessor.createProxy(interfaceClass);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.lang.annotation.Target;

@Documented
@HttpMethod
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface DELETE {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.lang.annotation.Target;

@Documented
@HttpMethod
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface GET {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.sashirestela.cleverclient.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
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface HttpMethod {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.github.sashirestela.cleverclient.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
@HttpMethod
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface PATCH {
String value() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.lang.annotation.Target;

@Documented
@HttpMethod
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface POST {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.lang.annotation.Target;

@Documented
@HttpMethod
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface PUT {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import io.github.sashirestela.cleverclient.sender.HttpSenderFactory;
import io.github.sashirestela.cleverclient.util.JsonUtil;
import io.github.sashirestela.cleverclient.util.ReflectUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;

Expand Down Expand Up @@ -58,7 +57,7 @@ private BodyPublisher createBodyPublisher(Object bodyObject, boolean isMultipart
logger.debug("Request Body : (Empty)");
bodyPublisher = BodyPublishers.noBody();
} else if (isMultipart) {
var data = ReflectUtil.getMapFields(bodyObject);
var data = JsonUtil.objectToMap(bodyObject);
var requestBytes = HttpMultipart.toByteArrays(data);
logger.debug("Request Body : {}", data);
bodyPublisher = BodyPublishers.ofByteArrays(requestBytes);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.sashirestela.cleverclient.http;

import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -29,12 +30,12 @@ public static List<byte[]> toByteArrays(Map<String, Object> data) {
byteArrays.add(toBytes(DASH + Constant.BOUNDARY_VALUE + NL));
byteArrays.add(toBytes(DISPOSITION));
var fieldName = entry.getKey();
if (entry.getValue() instanceof Path) {
if (isFile(entry.getValue())) {
String fileName = null;
String mimeType = null;
byte[] fileContent = null;
try {
var path = (Path) entry.getValue();
var path = Path.of(new URL((String) entry.getValue()).getPath());
fileName = path.toString();
mimeType = Files.probeContentType(path);
fileContent = Files.readAllBytes(path);
Expand All @@ -60,4 +61,10 @@ public static List<byte[]> toByteArrays(Map<String, Object> data) {
private static byte[] toBytes(String text) {
return text.getBytes(StandardCharsets.UTF_8);
}

private static boolean isFile(Object value) {
final String FILE_PROTOCOL = "file:";
return value instanceof String
&& ((String) value).startsWith(FILE_PROTOCOL);
}
}
Loading

0 comments on commit b8a44de

Please sign in to comment.