Skip to content

Commit d312a29

Browse files
author
Matt Bernier
authored
Merge pull request #77 from lanre01/patch-1
Closes #72 Update Example.java
2 parents fa1f9a5 + b7200b0 commit d312a29

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

examples/Example.java

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ public static void main(String[] args) throws IOException {
2828
request.addQueryParam("limit", "100");
2929
request.addQueryParam("offset", "0");
3030
try {
31-
response = client.api(request);
32-
System.out.println(response.getStatusCode());
33-
System.out.println(response.getBody());
34-
System.out.println(response.getHeaders());
31+
processResponse();
3532
} catch (IOException ex) {
3633
throw ex;
3734
}
@@ -43,10 +40,7 @@ public static void main(String[] args) throws IOException {
4340
request.setBody("{\"name\": \"My api Key\",\"scopes\": [\"mail.send\",\"alerts.create\",\"alerts.read\"]}");
4441

4542
try {
46-
response = client.api(request);
47-
System.out.println(response.getStatusCode());
48-
System.out.println(response.getBody());
49-
System.out.println(response.getHeaders());
43+
processResponse();
5044
} catch (IOException ex) {
5145
throw ex;
5246
}
@@ -64,10 +58,7 @@ public static void main(String[] args) throws IOException {
6458
request.setMethod(Method.GET);
6559
request.setEndpoint("/v3/api_keys/" + apiKeyId);
6660
try {
67-
response = client.api(request);
68-
System.out.println(response.getStatusCode());
69-
System.out.println(response.getBody());
70-
System.out.println(response.getHeaders());
61+
processResponse();
7162
} catch (IOException ex) {
7263
throw ex;
7364
}
@@ -76,10 +67,7 @@ public static void main(String[] args) throws IOException {
7667
request.setMethod(Method.PATCH);
7768
request.setBody("{\"name\": \"A New Ho}");
7869
try {
79-
response = client.api(request);
80-
System.out.println(response.getStatusCode());
81-
System.out.println(response.getBody());
82-
System.out.println(response.getHeaders());
70+
processResponse();
8371
} catch (IOException ex) {
8472
throw ex;
8573
}
@@ -89,11 +77,7 @@ public static void main(String[] args) throws IOException {
8977
request.setMethod(Method.PUT);
9078
request.setBody("{\"name\": \"A New Hope\",\"scopes\": [\"user.profile.read\",\"user.profile.update\"]}");
9179
try {
92-
response = client.api(request);
93-
System.out.println(response.getStatusCode());
94-
System.out.println(response.getBody());
95-
System.out.println(response.getHeaders());
96-
} catch (IOException ex) {
80+
processResponse();
9781
throw ex;
9882
}
9983
request.clearBody();
@@ -108,4 +92,12 @@ public static void main(String[] args) throws IOException {
10892
throw ex;
10993
}
11094
}
111-
}
95+
96+
//Refactor method
97+
private void processResponse(){
98+
response = client.api(request);
99+
System.out.println(response.getStatusCode());
100+
System.out.println(response.getBody());
101+
System.out.println(response.getHeaders());
102+
}
103+
}

0 commit comments

Comments
 (0)