Skip to content

Commit

Permalink
released 2.3.0 to support regional gateway endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
snatchblock committed Nov 23, 2018
1 parent 2dca904 commit 7607ad4
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 22 deletions.
15 changes: 13 additions & 2 deletions README.md
Expand Up @@ -16,7 +16,7 @@ The dependency information is as follows:
<dependency>
<groupId>com.whispir</groupId>
<artifactId>sdk</artifactId>
<version>2.2.2</version>
<version>2.3.0</version>
</dependency>
```
See the examples section below for usage instructions.
Expand Down Expand Up @@ -77,22 +77,26 @@ package com.whispir.sdk.examples;
import java.util.Map;
import java.util.TreeMap;

import com.whispir.sdk.WhispirEndPoints;
import com.whispir.sdk.WhispirResponse;
import com.whispir.sdk.WhispirSDK;
import com.whispir.sdk.exceptions.WhispirSDKException;


public class SDKExample {

//APIKEY, Username and Password available from whispir.io
public static final String API_KEY = "...";
public static final String USERNAME = "...";
public static final String PASSWORD = "...";
public static final WhispirEndPoints APIENDPOINT = WhispirEndPoints.AU;


public static void main(String[] args) {
try {

// INIT API object
WhispirSDK sdk = new WhispirSDK(API_KEY, USERNAME, PASSWORD);
WhispirSDK sdk = new WhispirSDK(API_KEY, USERNAME, PASSWORD, APIENDPOINT);

// Send the message
WhispirResponse response = sdk.sendMessage("61400000000",
Expand Down Expand Up @@ -169,6 +173,13 @@ See the LICENSE.txt and refer to [Whispir's Terms of Service](http://whispir.com

# Change Log

## Updates November 23, 2018 - Release 2.3.0

### Added the following:

* Updated the SDK to handle the API gateway changes. You would now be able to connect to the regional api gateways
* Upgraded pom.xml; org.apache.httpcomponents:httpclient to now use version 4.3.6 or later to fix the vulnerability described in CVE-2015-5262

## Updates April 22, 2016 - Release 2.2.2

### Added the following:
Expand Down
12 changes: 3 additions & 9 deletions pom.xml
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.whispir</groupId>
<artifactId>sdk</artifactId>
<version>2.2.2</version>
<version>2.3.0</version>
<name>WhispirSDK</name>
<description>Whispir SDK for the Whispir API. Simplifies development on the Whispir API for Java developers.</description>
<url>https://whispir.io</url>
Expand All @@ -24,12 +24,6 @@
<developerConnection>scm:git:git@github.com:whispir/whispir-java-sdk.git</developerConnection>
</scm>
<developers>
<developer>
<email>jwalsh@whispir.com</email>
<name>Jordan Walsh</name>
<url>https://github.com/jordanwalsh23</url>
<id>jordanwalsh23</id>
</developer>
<developer>
<email>smandalapu@whispir.com</email>
<name>Sanjeev Mandalapu</name>
Expand Down Expand Up @@ -156,7 +150,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.5</version>
<version>4.3.6</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
Expand Down Expand Up @@ -236,6 +230,6 @@
</profiles>
<organization>
<name>Whispir</name>
<url>http://whispir.com</url>
<url>https://www.whispir.com</url>
</organization>
</project>
36 changes: 33 additions & 3 deletions src/main/java/com/whispir/sdk/WhispirSDK.java
Expand Up @@ -46,6 +46,8 @@
* @author Jordan Walsh
* @version 1.0
*
* @author Sanjeev Mandalapu
* @version 2.0
*/

public class WhispirSDK implements MessageHelper, WorkspaceHelper,
Expand All @@ -69,6 +71,9 @@ public class WhispirSDK implements MessageHelper, WorkspaceHelper,
WorkspaceHelper workspaceHelper;
ScenarioHelper scenarioHelper;

// endpoint
private WhispirEndPoints APIEndPoint;

@SuppressWarnings("unused")
private WhispirSDK() {
}
Expand All @@ -84,9 +89,32 @@ private WhispirSDK() {
* @param password
*/

public WhispirSDK(String apikey, String username, String password)
// public WhispirSDK(String apikey, String username, String password)
// throws WhispirSDKException {
// this(apikey, username, password, "");
// }

public WhispirSDK(String apikey, String username, String password, WhispirEndPoints EndPoint)
throws WhispirSDKException {
this(apikey, username, password, "");

if (apikey.equals(null) || username.equals(null)
|| password.equals(null)) {
throw new WhispirSDKException(WhispirSDKConstants.NO_AUTH_ERROR);
}

if ("".equals(apikey) || "".equals(username) || "".equals(password)) {
throw new WhispirSDKException(WhispirSDKConstants.NO_AUTH_ERROR);
}

this.apikey = apikey;
this.username = username;
this.password = password;
this.proxyEnabled = false;
this.proxyCredentials = null;
this.APIEndPoint = EndPoint;


initHelpers();
}

/**
Expand Down Expand Up @@ -374,13 +402,14 @@ private void setHeaders(HttpRequestBase request, String resourceType)

request.setHeader("Content-Type", header);
request.setHeader("Accept", header);
request.setHeader("x-api-key", this.apikey);
}

public String getHost() {
if (debug) {
return this.debugHost;
} else {
return WhispirSDKConstants.API_HOST;
return String.format("api.%s.whispir.com", APIEndPoint.toString());
}
}

Expand Down Expand Up @@ -542,3 +571,4 @@ private WhispirResponse executeRequest(HttpRequestBase httpRequest)
}

}

12 changes: 7 additions & 5 deletions src/main/java/com/whispir/sdk/examples/SDKExample.java
Expand Up @@ -3,21 +3,22 @@
import java.util.Map;
import java.util.TreeMap;

import com.whispir.sdk.WhispirEndPoints;
import com.whispir.sdk.WhispirResponse;
import com.whispir.sdk.WhispirSDK;
import com.whispir.sdk.exceptions.WhispirSDKException;

public class SDKExample {

public static final String API_KEY = "...";
public static final String USERNAME = "...";
public static final String PASSWORD = "...";

public static final String API_KEY = "";
public static final String USERNAME = "";
public static final String PASSWORD = "";
public static final WhispirEndPoints APIENDPOINT = WhispirEndPoints.AU;
public static void main(String[] args) {
try {

// INIT API object
WhispirSDK sdk = new WhispirSDK(API_KEY, USERNAME, PASSWORD);
WhispirSDK sdk = new WhispirSDK(API_KEY, USERNAME, PASSWORD, APIENDPOINT);

// Send the message
WhispirResponse response = sdk.sendMessage("61400000000",
Expand Down Expand Up @@ -75,3 +76,4 @@ public static void main(String[] args) {
}
}
}

9 changes: 6 additions & 3 deletions src/test/java/com/whispir/sdk/tests/WhispirSDKTest.java
Expand Up @@ -6,6 +6,7 @@
import org.junit.Before;
import org.junit.Test;

import com.whispir.sdk.WhispirEndPoints;
import com.whispir.sdk.WhispirResponse;
import com.whispir.sdk.WhispirSDK;
import com.whispir.sdk.exceptions.WhispirSDKException;
Expand All @@ -19,7 +20,8 @@ public class WhispirSDKTest {
protected static final String TEST_API_KEY = "";
protected static final String TEST_USERNAME = "";
protected static final String TEST_PASSWORD = "";

protected static final WhispirEndPoints APIENDPOINT = null;

// Message content variables for the tests
protected static final String TEST_RECIPIENT = "";
protected static final String TEST_WORKSPACE_ID = "";
Expand All @@ -36,7 +38,7 @@ public class WhispirSDKTest {
protected static final boolean PROXY_HTTPS_ENABLED = false;
protected static final String PROXY_USERNAME = "";
protected static final String PROXY_PASSWORD = "";

//Squid Proxy Error Code is 407 (Proxy Authentication Required)
protected static final int PROXY_ERROR_CODE = 407;

Expand All @@ -47,7 +49,7 @@ public void setUp() throws Exception {
TEST_PASSWORD, DEBUG_HOST);
} else {
this.whispirSDK = new WhispirSDK(TEST_API_KEY, TEST_USERNAME,
TEST_PASSWORD);
TEST_PASSWORD, APIENDPOINT);
}

if (!"".equals(PROXY_HOST)) {
Expand Down Expand Up @@ -155,3 +157,4 @@ public void testDebugHost() throws WhispirSDKException {
assertTrue(this.whispirSDK.getHost().equals("sandbox.whispir.com"));
}
}

0 comments on commit 7607ad4

Please sign in to comment.