Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added support for device entity

  • Loading branch information...
commit e49581754488bdd17b431fe933930e4228422c6b 1 parent 892d9f8
@edanuff edanuff authored
View
7 README.txt
@@ -4,3 +4,10 @@ Usergrid Android Client
Experimental Android client for Usergrid. Basically uses Spring Android and
Jackson to wrap calls to Usergrid REST API. Loosely based on the Usergrid
Javascript client.
+
+Requires the following permissions:
+
+ <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.READ_PHONE_STATE" />
+ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+
View
28 src/main/java/org/usergrid/android/client/Client.java
@@ -1,14 +1,16 @@
package org.usergrid.android.client;
-import static org.usergrid.android.client.Utils.addQueryParams;
-import static org.usergrid.android.client.Utils.encodeParams;
-import static org.usergrid.android.client.Utils.isEmpty;
-import static org.usergrid.android.client.Utils.path;
+import static org.usergrid.android.client.utils.JsonUtils.parse;
+import static org.usergrid.android.client.utils.ObjectUtils.isEmpty;
+import static org.usergrid.android.client.utils.UrlUtils.addQueryParams;
+import static org.usergrid.android.client.utils.UrlUtils.encodeParams;
+import static org.usergrid.android.client.utils.UrlUtils.path;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
import org.codehaus.jackson.node.JsonNodeFactory;
import org.springframework.http.HttpEntity;
@@ -18,11 +20,14 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
+import org.usergrid.android.client.entities.Device;
import org.usergrid.android.client.entities.Entity;
import org.usergrid.android.client.entities.Group;
import org.usergrid.android.client.entities.User;
import org.usergrid.android.client.response.ApiResponse;
+import org.usergrid.android.client.utils.DeviceUuidFactory;
+import android.content.Context;
import android.util.Log;
/**
@@ -299,8 +304,7 @@ public ApiResponse apiRequest(HttpMethod method,
Log.e(TAG,
"Client.apiRequest(): HTTP error: "
+ e.getLocalizedMessage());
- response = Utils.parse(e.getResponseBodyAsString(),
- ApiResponse.class);
+ response = parse(e.getResponseBodyAsString(), ApiResponse.class);
if ((response != null) && !isEmpty(response.getError())) {
Log.e(TAG,
"Client.apiRequest(): Response error: "
@@ -398,6 +402,18 @@ public ApiResponse authorizeAppClient(String clientId, String clientSecret) {
return response;
}
+ public Device registerDevice(Context context, Map<String, Object> properties) {
+ assertValidApplicationId();
+ UUID deviceId = new DeviceUuidFactory(context).getDeviceUuid();
+ if (properties == null) {
+ properties = new HashMap<String, Object>();
+ }
+ properties.put("refreshed", System.currentTimeMillis());
+ ApiResponse response = apiRequest(HttpMethod.PUT, null, properties,
+ applicationId, "devices", deviceId.toString());
+ return response.getFirstEntity(Device.class);
+ }
+
public ApiResponse createEntity(Entity entity) {
assertValidApplicationId();
if (isEmpty(entity.getType())) {
Please sign in to comment.
Something went wrong with that request. Please try again.