1
1
package com .amit .api ;
2
2
3
+ import android .annotation .SuppressLint ;
3
4
import android .content .Context ;
4
5
import android .graphics .Bitmap ;
5
6
import android .graphics .BitmapFactory ;
18
19
import java .net .HttpURLConnection ;
19
20
import java .net .URL ;
20
21
21
- /*
22
- * Created By AMIT JANGID
23
- * 2018 April 17 - Tuesday - 12:56 PM
22
+ /**
23
+ * Created By AMIT JANGID
24
+ * 2018 April 17 - Tuesday - 12:56 PM
24
25
**/
25
-
26
+ @ SuppressWarnings ("unused" )
27
+ @ SuppressLint ("HardwareIds" )
26
28
public class ApiServices
27
29
{
28
30
private static final String TAG = ApiServices .class .getSimpleName ();
29
31
30
- public int mResponseCode = 0 ;
31
32
private String apiPath , mDeviceID ;
32
33
private SharedPreferenceData sharedPreferenceData ;
33
34
@@ -130,13 +131,13 @@ private String capitalizeString(String string)
130
131
* - if the api requires token then this has to be true
131
132
* - if the api doesn't require token then this has to be false
132
133
*
133
- * @return String which contains result from API.
134
+ * @return Pair of integer and string which contains response value and response code from the server
134
135
*
135
136
************************************************************************************************
136
137
**/
137
- public String makeAPICall (final String apiName , final String requestMethod ,
138
- final boolean parameters , final JSONObject values ,
139
- final boolean hasToken )
138
+ public Pair < Integer , String > makeAPICall (final String apiName , final String requestMethod ,
139
+ final boolean parameters , final JSONObject values ,
140
+ final boolean hasToken )
140
141
{
141
142
try
142
143
{
@@ -155,7 +156,7 @@ public String makeAPICall(final String apiName, final String requestMethod,
155
156
Log .e (TAG , "makeAPICall: x-access-token is: " + sharedPreferenceData .getValue ("token" ));
156
157
}
157
158
158
- httpURLConnection .setConnectTimeout (10000 );
159
+ // httpURLConnection.setConnectTimeout(10000);
159
160
httpURLConnection .setRequestProperty ("Connection" , "close" );
160
161
Log .e (TAG , "makeAPICall: api = " + url + " values = " + values );
161
162
@@ -169,8 +170,6 @@ public String makeAPICall(final String apiName, final String requestMethod,
169
170
}
170
171
171
172
int responseCode = httpURLConnection .getResponseCode ();
172
- mResponseCode = responseCode ;
173
- Log .e (TAG , "makeAPICall: response code from api is: " + mResponseCode );
174
173
175
174
if (responseCode == 200 )
176
175
{
@@ -185,6 +184,7 @@ public String makeAPICall(final String apiName, final String requestMethod,
185
184
186
185
bufferedReader .close ();
187
186
result = stringBuilder .toString ();
187
+ httpURLConnection .disconnect ();
188
188
Log .e (TAG , "makeAPICall: result from server is: " + result );
189
189
}
190
190
else
@@ -206,7 +206,7 @@ public String makeAPICall(final String apiName, final String requestMethod,
206
206
httpURLConnection .disconnect ();
207
207
}
208
208
209
- return result ;
209
+ return new Pair <>( responseCode , result ) ;
210
210
}
211
211
catch (Exception e )
212
212
{
@@ -217,7 +217,7 @@ public String makeAPICall(final String apiName, final String requestMethod,
217
217
}
218
218
219
219
/**
220
- * Get Bitmap Data
220
+ * Get Bitmap Image from Server method
221
221
*
222
222
* this method gets bitmap image from the server
223
223
* this can be used to download the image from server or api
@@ -233,7 +233,7 @@ public String makeAPICall(final String apiName, final String requestMethod,
233
233
* and bitmap will be the file uploaded.
234
234
*
235
235
**/
236
- public Pair <Integer , Bitmap > getBitmapData (String apiPath , String requestType , String parameter )
236
+ public Pair <Integer , Bitmap > getBitmapImageFromServer (String apiPath , String requestType , String parameter )
237
237
{
238
238
Bitmap resultVal = null ;
239
239
InputStream iStream ;
0 commit comments