-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Subhi Beidas
committed
Mar 23, 2015
1 parent
6f77ff9
commit 8cba36a
Showing
98 changed files
with
3,954 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
=== 1.0 2014.11.21 | ||
|
||
Initial change-log entry |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
The MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,80 @@ | ||
# shippo-java-client | ||
# Shippo Java Bindings | ||
|
||
You can sign up for a Shippo account at https://goshippo.com | ||
|
||
Requirements | ||
============ | ||
|
||
Java 1.5 and later | ||
|
||
Installation | ||
============ | ||
|
||
### Maven users | ||
|
||
Add this dependency to your project's POM: | ||
|
||
<dependency> | ||
<groupId>com.shippo</groupId> | ||
<artifactId>shippo-java-client</artifactId> | ||
<version>1.0</version> | ||
</dependency> | ||
|
||
|
||
### Others | ||
|
||
You'll need to manually install the following JARs: | ||
|
||
* The latest Shippo JAR from <https://github.com/goshippo/shippo-java-client/releases> | ||
* [Google Gson](http://code.google.com/p/google-gson/) from <http://google-gson.googlecode.com/files/google-gson-2.2.4-release.zip>. | ||
|
||
### Developing with Eclipse | ||
|
||
You can also load the source into Eclipse, simply clone this repository. Then open up Eclipse (the latest eclipse comes with maven). | ||
Within eclipse, File --> Import | ||
In the dialog window that appears, chose "Existing Maven Projects", from there on, follow the wizard, and you will have imported the project. | ||
You can then run Example.java, or any of the individual JUnit test cases. | ||
|
||
|
||
Usage | ||
===== | ||
|
||
Check out the file Example.java for more examples, alternatively you can look through all of the test classes for each particular model for examples. | ||
For useful debugging information including headers, server raw response etc, set Shippo.setDEBUG(true); | ||
|
||
Below is a brief code example: | ||
|
||
/* Code Example */ | ||
public static void main(String[] args) { | ||
|
||
Shippo.apiKey = "<Your Shippo authToken>"; | ||
Map<String, Object> addressMap = new HashMap<String, Object>(); | ||
addressMap.put("object_purpose", "PURCHASE"); | ||
addressMap.put("name", "Shippo Itle"); | ||
addressMap.put("company", "Shippo"); | ||
addressMap.put("street1", "215 Clayton St."); | ||
addressMap.put("city", "San Francisco"); | ||
addressMap.put("state", "CA"); | ||
addressMap.put("zip", "94117"); | ||
addressMap.put("country", "US"); | ||
addressMap.put("phone", "+1 555 341 9393"); | ||
addressMap.put("email", "[email protected]") | ||
|
||
try { | ||
Address address = Address.create(addressMap); | ||
System.out.println(address.toString()); | ||
System.out.println("Zip code: " + address.getZip()); | ||
} catch (ShippoException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
|
||
|
||
Testing | ||
======= | ||
|
||
You must have Maven installed. To run the tests, simply run `mvn test`. You can run particular tests by passing `-D test=Class#method` -- for example, `-D test=ShippoTest#testAddressCreate`. | ||
|
||
You can also run the tests in eclipse. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.0 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.shippo</groupId> | ||
<artifactId>shippo-java-client</artifactId> | ||
<packaging>jar</packaging> | ||
<version>1.19.1</version> | ||
<name>shippo-java-client</name> | ||
<url>https://github.com/goshippo/shippo-java-client</url> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
<version>2.2.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.10</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<description>Shippo Java Bindings</description> | ||
<organization> | ||
<name>Shippo</name> | ||
<url>https://goshippo.com</url> | ||
</organization> | ||
<parent> | ||
<groupId>org.sonatype.oss</groupId> | ||
<artifactId>oss-parent</artifactId> | ||
<version>7</version> | ||
</parent> | ||
<scm> | ||
<connection>scm:git:[email protected]:goshippo/shippo-java-clienta.git</connection> | ||
<developerConnection>scm:git:[email protected]:goshippo/shippo-java-client.git</developerConnection> | ||
<url>[email protected]:goshippo/shippo-java-client.git</url> | ||
</scm> | ||
<build> | ||
<resources> | ||
<resource> | ||
<directory>.</directory> | ||
<includes> | ||
<include>VERSION</include> | ||
</includes> | ||
</resource> | ||
</resources> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-gpg-plugin</artifactId> | ||
<version>1.5</version> | ||
<executions> | ||
<execution> | ||
<id>sign-artifacts</id> | ||
<phase>verify</phase> | ||
<goals> | ||
<goal>sign</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.1</version> | ||
<configuration> | ||
<source>1.5</source> | ||
<target>1.5</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<version>2.3</version> | ||
<executions> | ||
<execution> | ||
<id>attach-sources</id> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
<version>2.9.1</version> | ||
<executions> | ||
<execution> | ||
<id>attach-javadocs</id> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.sonatype.plugins</groupId> | ||
<version>1.6.4</version> | ||
<artifactId>nexus-staging-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>default-deploy</id> | ||
<phase>deploy</phase> | ||
<goals> | ||
<goal>deploy</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<serverId>sonatype-nexus-staging</serverId> | ||
<nexusUrl>https://oss.sonatype.org/</nexusUrl> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.shippo; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.shippo.exception.APIConnectionException; | ||
import com.shippo.exception.APIException; | ||
import com.shippo.exception.AuthenticationException; | ||
import com.shippo.exception.InvalidRequestException; | ||
import com.shippo.exception.RequestTimeoutException; | ||
import com.shippo.exception.ShippoException; | ||
import com.shippo.model.Address; | ||
import com.shippo.model.AddressCollection; | ||
import com.shippo.model.Rate; | ||
import com.shippo.model.RateCollection; | ||
import com.shippo.model.Shipment; | ||
import com.shippo.model.Transaction; | ||
|
||
public class Example { | ||
|
||
public static void main(String[] args) throws ShippoException { | ||
|
||
// replace with your Shippo Token | ||
// don't have one? get more info here (https://goshippo.com/docs/#overview) | ||
Shippo.setApiKey("<Shippo Token>"); | ||
|
||
// Optional defaults to false | ||
//Shippo.setDEBUG(true); | ||
|
||
// to address | ||
Map<String, Object> toAddressMap = new HashMap<String, Object>(); | ||
toAddressMap.put("object_purpose", "PURCHASE"); | ||
toAddressMap.put("name", "Shippo Itle"); | ||
toAddressMap.put("company", "Shippo"); | ||
toAddressMap.put("street1", "215 Clayton St."); | ||
toAddressMap.put("city", "San Francisco"); | ||
toAddressMap.put("state", "CA"); | ||
toAddressMap.put("zip", "94117"); | ||
toAddressMap.put("country", "US"); | ||
toAddressMap.put("phone", "+1 555 341 9393"); | ||
toAddressMap.put("email", "[email protected]"); | ||
|
||
// from address | ||
Map<String, Object> fromAddressMap = new HashMap<String, Object>(); | ||
fromAddressMap.put("object_purpose", "PURCHASE"); | ||
fromAddressMap.put("name", "Mr Hippo"); | ||
fromAddressMap.put("company", "San Diego Zoo"); | ||
fromAddressMap.put("street1", "2920 Zoo Drive"); | ||
fromAddressMap.put("city", "San Diego"); | ||
fromAddressMap.put("state", "CA"); | ||
fromAddressMap.put("zip", "92101"); | ||
fromAddressMap.put("country", "US"); | ||
fromAddressMap.put("email", "[email protected]"); | ||
fromAddressMap.put("phone", "+1 619 231 1515"); | ||
fromAddressMap.put("metadata", "Customer ID 123456"); | ||
|
||
// parcel | ||
Map<String, Object> parcelMap = new HashMap<String, Object>(); | ||
parcelMap.put("length", "5"); | ||
parcelMap.put("width", "5"); | ||
parcelMap.put("height", "5"); | ||
parcelMap.put("distance_unit", "in"); | ||
parcelMap.put("weight", "2"); | ||
parcelMap.put("mass_unit", "lb"); | ||
|
||
Map<String, Object> shipmentMap = new HashMap<String, Object>(); | ||
shipmentMap.put("address_to", toAddressMap); | ||
shipmentMap.put("address_from", fromAddressMap); | ||
shipmentMap.put("parcel", parcelMap); | ||
shipmentMap.put("object_purpose", "PURCHASE"); | ||
|
||
// create Shipment object | ||
System.out.println("Creating Shipment object.."); | ||
Shipment shipment = Shipment.create(shipmentMap); | ||
|
||
// get shipping rates | ||
System.out.println(String.format("Generating rates for shipment %s", shipment.getObject_id())); | ||
RateCollection rates = Shipment.getShippingRatesSync(shipment.getObject_id()); | ||
|
||
|
||
System.out.println(String.format("Obtainned %d rates for shipment %s ", rates.getCount(), shipment.getObject_id()));; | ||
Rate rate = rates.getData().get(0); | ||
|
||
System.out.println("Getting shipping label.."); | ||
Map<String, Object> transParams = new HashMap<String, Object>(); | ||
transParams.put("rate", rate.getObject_id()); | ||
Transaction transaction = Transaction.createSync(transParams); | ||
|
||
if (transaction.getObject_status().equals("SUCCESS")) { | ||
System.out.println(String.format("Label url : %s", transaction.getLabel_url())); | ||
System.out.println(String.format("Tracking number : %s", transaction.getTracking_number())); | ||
} else { | ||
System.out.println(String.format("An Error has occured while generating you label. Messages : %s", transaction.getMessages())); | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.shippo; | ||
|
||
public abstract class Shippo { | ||
|
||
public static final String LIVE_API_BASE = "https://api.goshippo.com"; | ||
public static final String VERSION = "1.0"; | ||
public static boolean DEBUG = false; | ||
|
||
public static int RATES_REQ_TIMEOUT = 25000; // milliseconds | ||
public static int TRANSACTION_REQ_TIMEOUT = 25000; // milliseconds | ||
|
||
public static volatile String apiKey; | ||
public static volatile String apiVersion; | ||
|
||
private static volatile boolean verifySSL = true; | ||
private static volatile String apiBase = LIVE_API_BASE; | ||
|
||
|
||
/** | ||
* (FOR TESTING ONLY) If you'd like your API requests to hit your own | ||
* (mocked) server, you can set this up here by overriding the base api URL. | ||
*/ | ||
public static void overrideApiBase(final String overriddenApiBase) { | ||
apiBase = overriddenApiBase; | ||
} | ||
|
||
/** | ||
* (FOR TESTING ONLY) Only disable SSL verification if you're using your own | ||
* (mocked) server. Disabling verification on shippo.com is not supported | ||
*/ | ||
public static void setVerifySSL(boolean verify) { | ||
verifySSL = verify; | ||
} | ||
|
||
public static boolean getVerifySSL() { | ||
return verifySSL; | ||
} | ||
|
||
public static String getApiBase() { | ||
return apiBase; | ||
} | ||
|
||
public static boolean isDEBUG() { | ||
return DEBUG; | ||
} | ||
|
||
public static void setDEBUG(boolean dEBUG) { | ||
DEBUG = dEBUG; | ||
} | ||
|
||
public static String getApiKey() { | ||
return apiKey; | ||
} | ||
|
||
public static void setApiKey(String apiKey) { | ||
Shippo.apiKey = apiKey; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/shippo/exception/APIConnectionException.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.shippo.exception; | ||
|
||
public class APIConnectionException extends ShippoException { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public APIConnectionException(String message) { | ||
super(message); | ||
} | ||
|
||
public APIConnectionException(String message, Throwable e) { | ||
super(message, e); | ||
} | ||
|
||
} |
Oops, something went wrong.