Skip to content

Commit

Permalink
Merge pull request #17 from goshippo/api-version-v3
Browse files Browse the repository at this point in the history
[API v3] Change the java client library with the V3 changes
  • Loading branch information
jainankit authored Mar 30, 2017
2 parents 6207f36 + 6cf56ca commit 5ee5e30
Show file tree
Hide file tree
Showing 27 changed files with 218 additions and 422 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Print a shipping label in 10 mins using our default USPS and DHL Express account
Requirements
============

* Shippo API Versions: 2014-02-11 or 2016-10-25
* Shippo API Version: 2017-03-29. For older versions, please use an older release.
* Java 1.5 and later

* [Shippo account](https://goshippo.com/) - free to sign up, free to use the API. Only pay to print a live label, test labels are free.
Expand Down Expand Up @@ -57,7 +57,6 @@ Below is a brief code example:
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.");
Expand All @@ -66,7 +65,7 @@ Below is a brief code example:
addressMap.put("zip", "94117");
addressMap.put("country", "US");
addressMap.put("phone", "+1 555 341 9393");
addressMap.put("email", "laura@goshipppo.com");
addressMap.put("email", "test@goshipppo.com");

try {
Address address = Address.create(addressMap);
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.goshippo</groupId>
<artifactId>shippo-java-client</artifactId>
<version>1.3.1-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Shippo Java Client</name>
<description>Shippo Java Bindings</description>
Expand Down Expand Up @@ -37,7 +37,7 @@
<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>
<tag>1.3.1</tag>
<tag>2.0.0</tag>
</scm>
<dependencies>
<dependency>
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/com/shippo/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public static void main(String[] args) throws ShippoException {

// to address
Map<String, Object> toAddressMap = new HashMap<String, Object>();
toAddressMap.put("object_purpose", "PURCHASE");
toAddressMap.put("name", "Mr Hippo");
toAddressMap.put("company", "Shippo");
toAddressMap.put("street1", "215 Clayton St.");
Expand All @@ -35,7 +34,6 @@ public static void main(String[] args) throws ShippoException {

// from address
Map<String, Object> fromAddressMap = new HashMap<String, Object>();
fromAddressMap.put("object_purpose", "PURCHASE");
fromAddressMap.put("name", "Ms Hippo");
fromAddressMap.put("company", "San Diego Zoo");
fromAddressMap.put("street1", "2920 Zoo Drive");
Expand All @@ -60,14 +58,13 @@ public static void main(String[] args) throws ShippoException {
shipmentMap.put("address_to", toAddressMap);
shipmentMap.put("address_from", fromAddressMap);
shipmentMap.put("parcel", parcelMap);
shipmentMap.put("object_purpose", "PURCHASE");
shipmentMap.put("async", false);

Shipment shipment = Shipment.create(shipmentMap);

// select shipping rate according to your business logic
// we select the first rate in this example
List<Rate> rates = shipment.getRatesList();
List<Rate> rates = shipment.getRates();
Rate rate = rates.get(0);

System.out.println("Getting shipping label..");
Expand All @@ -76,7 +73,7 @@ public static void main(String[] args) throws ShippoException {
transParams.put("async", false);
Transaction transaction = Transaction.create(transParams);

if (transaction.getObjectStatus().equals("SUCCESS")) {
if (transaction.getStatus().equals("SUCCESS")) {
System.out.println(String.format("Label url : %s", transaction.getLabelUrl()));
System.out.println(String.format("Tracking number : %s", transaction.getTrackingNumber()));
} else {
Expand Down
41 changes: 8 additions & 33 deletions src/main/java/com/shippo/model/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Map;

import com.google.gson.annotations.SerializedName;
import com.shippo.exception.APIConnectionException;
import com.shippo.exception.APIException;
import com.shippo.exception.AuthenticationException;
Expand All @@ -11,9 +12,9 @@
// Class is affected by URL name inconsistencies, see APIResource.java (private static String className(Class<?> clazz))
public class Address extends APIResource {

String objectState;
String objectStatus;
String objectPurpose;
@SerializedName("is_complete")
boolean isComplete;

String objectId;
String objectOwner;
Object objectCreated;
Expand All @@ -30,14 +31,12 @@ public class Address extends APIResource {
Object phone;
Object email;
Object is_residential;
Object ip;
Object metadata;
Object messages;

public static Address createForPurchase(String name, String street1, String city, String zip, String state,
String country, String email) {
Address a = new Address();
a.objectPurpose = "PURCHASE";
a.name = name;
a.street1 = street1;
a.city = city;
Expand Down Expand Up @@ -88,28 +87,12 @@ public static AddressCollection all(Map<String, Object> params, String apiKey) t
return request(RequestMethod.GET, classURL(Address.class), params, AddressCollection.class, apiKey);
}

public String getObjectState() {
return objectState;
}

public void setObjectState(String objectState) {
this.objectState = objectState;
}

public String getObjectStatus() {
return objectStatus;
}

public void setObjectStatus(String objectStatus) {
this.objectStatus = objectStatus;
public boolean getIsComplete() {
return isComplete;
}

public String getObjectPurpose() {
return objectPurpose;
}

public void setObject_purpose(String objectPurpose) {
this.objectPurpose = objectPurpose;
public void setIsComplete(boolean isComplete) {
this.isComplete = isComplete;
}

public String getObjectId() {
Expand Down Expand Up @@ -236,14 +219,6 @@ public void setEmail(Object email) {

public void setIs_Residential(Object is_residential) { this.is_residential = is_residential; }

public Object getIp() {
return ip;
}

public void setIp(Object ip) {
this.ip = ip;
}

public Object getMetadata() {
return metadata;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shippo/model/Batch.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static enum BatchStatus {
VALIDATING, VALID, INVALID, PURCHASING, PURCHASED
}

@SerializedName("object_status")
@SerializedName("status")
private BatchStatus status;

@SerializedName("object_created")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shippo/model/BatchShipment.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static enum Status {
INVALID, VALID, INCOMPLETE, TRANSACTION_FAILED
}

@SerializedName("object_status")
@SerializedName("status")
private Status status;

@SerializedName("carrier_account")
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/shippo/model/Manifest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

public class Manifest extends APIResource {
String objectState;
String objectStatus;
String status;
String objectId;
String objectOwner;
Object objectCreated;
Object objectUpdated;
Object provider;
Object submissionDate;
Object shipmentDate;
Object addressFrom;
Object documents;

Expand Down Expand Up @@ -62,12 +62,12 @@ public void setObjectState(String objectState) {
this.objectState = objectState;
}

public String getObjectStatus() {
return objectStatus;
public String getStatus() {
return status;
}

public void setObjectStatus(String objectStatus) {
this.objectStatus = objectStatus;
public void setStatus(String status) {
this.status = status;
}

public String getObjectId() {
Expand Down Expand Up @@ -110,12 +110,12 @@ public void setProvider(Object provider) {
this.provider = provider;
}

public Object getSubmissionDate() {
return submissionDate;
public Object getShipmentDate() {
return shipmentDate;
}

public void setSubmissionDate(Object submissionDate) {
this.submissionDate = submissionDate;
public void setShipmentDate(Object shipmentDate) {
this.shipmentDate = shipmentDate;
}

public Object getAddressFrom() {
Expand Down
Loading

0 comments on commit 5ee5e30

Please sign in to comment.