Created
March 1, 2012 19:15
-
-
Save hunt3r/1952419 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import java.beans.Encoder; | |
import java.io.Serializable; | |
import java.net.URL; | |
import java.net.URLEncoder; | |
import java.util.HashMap; | |
import java.util.Map; | |
public class CategoryPersistance implements Serializable { | |
private static final long serialVersionUID = -2908235189851507205L; | |
protected FelixConfiguration mObjConfiguration = FelixConfiguration.getFelixConfiguration(); | |
protected OrionSession mObjSession = null; | |
public Categories getCategories(String countryCode, String languageCode) throws Exception { | |
String sURL = mObjConfiguration.getServiceProviderDomain() + (mObjConfiguration.getServiceProviderDomain().endsWith("/") ? "" : "/") + countryCode + "/" + languageCode; | |
OrionSession objSession = new OrionSessionManager().login(sURL); | |
Map<String, String> mapHeaders = new HashMap<String, String>(); | |
mapHeaders.put("Content-Type", "Application/JSON"); | |
mapHeaders.put("x-oesp-token", objSession.getOespToken()); | |
mapHeaders.put("x-oesp-username", objSession.getUsername()); | |
sURL += "/web/categories?sort=" + URLEncoder.encode("title|ASC", "UTF-8"); | |
return((Categories)(new RESTParser().doRequest(new URL(sURL), "GET", mapHeaders, "{}", Categories.class))); | |
} | |
public String getCategoriesJSON(String countryCode, String languageCode) throws Exception { | |
String sURL = mObjConfiguration.getServiceProviderDomain() + (mObjConfiguration.getServiceProviderDomain().endsWith("/") ? "" : "/") + countryCode + "/" + languageCode; | |
OrionSession objSession = new OrionSessionManager().login(sURL); | |
Map<String, String> mapHeaders = new HashMap<String, String>(); | |
mapHeaders.put("Content-Type", "Application/JSON"); | |
mapHeaders.put("x-oesp-token", objSession.getOespToken()); | |
mapHeaders.put("x-oesp-username", objSession.getUsername()); | |
sURL += "/web/categories?sort=" + URLEncoder.encode("title|ASC", "UTF-8"); | |
return(new RESTParser().doRequest(new URL(sURL), "GET", mapHeaders, "{}")); | |
} | |
public Categories getCategoriesByParentID(String countryCode, String languageCode, Integer parentID) throws Exception { | |
String sURL = mObjConfiguration.getServiceProviderDomain() + (mObjConfiguration.getServiceProviderDomain().endsWith("/") ? "" : "/") + countryCode + "/" + languageCode; | |
OrionSession objSession = new OrionSessionManager().login(sURL); | |
Map<String, String> mapHeaders = new HashMap<String, String>(); | |
mapHeaders.put("Content-Type", "Application/JSON"); | |
mapHeaders.put("x-oesp-token", objSession.getOespToken()); | |
mapHeaders.put("x-oesp-username", objSession.getUsername()); | |
String strParentID = "-"; // OESP uses "-" for null parentID | |
if (parentID != null) { | |
strParentID = Integer.toString(parentID); | |
} | |
sURL += "/web/categories?byParentId=" + strParentID; //NOTE: cannot sort and filter by parent ID in same query - returns 400 - SORT REMOVED | |
return((Categories)(new RESTParser().doRequest(new URL(sURL), "GET", mapHeaders, "{}", Categories.class))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment