This repository has been archived by the owner on Aug 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…closed #8
- Loading branch information
1 parent
6c87af3
commit 3ed2829
Showing
6 changed files
with
132 additions
and
27 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
73 changes: 73 additions & 0 deletions
73
app/src/main/java/nuesoft/restfulpy/client/webService/Response.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,73 @@ | ||
package nuesoft.restfulpy.client.webService; | ||
|
||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Created by mysterious on 8/23/17. | ||
*/ | ||
|
||
public class Response { | ||
|
||
private okhttp3.Response response; | ||
|
||
//Saving because string() method can call just once | ||
private String body; | ||
|
||
private String json; | ||
|
||
public Response(okhttp3.Response response) { | ||
|
||
try { | ||
this.response = response; | ||
this.body = response.body().string(); | ||
this.json = null; | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public int getStatus() { | ||
|
||
return this.response.code(); | ||
} | ||
|
||
public String getHeader(String key) { | ||
|
||
return this.response.headers().get(key); | ||
} | ||
|
||
public String getIdentity() { | ||
|
||
return this.getHeader("X-Identity"); | ||
} | ||
|
||
public boolean isAuthenticated() { | ||
|
||
return getIdentity() != null; | ||
} | ||
|
||
public String getBody() { | ||
|
||
if (this.getStatus() == 200 && this.body != null) | ||
return this.body; | ||
|
||
return null; | ||
} | ||
|
||
public String getField(String name) { | ||
//TODO check for json array | ||
JSONObject jsonObj = null; | ||
try { | ||
jsonObj = new JSONObject(this.getBody()); | ||
String value = (String) jsonObj.get(name); | ||
return value; | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
} |