Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added Wrapper for Subscription AddOn & Updated Base #3

Open
wants to merge 2 commits into from

1 participant

@EZWrighter

Added a Wrapper for the Subscription AddOn Array
Changed Base to allow for setting subdomain in the baseURI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
16 src/com/kwanzoo/recurly/AddOn.java
@@ -0,0 +1,16 @@
+package com.kwanzoo.recurly;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name="add_on")
+public class AddOn{
+ @XmlElement(name="add_on_code")
+ public String addOnCode;
+
+ @XmlElement(name="unit_amount_in_cents")
+ public Integer unitAmountInCents;
+
+ @XmlElement(name="quantity")
+ public Integer quantity;
+}
View
16 src/com/kwanzoo/recurly/Base.java
@@ -3,6 +3,7 @@
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
+
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
@@ -30,7 +31,10 @@
import com.sun.jersey.core.util.Base64;
public abstract class Base{
- private static final String BaseURI = "https://app.recurly.com";
+ private static String protocol = "https://";
+ private static String subdomain = "app";
+ private static String domain = "recurly.com";
+ //private static String BaseURI = protocol + subdomain + "." + domain;
private static final WebResource webResource;
private static String base64AuthStr = "";
private static final int UNPROCESSABLE_ENTITY_HTTP_CODE = 422;
@@ -72,6 +76,10 @@ private static SSLContext getSSLContext(){
}
return context;
}
+
+ private static String getBaseURI() {
+ return protocol + subdomain + "." + domain;
+ }
private static HostnameVerifier getHostNameVerifier(){
return new HostnameVerifier() {
@@ -85,7 +93,7 @@ public boolean verify(final String hostname, final SSLSession sslSession) {
private static WebResource getNewWebResource(){
final ClientConfig config = new DefaultClientConfig();
config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(getHostNameVerifier(), getSSLContext()));
- return Client.create(config).resource(BaseURI);
+ return Client.create(config).resource(getBaseURI());
}
public static WebResource.Builder getWebResourceBuilder(final String path){
@@ -97,7 +105,8 @@ private static WebResource getNewWebResource(){
}
//This method needs to be invoked only once, just before performing the first recurly operation
- public static void setAuth(final String recurlyUsername, final String recurlyPassword){
+ public static void setAuth(final String recurlySubdomain, final String recurlyUsername, final String recurlyPassword){
+ subdomain = recurlySubdomain;
base64AuthStr = new String(Base64.encode(recurlyUsername + ":" + recurlyPassword));
}
@@ -146,6 +155,7 @@ else if(status.equals(ClientResponse.Status.SERVICE_UNAVAILABLE)){
protected abstract String getResourcePath();
protected abstract String getResourceCreationPath();
+
//default implementations for create, update and delete operation on a resource.
//read operations are static methods within respective resource classes.
public void create() throws Exception{
View
6 src/com/kwanzoo/recurly/Subscription.java
@@ -1,8 +1,10 @@
package com.kwanzoo.recurly;
import java.util.Date;
+import java.util.List;
import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import com.sun.jersey.api.client.GenericType;
@@ -33,6 +35,10 @@
@XmlElement(name="plan")
public Plan plan;
+ @XmlElementWrapper(name = "add_ons")
+ @XmlElement(name = "add_on")
+ public List<AddOn> addOns;
+
@XmlElement(name="state")
public String state;
View
2  src/com/kwanzoo/recurly/test/RecurlyTest.java
@@ -58,7 +58,7 @@ public void setUp() {
currentYear = Integer.parseInt(new SimpleDateFormat("yyyy").format(new Date()));
- Base.setAuth(username, password);
+ Base.setAuth("app", username, password);
}
catch (IOException e) {
e.printStackTrace();
Something went wrong with that request. Please try again.