This repository has been archived by the owner on Jan 15, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ardevd/1-profiledata
Implemented the /profile API for user profile data parsing
- Loading branch information
Showing
15 changed files
with
381 additions
and
96 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
47 changes: 47 additions & 0 deletions
47
app/src/main/java/no/aegisdynamics/habitat/data/profile/ProfileDataHelper.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,47 @@ | ||
package no.aegisdynamics.habitat.data.profile; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Helper class for parsing profile data from JSON API. | ||
*/ | ||
public class ProfileDataHelper { | ||
|
||
private ProfileDataHelper() { | ||
// Empty constructor | ||
} | ||
|
||
/** | ||
* Parse profile data from JSONObject. | ||
* @param dataObject JSONObject containing profile data from Z-Way API | ||
* @return valid user Profile object. | ||
*/ | ||
public static Profile getProfileFromJsonData(JSONObject dataObject) { | ||
|
||
try { | ||
int profileId = dataObject.getInt("id"); | ||
String profileUserName = dataObject.getString("login"); | ||
String profileEmail = dataObject.getString("email"); | ||
String profileName = dataObject.getString("name"); | ||
|
||
// parse dashboard devices | ||
JSONArray dashboardDevices = dataObject.getJSONArray("dashboard"); | ||
List<String> dashboardDevicesList = new ArrayList<>(); | ||
for (int i = 0; i < dashboardDevices.length(); i++) { | ||
dashboardDevicesList.add(dashboardDevices.getString(i)); | ||
} | ||
|
||
return new Profile(profileId, profileUserName, profileName, profileEmail, | ||
dashboardDevicesList); | ||
} catch (JSONException ex) { | ||
return null; | ||
} | ||
|
||
|
||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
app/src/main/java/no/aegisdynamics/habitat/util/VolleyResponseHelper.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,23 @@ | ||
package no.aegisdynamics.habitat.util; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
/** | ||
* Helper class for Volley response handling | ||
*/ | ||
public class VolleyResponseHelper { | ||
|
||
private VolleyResponseHelper() { | ||
// empty constructor | ||
} | ||
|
||
public static boolean hasResponseReturnedOK(JSONObject response) { | ||
try { | ||
int responseCode = response.getInt("code"); | ||
return responseCode == 200; | ||
} catch (JSONException ex) { | ||
return false; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.