Skip to content

Commit 2ffe3a7

Browse files
committed
Initial commit.
0 parents  commit 2ffe3a7

File tree

8 files changed

+857
-0
lines changed

8 files changed

+857
-0
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
.AppleDouble
3+
.LSOverride
4+
Icon
5+
._*
6+
.Spotlight-V100
7+
.Trashes
8+
9+
node_modules

CHANGELOG

Whitespace-only changes.

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License
2+
3+
Copyright (c) 2013 EasyPost (Simpler Postage, Inc)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# EasyPost NodeJS Client Library
2+
3+
EasyPost is a simple shipping API. You can sign up for an account at https://easypost.com
4+
5+
Installation
6+
---------------
7+
8+
```
9+
npm install easypost
10+
```
11+
12+
Example
13+
------------------
14+
15+
```javascript
16+
var apiKey = 'cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi';
17+
var easypost = require('./lib/main.js')(apiKey);
18+
19+
// set addresses
20+
var toAddress = {
21+
name: "Sawyer Bateman",
22+
street1: "1A Larkspur Cres.",
23+
street2: "",
24+
city: "St. Albert",
25+
state: "AB",
26+
zip: "t8n2m4",
27+
country: "CA",
28+
phone: "780-283-9384"
29+
};
30+
var fromAddress = {
31+
name: "Jon Calhoun",
32+
street1: "388 Townsend St",
33+
city: "San Francisco",
34+
state: "CA",
35+
zip: "94107",
36+
phone: "415-456-7890"
37+
};
38+
39+
// verify address
40+
easypost.Address.create(fromAddress, function(err, fromAddress) {
41+
fromAddress.verify(function(err, response) {
42+
if (err) {
43+
console.log('Address is invalid.');
44+
} else if (response.message !== undefined && response.message !== null) {
45+
console.log('Address is valid but has an issue: ', response.message);
46+
var verifiedAddress = response.address;
47+
} else {
48+
var verifiedAddress = response;
49+
}
50+
});
51+
});
52+
53+
// set parcel
54+
easypost.Parcel.create({
55+
predefined_package: "InvalidPackageName",
56+
weight: 21.2
57+
}, function(err, response) {
58+
console.log(err);
59+
});
60+
61+
var parcel = {
62+
length: 10.2,
63+
width: 7.8,
64+
height: 4.3,
65+
weight: 21.2
66+
};
67+
68+
69+
// create customs_info form for intl shipping
70+
var customsItem = {
71+
description: "EasyPost t-shirts",
72+
hs_tariff_number: 123456,
73+
origin_country: "US",
74+
quantity: 2,
75+
value: 96.27,
76+
weight: 21.1
77+
};
78+
79+
var customsInfo = {
80+
customs_certify: 1,
81+
customs_signer: "Hector Hammerfall",
82+
contents_type: "gift",
83+
contents_explanation: "",
84+
eel_pfc: "NOEEI 30.37(a)",
85+
non_delivery_option: "return",
86+
restriction_type: "none",
87+
restriction_comments: "",
88+
customs_items: [customsItem]
89+
};
90+
91+
// create shipment
92+
easypost.Shipment.create({
93+
to_address: toAddress,
94+
from_address: fromAddress,
95+
parcel: parcel,
96+
customs_info: customsInfo
97+
}, function(err, shipment) {
98+
// buy postage label with one of the rate objects
99+
shipment.buy({rate: shipment.lowestRate(['USPS', 'ups'])}, function(err, response) {
100+
console.log(response.tracking_code);
101+
console.log(response.postage_label.label_url);
102+
});
103+
104+
});
105+
106+
```
107+
108+
Documentation
109+
--------------------
110+
111+
Up-to-date documentation at: https://easypost.com/docs/v2
112+
113+
Tests
114+
--------------------
115+
116+
```
117+
npm test
118+
```

example.js

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
var apiKey = 'cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi';
2+
var easypost = require('./lib/main.js')(apiKey);
3+
4+
// set addresses
5+
var toAddress = {
6+
name: "Sawyer Bateman",
7+
street1: "1A Larkspur Cres.",
8+
street2: "",
9+
city: "St. Albert",
10+
state: "AB",
11+
zip: "t8n2m4",
12+
country: "CA",
13+
phone: "780-283-9384"
14+
};
15+
var fromAddress = {
16+
name: "Jon Calhoun",
17+
street1: "388 Townsend St",
18+
city: "San Francisco",
19+
state: "CA",
20+
zip: "94107",
21+
phone: "415-456-7890"
22+
};
23+
24+
// verify address
25+
easypost.Address.create(fromAddress, function(err, fromAddress) {
26+
fromAddress.verify(function(err, response) {
27+
if (err) {
28+
console.log('Address is invalid.');
29+
} else if (response.message !== undefined && response.message !== null) {
30+
console.log('Address is valid but has an issue: ', response.message);
31+
var verifiedAddress = response.address;
32+
} else {
33+
var verifiedAddress = response;
34+
}
35+
});
36+
});
37+
38+
// set parcel
39+
easypost.Parcel.create({
40+
predefined_package: "InvalidPackageName",
41+
weight: 21.2
42+
}, function(err, response) {
43+
console.log(err);
44+
});
45+
46+
var parcel = {
47+
length: 10.2,
48+
width: 7.8,
49+
height: 4.3,
50+
weight: 21.2
51+
};
52+
53+
54+
// create customs_info form for intl shipping
55+
var customsItem = {
56+
description: "EasyPost t-shirts",
57+
hs_tariff_number: 123456,
58+
origin_country: "US",
59+
quantity: 2,
60+
value: 96.27,
61+
weight: 21.1
62+
};
63+
64+
var customsInfo = {
65+
customs_certify: 1,
66+
customs_signer: "Hector Hammerfall",
67+
contents_type: "gift",
68+
contents_explanation: "",
69+
eel_pfc: "NOEEI 30.37(a)",
70+
non_delivery_option: "return",
71+
restriction_type: "none",
72+
restriction_comments: "",
73+
customs_items: [customsItem]
74+
};
75+
76+
// create shipment
77+
easypost.Shipment.create({
78+
to_address: toAddress,
79+
from_address: fromAddress,
80+
parcel: parcel,
81+
customs_info: customsInfo
82+
}, function(err, response) {
83+
// buy postage label with one of the rate objects
84+
// shipment.buy(rate = shipment.rates[0])
85+
// shipment.buy(rate = shipment.lowest_rate('usps'))
86+
var shipment = response;
87+
console.log(shipment);
88+
// shipment.lowestRate(['USPS', 'ups'], 'priorityMAILInternational');
89+
shipment.buy({rate: shipment.lowestRate(['USPS', 'ups'])}, function(err, response) {
90+
console.log(response);
91+
});
92+
93+
});

0 commit comments

Comments
 (0)