-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
808cb53
commit d4cd70c
Showing
18 changed files
with
141 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...ay-api-client/src/main/java/org/stingraymappingproject/api/clientandroid/GsonRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.stingraymappingproject.api.clientandroid; | ||
|
||
import com.android.volley.NetworkResponse; | ||
import com.android.volley.ParseError; | ||
import com.android.volley.Request; | ||
import com.android.volley.Response; | ||
import com.android.volley.toolbox.HttpHeaderParser; | ||
import com.google.gson.Gson; | ||
import com.google.gson.JsonSyntaxException; | ||
|
||
import org.json.JSONObject; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
|
||
/** | ||
* Created by Marvin Arnold on 23/08/15. | ||
*/ | ||
public class GsonRequest<T> extends Request<T> { | ||
public JSONObject getJsonObject() { | ||
return mRequestJsonObject; | ||
} | ||
public Response.Listener getSuccessListener() { | ||
return mSuccessListener; | ||
} | ||
|
||
protected final Gson mGson; | ||
|
||
/** class of type of response */ | ||
protected final Class<T> mClazz; | ||
private final JSONObject mRequestJsonObject; | ||
private final Response.Listener mSuccessListener; | ||
|
||
public GsonRequest(JSONObject jsonObject, | ||
String requestUrl, | ||
int method, | ||
Response.Listener<T> successListener, | ||
Response.ErrorListener errorListener, | ||
Class<T> responseClazz) { | ||
super(method, requestUrl, errorListener); | ||
|
||
this.mRequestJsonObject = jsonObject; | ||
this.mSuccessListener = successListener; | ||
this.mGson = new Gson(); | ||
this.mClazz = responseClazz; | ||
} | ||
|
||
@Override | ||
protected Response<T> parseNetworkResponse(NetworkResponse response) { | ||
try { | ||
String json = new String( | ||
response.data, HttpHeaderParser.parseCharset(response.headers)); | ||
return Response.success( | ||
mGson.fromJson(json, mClazz), HttpHeaderParser.parseCacheHeaders(response)); | ||
} catch (UnsupportedEncodingException e) { | ||
return Response.error(new ParseError(e)); | ||
} catch (JsonSyntaxException e) { | ||
return Response.error(new ParseError(e)); | ||
} | ||
} | ||
|
||
@Override | ||
protected void deliverResponse(T response) { | ||
this.mSuccessListener.onResponse(response); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...api-client/src/main/java/org/stingraymappingproject/api/clientandroid/models/Factoid.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.stingraymappingproject.api.clientandroid.models; | ||
|
||
/** | ||
* Created by Marvin Arnold on 24/08/15. | ||
*/ | ||
public class Factoid { | ||
String id; | ||
|
||
public String getFact() { | ||
return fact; | ||
} | ||
|
||
String fact; | ||
String created_at; | ||
} |
18 changes: 0 additions & 18 deletions
18
.../main/java/org/stingraymappingproject/api/clientandroid/params/FactoidsRequestParams.java
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
...a/org/stingraymappingproject/api/clientandroid/params/JsonArrayResponseRequestParams.java
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
.../org/stingraymappingproject/api/clientandroid/params/JsonObjectResponseRequestParams.java
This file was deleted.
Oops, something went wrong.
48 changes: 0 additions & 48 deletions
48
...ient/src/main/java/org/stingraymappingproject/api/clientandroid/params/RequestParams.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.