Skip to content

Commit

Permalink
chore: fixed request and response (#752)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbansla authored Jun 23, 2024
1 parent 662d24d commit ea25cbc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
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

0 comments on commit ea25cbc

Please sign in to comment.