diff --git a/.classpath b/.classpath deleted file mode 100644 index 92eb57c..0000000 --- a/.classpath +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/.gitignore b/.gitignore index d79ff33..327df8e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ ### /Users/egrim/.gitignore-boilerplates/Java.gitignore *.class - +target/ +release.properties +pom.xml.* +.settings/ diff --git a/.project b/.project deleted file mode 100644 index ef3b0b7..0000000 --- a/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - ToopherJava - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/README.md b/README.md index 494270a..ca4ff7f 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,6 @@ This library uses the Apache Commons HttpClient and OAuth-Signpost libraries, wh #### Try it out Check out `com.toopher.ToopherAPIDemo.java` for an example program that walks you through the whole process! A runnable jar for the demo can be built and executed as follows: ```shell -$ ant +$ mvn $ java -jar ToopherJavaDemo.jar ``` diff --git a/build.xml b/build.xml deleted file mode 100644 index c5dbdff..0000000 --- a/build.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/lib/commons-codec-1.6.jar b/lib/commons-codec-1.6.jar deleted file mode 100644 index ee1bc49..0000000 Binary files a/lib/commons-codec-1.6.jar and /dev/null differ diff --git a/lib/commons-logging-1.1.1.jar b/lib/commons-logging-1.1.1.jar deleted file mode 100644 index 1deef14..0000000 Binary files a/lib/commons-logging-1.1.1.jar and /dev/null differ diff --git a/lib/fluent-hc-4.2.1.jar b/lib/fluent-hc-4.2.1.jar deleted file mode 100644 index be4a485..0000000 Binary files a/lib/fluent-hc-4.2.1.jar and /dev/null differ diff --git a/lib/httpclient-4.2.1.jar b/lib/httpclient-4.2.1.jar deleted file mode 100644 index 1d52333..0000000 Binary files a/lib/httpclient-4.2.1.jar and /dev/null differ diff --git a/lib/httpclient-cache-4.2.1.jar b/lib/httpclient-cache-4.2.1.jar deleted file mode 100644 index ce1d553..0000000 Binary files a/lib/httpclient-cache-4.2.1.jar and /dev/null differ diff --git a/lib/httpcore-4.2.1.jar b/lib/httpcore-4.2.1.jar deleted file mode 100644 index 16d75e1..0000000 Binary files a/lib/httpcore-4.2.1.jar and /dev/null differ diff --git a/lib/httpcore-4.2.2.jar b/lib/httpcore-4.2.2.jar deleted file mode 100644 index f7dffd3..0000000 Binary files a/lib/httpcore-4.2.2.jar and /dev/null differ diff --git a/lib/httpcore-ab-4.2.2.jar b/lib/httpcore-ab-4.2.2.jar deleted file mode 100644 index 69b0b23..0000000 Binary files a/lib/httpcore-ab-4.2.2.jar and /dev/null differ diff --git a/lib/httpcore-nio-4.2.2.jar b/lib/httpcore-nio-4.2.2.jar deleted file mode 100644 index 7786d40..0000000 Binary files a/lib/httpcore-nio-4.2.2.jar and /dev/null differ diff --git a/lib/httpmime-4.2.1.jar b/lib/httpmime-4.2.1.jar deleted file mode 100644 index f23d5be..0000000 Binary files a/lib/httpmime-4.2.1.jar and /dev/null differ diff --git a/lib/json.org.jar b/lib/json.org.jar deleted file mode 100644 index 87559a0..0000000 Binary files a/lib/json.org.jar and /dev/null differ diff --git a/lib/signpost-commonshttp4-1.2.1.2.jar b/lib/signpost-commonshttp4-1.2.1.2.jar deleted file mode 100644 index fd37cfa..0000000 Binary files a/lib/signpost-commonshttp4-1.2.1.2.jar and /dev/null differ diff --git a/lib/signpost-core-1.2.1.2.jar b/lib/signpost-core-1.2.1.2.jar deleted file mode 100644 index 8871730..0000000 Binary files a/lib/signpost-core-1.2.1.2.jar and /dev/null differ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..33eca9c --- /dev/null +++ b/pom.xml @@ -0,0 +1,159 @@ + + 4.0.0 + + com.toopher + toopher-java + 1.2.0 + jar + + toopher-java + http://dev.toopher.com + + + scm:git:https://github.com/mrhanlon/toopher-java + HEAD + + + + UTF-8 + 1.7 + 1.7 + + + + package assembly:single + + + org.apache.maven.plugins + maven-compiler-plugin + 2.5 + + ${project.build.sourceEncoding} + ${java.source.version} + ${java.target.version} + + + + org.apache.maven.plugins + maven-resources-plugin + 2.5 + + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-eclipse-plugin + 2.6 + + ${project.build.sourceEncoding} + + + + maven-assembly-plugin + + ToopherJavaDemo + false + + + true + com.toopher.ToopherAPIDemo + + + + jar-with-dependencies + + + + + org.apache.maven.plugins + maven-release-plugin + 2.5 + + v@{version} + + + + + + + + commons-codec + commons-codec + 1.9 + + + + commons-logging + commons-logging + 1.2 + + + + org.apache.httpcomponents + fluent-hc + 4.2.2 + + + + org.apache.httpcomponents + httpclient + 4.2.2 + + + + org.apache.httpcomponents + httpclient-cache + 4.2.2 + + + + org.apache.httpcomponents + httpcore + 4.2.2 + + + + org.apache.httpcomponents + httpcore-ab + 4.2.2 + + + + org.apache.httpcomponents + httpcore-nio + 4.2.2 + + + + org.apache.httpcomponents + httpmime + 4.2.2 + + + + org.json + json + 20140107 + + + + oauth.signpost + signpost-commonshttp4 + 1.2.1.2 + + + + oauth.signpost + signpost-core + 1.2.1.2 + + + + junit + junit + 4.11 + test + + + diff --git a/src/com/toopher/ApiResponseObject.java b/src/main/java/com/toopher/ApiResponseObject.java similarity index 100% rename from src/com/toopher/ApiResponseObject.java rename to src/main/java/com/toopher/ApiResponseObject.java diff --git a/src/com/toopher/AuthenticationStatus.java b/src/main/java/com/toopher/AuthenticationStatus.java similarity index 100% rename from src/com/toopher/AuthenticationStatus.java rename to src/main/java/com/toopher/AuthenticationStatus.java diff --git a/src/com/toopher/PairingStatus.java b/src/main/java/com/toopher/PairingStatus.java similarity index 100% rename from src/com/toopher/PairingStatus.java rename to src/main/java/com/toopher/PairingStatus.java diff --git a/src/com/toopher/RequestError.java b/src/main/java/com/toopher/RequestError.java similarity index 100% rename from src/com/toopher/RequestError.java rename to src/main/java/com/toopher/RequestError.java diff --git a/src/com/toopher/ToopherAPI.java b/src/main/java/com/toopher/ToopherAPI.java similarity index 85% rename from src/com/toopher/ToopherAPI.java rename to src/main/java/com/toopher/ToopherAPI.java index 271dcd0..1bde64a 100644 --- a/src/com/toopher/ToopherAPI.java +++ b/src/main/java/com/toopher/ToopherAPI.java @@ -145,6 +145,71 @@ public PairingStatus pair(String pairingPhrase, String userName, Map extras) throws RequestError { + final String endpoint = "pairings/create/qr"; + + List params = new ArrayList(); + params.add(new BasicNameValuePair("user_name", userName)); + + try { + JSONObject json = post(endpoint, params, extras); + return new PairingStatus(json); + } catch (Exception e) { + throw new RequestError(e); + } + } + + /** + * Create a pairing for SMS + * + * @param phoneNumber + * The phone number for the user + * @param userName + * A user-facing descriptive name for the user (displayed in requests) + * @return A PairingStatus object + * @throws RequestError + * Thrown when a exceptional condition is encountered + */ + public PairingStatus pairSMS(String phoneNumber, String userName) throws RequestError { + return this.pairSMS(phoneNumber, userName, null, null); + } + + public PairingStatus pairSMS(String phoneNumber, String userName, String phoneCountry, Map extras) throws RequestError { + final String endpoint = "pairings/create/sms"; + + List params = new ArrayList(); + params.add(new BasicNameValuePair("phone_number", phoneNumber)); + params.add(new BasicNameValuePair("user_name", userName)); + + if (phoneCountry != null) { + params.add(new BasicNameValuePair("phone_country", phoneCountry)); + } + + try { + JSONObject json = post(endpoint, params, extras); + return new PairingStatus(json); + } catch (Exception e) { + throw new RequestError(e); + } + } /** * Retrieve the current status of a pairing request diff --git a/src/com/toopher/ToopherAPIDemo.java b/src/main/java/com/toopher/ToopherAPIDemo.java similarity index 68% rename from src/com/toopher/ToopherAPIDemo.java rename to src/main/java/com/toopher/ToopherAPIDemo.java index 87b3c26..b2dd025 100644 --- a/src/com/toopher/ToopherAPIDemo.java +++ b/src/main/java/com/toopher/ToopherAPIDemo.java @@ -23,6 +23,9 @@ public static void main(String[] args) { if(env.containsKey("TOOPHER_BASE_URL")){ try { base_uri = new URI(env.get("TOOPHER_BASE_URL")); + System.out.println("\n--------------------------------------"); + System.out.println("Using Toopher API at: " + env.get("TOOPHER_BASE_URL")); + System.out.println("--------------------------------------\n"); } catch (URISyntaxException e) { System.out.println("Error parsing environment arg TOOPHER_BASE_URL! Using default (https://api.toopher.com/v1/)"); base_uri = null; @@ -45,23 +48,52 @@ public static void main(String[] args) { api = new ToopherAPI (consumerKey, consumerSecret, base_uri); } + boolean pairSMS = false; + while (true) { + System.out.println("Step 0: Would you like to pair via SMS or using the Toopher App?"); + System.out.println("--------------------------------------"); + System.out.print("Enter \"sms\" to use SMS (default is \"app\"): "); + String response = in.nextLine(); + + if (response.trim().equalsIgnoreCase("sms")) { + pairSMS = true; + } + + break; + } + String pairingId; while (true) { - String pairingPhrase; - while (true) { - System.out.println("Step 1: Pair requester with phone"); - System.out.println("--------------------------------------"); - System.out.println("Pairing phrases are generated on the mobile app"); - System.out.print("Enter pairing phrase: "); - pairingPhrase = in.nextLine(); - - if (pairingPhrase.length() == 0) { - System.out.println("Please enter a pairing phrase to continue"); - } else { - break; - } - } - + String pairingPhrase; + if (pairSMS) { + while (true) { + System.out.println("Step 1: Pair requester with phone"); + System.out.println("--------------------------------------"); + System.out.print("Enter your 10-digit Mobile Phone number (no punctuation):"); + pairingPhrase = in.nextLine(); + + if (!pairingPhrase.matches("\\d{10}")) { + System.out.println("Please enter a valid phone number to continue"); + } else { + break; + } + } + } else { + while (true) { + System.out.println("Step 1: Pair requester with phone"); + System.out.println("--------------------------------------"); + System.out.println("Pairing phrases are generated on the mobile app"); + System.out.print("Enter pairing phrase: "); + pairingPhrase = in.nextLine(); + + if (pairingPhrase.length() == 0) { + System.out.println("Please enter a pairing phrase to continue"); + } else { + break; + } + } + } + System.out.print(String.format("Enter a username for this pairing [%s]: ", DEFAULT_USERNAME)); String userName = in.nextLine(); if (userName.length() == 0) { @@ -71,11 +103,17 @@ public static void main(String[] args) { System.out.println("Sending pairing request..."); try { - PairingStatus pairingStatus = api.pair(pairingPhrase, userName); + PairingStatus pairingStatus; + if (pairSMS) { + pairingStatus = api.pairSMS(pairingPhrase, userName); + } else { + pairingStatus = api.pair(pairingPhrase, userName); + } pairingId = pairingStatus.id; break; } catch (RequestError err) { System.out.println(String.format("The pairing phrase was not accepted (reason:%s)", err.getMessage())); + err.printStackTrace(); } }