@@ -28,10 +28,7 @@ public static void main(String[] args) throws IOException {
28
28
request .addQueryParam ("limit" , "100" );
29
29
request .addQueryParam ("offset" , "0" );
30
30
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 ();
35
32
} catch (IOException ex ) {
36
33
throw ex ;
37
34
}
@@ -43,10 +40,7 @@ public static void main(String[] args) throws IOException {
43
40
request .setBody ("{\" name\" : \" My api Key\" ,\" scopes\" : [\" mail.send\" ,\" alerts.create\" ,\" alerts.read\" ]}" );
44
41
45
42
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 ();
50
44
} catch (IOException ex ) {
51
45
throw ex ;
52
46
}
@@ -64,10 +58,7 @@ public static void main(String[] args) throws IOException {
64
58
request .setMethod (Method .GET );
65
59
request .setEndpoint ("/v3/api_keys/" + apiKeyId );
66
60
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 ();
71
62
} catch (IOException ex ) {
72
63
throw ex ;
73
64
}
@@ -76,10 +67,7 @@ public static void main(String[] args) throws IOException {
76
67
request .setMethod (Method .PATCH );
77
68
request .setBody ("{\" name\" : \" A New Ho}" );
78
69
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 ();
83
71
} catch (IOException ex ) {
84
72
throw ex ;
85
73
}
@@ -89,11 +77,7 @@ public static void main(String[] args) throws IOException {
89
77
request .setMethod (Method .PUT );
90
78
request .setBody ("{\" name\" : \" A New Hope\" ,\" scopes\" : [\" user.profile.read\" ,\" user.profile.update\" ]}" );
91
79
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 ();
97
81
throw ex ;
98
82
}
99
83
request .clearBody ();
@@ -108,4 +92,12 @@ public static void main(String[] args) throws IOException {
108
92
throw ex ;
109
93
}
110
94
}
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