Skip to content

Instantly share code, notes, and snippets.

@leadVisionary
Created March 2, 2012 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leadVisionary/1954920 to your computer and use it in GitHub Desktop.
Save leadVisionary/1954920 to your computer and use it in GitHub Desktop.
Clean Boundaries for 3rd party APIs
package com.quantumaspects
import groovyx.net.http.*
import net.sf.json.JSONArray
abstract class AbstractParseAPI implements ParseAPI {
public Collection retrieve(String parseEntity){
return retrieveFromParse(parseEntity)
}
private def retrieveFromParse(String parseEntity) {
def client = buildRequest()
def url = (parseEntity == "User")? "users" : "classes/${parseEntity}"
def response = client.get(path : url)
JSONArray.toCollection(response.data.results)
}
private def buildRequest(){
def http = new RESTClient("${API_URL}")
http.headers = [
"X-Parse-Application-Id": applicationId,
"X-Parse-REST-API-Key" : key,
"Content-Type" : 'application/json'
]
return http
}
}
package com.visionarysoftwaresolutions;
import java.util.Collection;
public interface DatastoreAPI {
Collection retrieve(String parseEntity);
}
package com.visionarysoftwaresolutions;
import java.util.Map;
public interface ParseAPI extends DatastoreAPI {
final String API_URL = "https://api.parse.com/1/";
String applicationId = "";
String key = "";
public String createUser(String username, String password);
public String createObject(String parseEntity, Map args);
public String queryForObject(String parseEntity, Map constraints);
public void pushNotification(String channel, Integer expiry, String type, Map data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment