Created
March 2, 2012 02:07
-
-
Save leadVisionary/1954920 to your computer and use it in GitHub Desktop.
Clean Boundaries for 3rd party APIs
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
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 | |
} | |
} |
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
package com.visionarysoftwaresolutions; | |
import java.util.Collection; | |
public interface DatastoreAPI { | |
Collection retrieve(String parseEntity); | |
} |
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
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