Skip to content

chore: Fixes #71 #73

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

Merged
merged 3 commits into from
Nov 30, 2017
Merged
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
78 changes: 52 additions & 26 deletions examples/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,10 @@
import java.util.Map;

public class Example {
public static void main(String[] args) throws IOException {
Client client = new Client();

Request request = new Request();
request.setBaseUri("api.sendgrid.com");
request.addHeader("Authorization", "Bearer " + System.getenv("SENDGRID_API_KEY"));

Response response = new Response();

// GET Collection

private static String apiKeyId = "";

private static void getCollection(Client client, Request request) throws IOException {
request.setMethod(Method.GET);
request.setEndpoint("/v3/api_keys");
request.addQueryParam("limit", "100");
Expand All @@ -33,8 +27,9 @@ public static void main(String[] args) throws IOException {
throw ex;
}
request.clearQueryParams();

// POST
}

private static void post(Client client, Request request) throws IOException {
request.setMethod(Method.POST);
request.setEndpoint("/v3/api_keys");
request.setBody("{\"name\": \"My api Key\",\"scopes\": [\"mail.send\",\"alerts.create\",\"alerts.read\"]}");
Expand All @@ -52,45 +47,76 @@ public static void main(String[] args) throws IOException {
} catch (IOException ex) {
throw ex;
}
request.clearBody();

// GET Single
request.clearBody();
}

private static void getSingle(Client client, Request request) throws IOException {
request.setMethod(Method.GET);
request.setEndpoint("/v3/api_keys/" + apiKeyId);
try {
processResponse();
} catch (IOException ex) {
throw ex;
}

// PATCH
}
}

private static void patch(Client client, Request request) throws IOException {
request.setMethod(Method.PATCH);
request.setBody("{\"name\": \"A New Ho}");
try {
processResponse();
} catch (IOException ex) {
throw ex;
}
request.clearBody();

// PUT
request.clearBody();
}

private static void put(Client client, Request request) throws IOException {
request.setMethod(Method.PUT);
request.setBody("{\"name\": \"A New Hope\",\"scopes\": [\"user.profile.read\",\"user.profile.update\"]}");
try {
processResponse();
} catch (IOException ex) {
throw ex;
}
request.clearBody();

// DELETE
request.clearBody();
}

private static void delete(Client client, Request request) throws IOException {
request.setMethod(Method.DELETE);
try {
response = client.api(request);
Response response = client.api(request);
System.out.println(response.getStatusCode());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
}
}

public static void main(String[] args) throws IOException {
Client client = new Client();

Request request = new Request();
request.setBaseUri("api.sendgrid.com");
request.addHeader("Authorization", "Bearer " + System.getenv("SENDGRID_API_KEY"));

// GET Collection
getCollection(client, request);

// POST
post(client, request);

// GET Single
getSingle(client, request);

// PATCH
patch(client, request);

// PUT
put(client, request);

// DELETE
delete(client, request);
}

//Refactor method
Expand Down