Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fixed request and response #752

Merged
merged 1 commit into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/com/sendgrid/constant/ApplicationConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.sendgrid.constant;

import java.util.function.Predicate;

public class ApplicationConstants {
public static final Predicate<Integer> SUCCESS = i -> i != null && i >= 200 && i < 400;
}
17 changes: 6 additions & 11 deletions src/main/java/com/sendgrid/http/ApiResponse.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
package com.sendgrid.http;

import lombok.Getter;

import org.apache.http.Header;
import java.util.Map;
import java.util.StringJoiner;

public class ApiResponse<T> {
@Getter
private Integer statusCode;
@Getter
private String statusMessage;
@Getter
private T body;
@Getter
private Map<String, String> headers;
private Header[] headers;


public ApiResponse(int statusCode, String statusMessage, Map<String, String> headers) {
public ApiResponse(int statusCode, Header[] headers) {
this.body = null;
this.headers = headers;
this.statusCode = statusCode;
this.statusMessage = statusMessage;
}

public ApiResponse(int statusCode, String statusMessage, T body, Map<String, String> headers) {
public ApiResponse(int statusCode, T body, Header[] headers) {
this.statusCode = statusCode;
this.statusMessage = statusMessage;
this.body = body;
this.headers = headers;
}
Expand All @@ -34,9 +30,8 @@ public ApiResponse(int statusCode, String statusMessage, T body, Map<String, Str
public String toString() {
StringJoiner joiner = new StringJoiner(", ", ApiResponse.class.getSimpleName() + "(", ")");
if (statusCode != null) joiner.add("statusCode=" + statusCode);
if (statusMessage != null) joiner.add("statusMessage=" + statusMessage);
if (statusMessage != null) joiner.add("body=" + body);
if (statusMessage != null) joiner.add("headers=" + headers);
if (headers != null) joiner.add("headers=" + headers);
if (body != null) joiner.add("body=" + body);
return joiner.toString();
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/sendgrid/http/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Builder addPathParam(String key, String value) {
return this;
}

public Builder addHeaderParams(String key, String value) {
public Builder addHeaderParam(String key, String value) {
headers.put(key, value);
return this;
}
Expand All @@ -80,7 +80,7 @@ public Builder addQueryParams(String key, String value) {
return this;
}

public Builder body(String body) {
public Builder addBody(String body) {
this.body = body;
return this;
}
Expand Down
Loading