easypost 2.7.3 → 3.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +9 -0
  3. data/CHANGELOG +40 -0
  4. data/README.md +2 -1
  5. data/VERSION +1 -1
  6. data/easypost.gemspec +24 -19
  7. data/lib/easypost.rb +108 -118
  8. data/lib/easypost/address.rb +47 -47
  9. data/lib/easypost/batch.rb +34 -38
  10. data/lib/easypost/carrier_account.rb +4 -6
  11. data/lib/easypost/customs_info.rb +3 -2
  12. data/lib/easypost/customs_item.rb +3 -2
  13. data/lib/easypost/error.rb +25 -33
  14. data/lib/easypost/event.rb +3 -6
  15. data/lib/easypost/insurance.rb +1 -3
  16. data/lib/easypost/item.rb +4 -8
  17. data/lib/easypost/object.rb +111 -113
  18. data/lib/easypost/order.rb +20 -18
  19. data/lib/easypost/parcel.rb +1 -3
  20. data/lib/easypost/pickup.rb +19 -18
  21. data/lib/easypost/pickup_rate.rb +1 -3
  22. data/lib/easypost/postage_label.rb +1 -3
  23. data/lib/easypost/print_job.rb +1 -5
  24. data/lib/easypost/printer.rb +18 -22
  25. data/lib/easypost/rate.rb +1 -3
  26. data/lib/easypost/refund.rb +1 -3
  27. data/lib/easypost/report.rb +22 -24
  28. data/lib/easypost/resource.rb +58 -60
  29. data/lib/easypost/scan_form.rb +4 -6
  30. data/lib/easypost/shipment.rb +84 -92
  31. data/lib/easypost/tracker.rb +10 -12
  32. data/lib/easypost/user.rb +33 -37
  33. data/lib/easypost/util.rb +99 -136
  34. data/lib/easypost/webhook.rb +22 -21
  35. metadata +42 -70
  36. data/circle.yml +0 -3
  37. data/spec/address_spec.rb +0 -81
  38. data/spec/batch_spec.rb +0 -48
  39. data/spec/carrier_account_spec.rb +0 -121
  40. data/spec/insurance_spec.rb +0 -69
  41. data/spec/item_spec.rb +0 -105
  42. data/spec/order_spec.rb +0 -58
  43. data/spec/pickup_spec.rb +0 -83
  44. data/spec/report_spec.rb +0 -59
  45. data/spec/scan_form_spec.rb +0 -46
  46. data/spec/shipment_spec.rb +0 -144
  47. data/spec/spec_helper.rb +0 -10
  48. data/spec/support/constant.rb +0 -106
  49. data/spec/tracker_spec.rb +0 -94
  50. data/spec/user_spec.rb +0 -88
  51. data/spec/webhook_spec.rb +0 -75
data/circle.yml DELETED
@@ -1,3 +0,0 @@
1
- machine:
2
- ruby:
3
- version: 2.0.0
@@ -1,81 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EasyPost::Address do
4
- describe ".create_and_verify" do
5
- context "for a successful response without an address" do
6
- it "should raise an error" do
7
- expect(EasyPost).to receive(:request).and_return([{}, ""])
8
- expect {
9
- EasyPost::Address.create_and_verify(ADDRESS[:california])
10
- }.to raise_error EasyPost::Error, /Unable to verify addres/
11
- end
12
- end
13
- end
14
-
15
- describe '#create' do
16
- it 'creates an address object' do
17
- address = EasyPost::Address.create(ADDRESS[:california])
18
-
19
- expect(address).to be_an_instance_of(EasyPost::Address)
20
- expect(address.company).to eq('EasyPost')
21
- end
22
- end
23
-
24
- describe '#verify' do
25
- it 'verifies an address with an error' do
26
- address = EasyPost::Address.create(
27
- ADDRESS[:california].reject {|k,v| k == :street1 || k == :company}
28
- )
29
-
30
- expect(address.street1).to be_nil
31
- expect(address.street2).to eq('Unit 1')
32
- expect(address.city).to eq('San Francisco')
33
- expect(address.state).to eq('CA')
34
- expect(address.zip).to eq('94107')
35
- expect(address.country).to eq('US')
36
-
37
- expect {
38
- address.verify()
39
- }.to raise_error EasyPost::Error, /Unable to verify addres/
40
- end
41
-
42
- it 'verifies an address without message' do
43
- address = EasyPost::Address.create(ADDRESS[:california])
44
-
45
- expect(address.street2).to be
46
-
47
- verified_address = address.verify()
48
- expect(verified_address).to be_an_instance_of(EasyPost::Address)
49
- expect(verified_address[:message]).to be_nil
50
- end
51
-
52
- it 'verifies an address using a carrier' do
53
- address = EasyPost::Address.create(ADDRESS[:california])
54
-
55
- expect(address.company).to eq('EasyPost')
56
- expect(address.street1).to eq('164 Townsend Street')
57
- expect(address.city).to eq('San Francisco')
58
- expect(address.state).to eq('CA')
59
- expect(address.zip).to eq('94107')
60
- expect(address.country).to eq('US')
61
-
62
- verified_address = address.verify(carrier: :usps)
63
- expect(verified_address).to be_an_instance_of(EasyPost::Address)
64
- end
65
-
66
- it 'is not able to verify address' do
67
- address = EasyPost::Address.create(
68
- company: 'Simpler Postage Inc',
69
- street1: '388 Junk Teerts',
70
- street2: 'Apt 20',
71
- city: 'San Francisco',
72
- state: 'CA',
73
- zip: '941abc07'
74
- )
75
-
76
- expect {
77
- address.verify()
78
- }.to raise_error(EasyPost::Error, /Unable to verify addres/)
79
- end
80
- end
81
- end
@@ -1,48 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EasyPost::Batch do
4
- describe '#create' do
5
- it 'creates a batch object' do
6
- batch = EasyPost::Batch.create({
7
- shipment: [{
8
- from_address: ADDRESS[:california],
9
- to_address: EasyPost::Address.create(ADDRESS[:missouri]),
10
- parcel: EasyPost::Parcel.create(PARCEL[:dimensions])
11
- }, {
12
- from_address: ADDRESS[:california],
13
- to_address: EasyPost::Address.create(ADDRESS[:canada]),
14
- parcel: EasyPost::Parcel.create(PARCEL[:dimensions]),
15
- }],
16
- reference: "batch123456789"
17
- })
18
- expect(batch).to be_an_instance_of(EasyPost::Batch)
19
- expect(batch.num_shipments).to eq(2)
20
- expect(batch.reference).to eq("batch123456789")
21
- expect(batch.state).to eq("creating")
22
- end
23
- end
24
-
25
- describe '#create_and_buy' do
26
- it 'creates a batch object and delayed jobs for purchasing the postage_labels' do
27
- batch = EasyPost::Batch.create({
28
- shipment: [{
29
- from_address: ADDRESS[:california],
30
- to_address: EasyPost::Address.create(ADDRESS[:missouri]),
31
- parcel: EasyPost::Parcel.create(PARCEL[:dimensions]),
32
- carrier: "usps",
33
- service: "priority"
34
- }, {
35
- from_address: ADDRESS[:california],
36
- to_address: EasyPost::Address.create(ADDRESS[:canada]),
37
- parcel: EasyPost::Parcel.create(PARCEL[:dimensions]),
38
- carrier: "usps",
39
- service: "prioritymailinternational"
40
- }],
41
- reference: "batch123456789"
42
- })
43
- expect(batch).to be_an_instance_of(EasyPost::Batch)
44
- expect(batch.state).to eq("creating")
45
- expect(batch.num_shipments).to eq(2)
46
- end
47
- end
48
- end
@@ -1,121 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EasyPost::CarrierAccount do
4
- before do
5
- EasyPost.api_key = "PRODUCTION API KEY"
6
- end
7
-
8
- # it 'performs retrieve on a carrier account' do
9
- # id = 'ca_r8hLl9jS'
10
- # ca = EasyPost::CarrierAccount.retrieve(id)
11
- #
12
- # expect(ca.id).to eq(id)
13
- # end
14
- #
15
- # context 'perform CRUD functions' do
16
- # it 'performs all basic CRUD actions on a CarrierAccount' do
17
- # original_num_cas = EasyPost::CarrierAccount.all.count
18
- #
19
- # description = "A test Ups Account"
20
- # reference = "RubyClientUpsTestAccount"
21
- #
22
- # created_ca = EasyPost::CarrierAccount.create(
23
- # type: "UpsAccount",
24
- # description: description,
25
- # reference: reference,
26
- # credentials: {
27
- # account_number: "A1A1A1",
28
- # user_id: "UPSDOTCOM_USERNAME",
29
- # password: "UPSDOTCOM_PASSWORD",
30
- # access_license_number: "UPS_ACCESS_LICENSE_NUMBER"
31
- # }
32
- # )
33
- #
34
- # id = created_ca["id"]
35
- #
36
- # interm_num_cas = EasyPost::CarrierAccount.all.count
37
- # expect(interm_num_cas).to eq(original_num_cas + 1)
38
- #
39
- # retrieved_ca = EasyPost::CarrierAccount.retrieve(id)
40
- #
41
- # expect(retrieved_ca["id"]).to eq(created_ca["id"])
42
- # expect(retrieved_ca["description"]).to eq(description)
43
- # expect(retrieved_ca["reference"]).to eq(reference)
44
- #
45
- # updated_description = "An updated description for a test Ups Account"
46
- # updated_account_number = "B2B2B2B2"
47
- # retrieved_ca.description = updated_description
48
- # retrieved_ca.credentials = {
49
- # account_number: updated_account_number,
50
- # user_id: "UPSDOTCOM_USERNAME",
51
- # password: "UPSDOTCOM_PASSWORD",
52
- # access_license_number: "UPS_ACCESS_LICENSE_NUMBER"
53
- # }
54
- # retrieved_ca.save
55
- #
56
- # updated_ca = EasyPost::CarrierAccount.retrieve(id)
57
- # expect(updated_ca["id"]).to eq(created_ca["id"])
58
- # expect(updated_ca["description"]).to eq(updated_description)
59
- # expect(updated_ca["credentials"]["account_number"]).to eq(updated_account_number)
60
- #
61
- # reupdated_account_number = "C3C3C3C3C3"
62
- # updated_user_id = "A_NEW_UPS_USERNAME"
63
- # updated_ca.credentials[:account_number] = reupdated_account_number
64
- # updated_ca.credentials[:user_id] = updated_user_id
65
- # updated_ca.save
66
- #
67
- # reupdated_ca = EasyPost::CarrierAccount.retrieve(id)
68
- # expect(reupdated_ca["id"]).to eq(created_ca["id"])
69
- # expect(reupdated_ca["credentials"]["account_number"]).to eq(reupdated_account_number)
70
- # expect(reupdated_ca["credentials"]["user_id"]).to eq(updated_user_id)
71
- #
72
- # final_ca = reupdated_ca.save
73
- # expect(final_ca["id"]).to eq(created_ca["id"])
74
- # expect(final_ca["credentials"]["account_number"]).to eq(reupdated_account_number)
75
- # expect(final_ca["credentials"]["user_id"]).to eq(updated_user_id)
76
- #
77
- # final_ca.delete
78
- #
79
- # final_num_cas = EasyPost::CarrierAccount.all.count
80
- # expect(final_num_cas).to eq(original_num_cas)
81
- # end
82
- # end
83
- #
84
- # describe '#types' do
85
- # let(:carrier_account_types) { [
86
- # "AsendiaAccount",
87
- # "AustraliaPostAccount",
88
- # "CanadaPostAccount",
89
- # "CanparAccount",
90
- # "ColisPriveAccount",
91
- # "DhlExpressAccount",
92
- # "DhlGlobalMailAccount",
93
- # "FastwayAccount",
94
- # "FedexAccount",
95
- # "FedexSmartpostAccount",
96
- # "GsoAccount",
97
- # "LasershipAccount",
98
- # "LsoAccount",
99
- # "NorcoAccount",
100
- # "NzpostAccount",
101
- # "OntracAccount",
102
- # "PurolatorAccount",
103
- # "RoyalMailAccount",
104
- # "SpeedeeAccount",
105
- # "TntExpressAccount",
106
- # "UpsAccount",
107
- # "UpsMailInnovationsAccount",
108
- # "UpsSurepostAccount"
109
- # ] }
110
- #
111
- # it 'returns the expected list of types' do
112
- # types = EasyPost::CarrierAccount.types
113
- # account_types = types.map(&:type)
114
- #
115
- # for account_type in carrier_account_types
116
- # expect(account_types).to include(account_type)
117
- # end
118
- # end
119
- # end
120
- end
121
-
@@ -1,69 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EasyPost::Insurance do
4
- let(:tracking_code) { 'EZ2000000002' }
5
- let(:carrier) { 'usps' }
6
- let(:amount) { 101.00 }
7
-
8
- describe '#create' do
9
- it 'creates an insurance object' do
10
- insurance = EasyPost::Insurance.create(
11
- to_address: ADDRESS[:california],
12
- from_address: ADDRESS[:missouri],
13
- amount: amount,
14
- tracking_code: tracking_code,
15
- carrier: carrier
16
- )
17
-
18
- expect(insurance).to be_a(EasyPost::Insurance)
19
- expect(insurance.id).not_to be_nil
20
- expect(insurance.amount).to eq("101.00000")
21
- expect(insurance.tracking_code).to eq(tracking_code)
22
- expect(insurance.tracker).to be_a(EasyPost::Tracker)
23
- end
24
- end
25
-
26
- describe '#retrieve' do
27
- it 'creates an insurance object' do
28
- id = EasyPost::Insurance.create(
29
- to_address: ADDRESS[:california],
30
- from_address: ADDRESS[:missouri],
31
- amount: amount,
32
- tracking_code: tracking_code,
33
- carrier: carrier
34
- ).id
35
-
36
- insurance = EasyPost::Insurance.retrieve(id)
37
-
38
- expect(insurance).to be_a(EasyPost::Insurance)
39
- expect(insurance.id).to eq(id)
40
- expect(insurance.amount).to eq("101.00000")
41
- expect(insurance.tracking_code).to eq(tracking_code)
42
- expect(insurance.tracker).to be_a(EasyPost::Tracker)
43
- end
44
- end
45
-
46
-
47
- describe '#index' do
48
- it 'retrieves a full page of insurances' do
49
- insurances = EasyPost::Insurance.all(page_size: 5)
50
-
51
- expect(insurances["insurances"].count).to eq(5)
52
- expect(insurances["has_more"]).to eq(true)
53
- end
54
-
55
- it 'retrieves all insurances with given tracking code, up to a page' do
56
- insurances = EasyPost::Insurance.all(tracking_code: tracking_code, page_size: 5)
57
-
58
- expect(insurances["insurances"].count).to eq(5)
59
- expect(insurances["has_more"]).to eq(true)
60
- end
61
-
62
- it 'retrieves all insurances with given tracking code and carrier, up to a page' do
63
- insurances = EasyPost::Insurance.all(tracking_code: tracking_code, carrier: carrier, page_size: 5)
64
-
65
- expect(insurances["insurances"].count).to eq(5)
66
- expect(insurances["has_more"]).to eq(true)
67
- end
68
- end
69
- end
@@ -1,105 +0,0 @@
1
- # TODO: fix this
2
- #
3
- #require 'spec_helper'
4
- #
5
- #describe EasyPost::Item do
6
- #
7
- # describe '#create' do
8
- # it 'creates an item object', focus: true do
9
- # item = EasyPost::Item.create(
10
- # name: "Spec Item",
11
- # description: "Spec item description",
12
- # harmonized_code: "66.77.90.10",
13
- # country_of_origin: "US",
14
- # length: 6.0,
15
- # width: 11.8,
16
- # height: 12.5,
17
- # weight: 10.55,
18
- # warehouse_location: "SECTION A",
19
- # value: 96.00,
20
- # sku: "V4C3D5R2Z6",
21
- # upc: "UPCYEAHYOUKNOWME"
22
- # )
23
- # expect(item).to be_an_instance_of(EasyPost::Item)
24
- # expect(item.weight).to eq(10.55)
25
- # expect(item.harmonized_code).to eq("66.77.90.10")
26
- # expect(item.sku).to eq("V4C3D5R2Z6")
27
- # end
28
- #
29
- # it 'fails to create an item object' do
30
- # expect { EasyPost::Item.create(
31
- # length: 6,
32
- # width: 12,
33
- # height: 13,
34
- # weight: 40
35
- # ) }.to raise_exception(EasyPost::Error, /Invalid request, 'name' is required./)
36
- # end
37
- #
38
- # it 'creates an item object with default values' do
39
- # item = EasyPost::Item.create(
40
- # name: "Default Item",
41
- # length: 6.0,
42
- # width: 8.0,
43
- # height: 10,
44
- # weight: 13,
45
- # value: 19.99
46
- # )
47
- # expect(item.description).to be_nil
48
- # end
49
- # end
50
- #
51
- # describe '#retrieve' do
52
- # it 'retrieves an item by id' do
53
- # item = EasyPost::Item.create(
54
- # name: "Test Item",
55
- # sku: "28374662838",
56
- # length: 6.0,
57
- # width: 8.0,
58
- # height: 10,
59
- # weight: 13,
60
- # value: 13.00
61
- # )
62
- # id = item.id
63
- # item = nil
64
- # item = EasyPost::Item.retrieve(id)
65
- #
66
- # expect(item).to be_an_instance_of(EasyPost::Item)
67
- # expect(item.value).to eq("13.00")
68
- # expect(item.sku).to eq("28374662838")
69
- # end
70
- #
71
- # it 'retrieves an item by reference' do
72
- # item_1 = EasyPost::Item.create(
73
- # name: "Test Item",
74
- # reference: "81993736515",
75
- # length: 6.0,
76
- # width: 8.0,
77
- # height: 10,
78
- # weight: 13,
79
- # value: 13.00
80
- # )
81
- # item_2 = EasyPost::Item.retrieve(item_1.reference)
82
- #
83
- # expect(item_2).to be_an_instance_of(EasyPost::Item)
84
- # expect(item_2.reference).to eq(item_1.reference)
85
- # end
86
- #
87
- # it 'retrieves an item by custom reference' do
88
- # item_1 = EasyPost::Item.create(
89
- # name: "Test Item",
90
- # sku: "928273646",
91
- # length: 6.0,
92
- # width: 8.0,
93
- # height: 10,
94
- # weight: 13,
95
- # value: 17.38
96
- # )
97
- # item_2 = EasyPost::Item.retrieve_reference(sku: "928273646")
98
- #
99
- # expect(item_2).to be_an_instance_of(EasyPost::Item)
100
- # expect(item_2.value).to eq("17.38")
101
- # end
102
- # end
103
- #
104
- #end
105
-
@@ -1,58 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EasyPost::Order do
4
- describe '#get_rates' do
5
- it 'refreshes rates' do
6
- order = EasyPost::Order.create(
7
- to_address: ADDRESS[:california],
8
- from_address: ADDRESS[:missouri],
9
- shipments: [{
10
- parcel: {length: 8, width: 6, height: 4, weight: 12}
11
- }]
12
- )
13
-
14
- expect(order).to be_an_instance_of(EasyPost::Order)
15
- expect(order.shipments.first).to be_an_instance_of(EasyPost::Shipment)
16
-
17
- rate_id = order.shipments.first.rates.first.id
18
- expect(rate_id).not_to be_nil
19
-
20
- order.get_rates
21
-
22
- new_rate_id = order.shipments.first.rates.first.id
23
- expect(new_rate_id).not_to be_nil
24
- expect(new_rate_id).not_to eq(rate_id)
25
- end
26
- end
27
-
28
- describe '#create' do
29
- it 'creates an order out of a single shipment' do
30
- order = EasyPost::Order.create(
31
- to_address: ADDRESS[:california],
32
- from_address: ADDRESS[:missouri],
33
- shipments: [{
34
- parcel: {length: 8, width: 6, height: 4, weight: 12}
35
- }]
36
- )
37
-
38
- expect(order).to be_an_instance_of(EasyPost::Order)
39
- expect(order.shipments.first).to be_an_instance_of(EasyPost::Shipment)
40
- end
41
-
42
- it 'creates an order out of two shipments' do
43
- order = EasyPost::Order.create(
44
- to_address: ADDRESS[:california],
45
- from_address: ADDRESS[:missouri],
46
- carrier_accounts: [{id: "ca_12345678"}],
47
- shipments: [{
48
- parcel: {length: 8, width: 6, height: 4, weight: 12}
49
- },{
50
- parcel: {length: 8, width: 6, height: 4, weight: 12}
51
- }]
52
- )
53
-
54
- expect(order).to be_an_instance_of(EasyPost::Order)
55
- expect(order.shipments.first).to be_an_instance_of(EasyPost::Shipment)
56
- end
57
- end
58
- end