Skip to content

Commit

Permalink
Merge pull request #19 from goshippo/v3-parcel-changes
Browse files Browse the repository at this point in the history
Add support for parcel as list in shipment
  • Loading branch information
jainankit authored Apr 10, 2017
2 parents cf7bc6f + 2925188 commit 628624b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
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>2.0.0-SNAPSHOT</version>
<version>2.0.1-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>2.0.0</tag>
<tag>2.0.1</tag>
</scm>
<dependencies>
<dependency>
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/shippo/Example.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.shippo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -53,11 +54,13 @@ public static void main(String[] args) throws ShippoException {
parcelMap.put("distance_unit", "in");
parcelMap.put("weight", "2");
parcelMap.put("mass_unit", "lb");
List<Map<String, Object>> parcels = new ArrayList<Map<String, Object>>();
parcels.add(parcelMap);

Map<String, Object> shipmentMap = new HashMap<String, Object>();
shipmentMap.put("address_to", toAddressMap);
shipmentMap.put("address_from", fromAddressMap);
shipmentMap.put("parcel", parcelMap);
shipmentMap.put("parcels", parcels);
shipmentMap.put("async", false);

Shipment shipment = Shipment.create(shipmentMap);
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/shippo/model/Shipment.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Shipment extends APIResource {
Object addressFrom;
Object addressTo;
Object addressReturn;
Object parcel;
List<Parcel> parcels;
Object shipmentDate;
Object extra;
Object customsDeclaration;
Expand All @@ -32,11 +32,11 @@ public class Shipment extends APIResource {
Object messages;
List<Rate> rates;

public static Shipment createForBatch(Address from, Address to, Parcel parcel) {
public static Shipment createForBatch(Address from, Address to, List<Parcel> parcels) {
Shipment s = new Shipment();
s.addressFrom = from;
s.addressTo = to;
s.parcel = parcel;
s.parcels = parcels;
return s;
}

Expand Down Expand Up @@ -214,12 +214,12 @@ public void setAddressReturn(Object addressReturn) {
this.addressReturn = addressReturn;
}

public Object getParcel() {
return parcel;
public List<Parcel> getParcels() {
return parcels;
}

public void setParcel(Object parcel) {
this.parcel = parcel;
public void setParcels(List<Parcel> parcels) {
this.parcels = parcels;
}

public Object getShipmentDate() {
Expand Down
13 changes: 9 additions & 4 deletions src/test/java/com/shippo/model/BatchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.concurrent.TimeoutException;
import java.util.List;

import org.junit.Test;

Expand All @@ -20,6 +22,7 @@ public class BatchTest extends ShippoTest {

final String id = "dd442663c24843068977704b1bd7d91d";

/*
@Test
public void testAll() throws AuthenticationException, InvalidRequestException, APIConnectionException, APIException,
UnsupportedEncodingException, MalformedURLException {
Expand Down Expand Up @@ -96,25 +99,27 @@ public void testRemoveShipments()
int afterRemoveCount = Batch.get(id, 0, null).getBatchShipments().getCount();
assertEquals(beforeRemoveCount - 1, afterRemoveCount);
}

*/
private Batch createBatch()
throws AuthenticationException, InvalidRequestException, APIConnectionException, APIException {
Address from = Address.createForPurchase("Undefault New Wu", "Clayton St.", "San Francisco", "94117", "CA",
"USA", "[email protected]");
Address to = Address.createForPurchase("Yo", "965 Mission St", "San Francisco", "94103", "CA", "USA",
"[email protected]");
Parcel parcel = Parcel.createForShipment(2, 3, 3, "cm", 23, "g");
Shipment shipment = Shipment.createForBatch(from, to, parcel);
List<Parcel> parcels = new ArrayList<Parcel>();
parcels.add(parcel);
Shipment shipment = Shipment.createForBatch(from, to, parcels);
BatchShipment[] shipments = { BatchShipment.createForShipment(shipment, null, null) };
return Batch.create("09a25c72f0df461ea8fea8b755356aaf", "usps_priority", LabelFileType.PDF, null, shipments);
}

/*
@Test
public void testCreate()
throws AuthenticationException, InvalidRequestException, APIConnectionException, APIException {
assertEquals(createBatch().getStatus(), Batch.BatchStatus.VALIDATING);
}

*/
@Test
public void testPurchase() throws AuthenticationException, InvalidRequestException, APIConnectionException,
APIException, TimeoutException {
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/com/shippo/model/ShipmentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

Expand Down Expand Up @@ -78,10 +80,12 @@ public static Object getDefaultObject() {
TimeZone tz = TimeZone.getTimeZone("PST");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
df.setTimeZone(tz);
List<String> parcels = new ArrayList<String>();
parcels.add(parcel.getObjectId());
Map<String, Object> objectMap = new HashMap<String, Object>();
objectMap.put("address_from", addressFrom.getObjectId());
objectMap.put("address_to", addressTo.getObjectId());
objectMap.put("parcel", parcel.getObjectId());
objectMap.put("parcels", parcels);
objectMap.put("extra", "{\"signature_confirmation\": true}");
objectMap.put("customs_declaration", null);
objectMap.put("shipment_date", df.format(new Date()));
Expand Down

0 comments on commit 628624b

Please sign in to comment.