Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add support for clouds

Closes #6
  • Loading branch information...
commit 81a1aeb4bc0c45d208b7e84d1522e9e42e2efe53 1 parent 397826a
@edsrzf edsrzf authored
View
2  README.md
@@ -17,7 +17,7 @@ The Basics
==========
**Initialize** a client and get a queue object:
- Client client = new Client("my project", "my token");
+ Client client = new Client("my project", "my token", Cloud.IronAWSUSEast);
Queue queue = client.queue("my_queue");
**Push** a message on the queue:
View
21 src/main/java/io/iron/ironmq/Client.java
@@ -14,25 +14,38 @@
* The Client class provides access to the IronMQ service.
*/
public class Client {
- static final private String proto = "https";
- static final private String host = "mq-aws-us-east-1.iron.io";
- static final private int port = 443;
static final private String apiVersion = "1";
private String projectId;
private String token;
+ private Cloud cloud;
/**
* Constructs a new Client using the specified project ID and token.
* The network is not accessed during construction and this call will
* succeed even if the credentials are invalid.
+ * This constructor uses the AWS cloud with the US East region.
*
* @param projectId A 24-character project ID.
* @param token An OAuth token.
*/
public Client(String projectId, String token) {
+ this(projectId, token, Cloud.ironAWSUSEast);
+ }
+
+ /**
+ * Constructs a new Client using the specified project ID and token.
+ * The network is not accessed during construction and this call will
+ * succeed even if the credentials are invalid.
+ *
+ * @param projectId A 24-character project ID.
+ * @param token An OAuth token.
+ * @param cloud The cloud to use.
+ */
+ public Client(String projectId, String token, Cloud cloud) {
this.projectId = projectId;
this.token = token;
+ this.cloud = cloud;
}
/**
@@ -59,7 +72,7 @@ JSONObject post(String endpoint, String body) throws IOException {
private JSONObject request(String method, String endpoint, String body) throws IOException {
String path = "/" + apiVersion + "/projects/" + projectId + "/" + endpoint;
- URL url = new URL(proto, host, port, path);
+ URL url = new URL(cloud.scheme, cloud.host, cloud.port, path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod(method);
View
16 src/main/java/io/iron/ironmq/Cloud.java
@@ -0,0 +1,16 @@
+package io.iron.ironmq;
+
+public class Cloud {
+ final String scheme;
+ final String host;
+ final int port;
+
+ public static final Cloud ironAWSUSEast = new Cloud("https", "mq-aws-us-east-1.iron.io", 443);
+ public static final Cloud ironRackspaceDFW = new Cloud("https", "mq-rackspace-dfw.iron.io", 443);
+
+ Cloud(String scheme, String host, int port) {
+ this.scheme = scheme;
+ this.host = host;
+ this.port = port;
+ }
+}
View
2  src/main/java/io/iron/ironmq/Queue.java
@@ -36,6 +36,8 @@ public Message get() throws IOException {
jsonMsg = array.getJSONObject(0);
} catch (JSONException e) {
throw new EmptyQueueException();
+ } catch (IndexOutOfBoundsException e) {
+ throw new EmptyQueueException();
}
Message msg = new Message();
View
2  src/test/java/io/iron/ironmq/IronMQTest.java
@@ -18,7 +18,7 @@
}
@Test public void client() throws IOException {
- Client c = new Client(projectId, token);
+ Client c = new Client(projectId, token, Cloud.ironAWSUSEast);
Queue q = c.queue("test-queue");
// clear out the queue
Please sign in to comment.
Something went wrong with that request. Please try again.