easypost 2.0.11 → 2.0.12

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.
@@ -1,83 +1,96 @@
1
+ require 'open-uri'
1
2
  require 'easypost'
2
3
  EasyPost.api_key = 'cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi'
3
- # EasyPost.api_base = 'http://localhost:5000/v2'
4
+ EasyPost.api_base = 'http://easypost-vm:5000/v2'
4
5
 
5
- def address_canada
6
- address = EasyPost::Address.create(
7
- :name => 'Sawyer Bateman',
8
- :street1 => '1A Larkspur Cres.',
9
- :city => 'St. Albert',
10
- :state => 'AB',
11
- :zip => 't8n2m4',
12
- :country => 'CA',
13
- :phone => '780-273-8374'
14
- )
15
- return address
16
- end
6
+ ADDRESS = {}
7
+ ADDRESS[:california] = {
8
+ :company => 'EasyPost',
9
+ :street1 => '164 Townsend Street',
10
+ :street2 => 'Unit 1',
11
+ :city => 'San Francisco',
12
+ :state => 'CA',
13
+ :zip => '94107',
14
+ :phone => '415-123-4567'
15
+ }
17
16
 
18
- def address_california
19
- {
20
- :company => 'Simpler Postage Inc',
21
- :street1 => '388 Townsend Street',
22
- :street2 => 'Apt 20',
23
- :city => 'San Francisco',
24
- :state => 'CA',
25
- :zip => '94107',
26
- :phone => '415-456-7890'
27
- }
28
- end
17
+ ADDRESS[:california_no_phone] = {
18
+ :company => 'EasyPost',
19
+ :street1 => '164 Townsend Street',
20
+ :street2 => 'Unit 1',
21
+ :city => 'San Francisco',
22
+ :state => 'CA',
23
+ :zip => '94107'
24
+ }
29
25
 
30
- def address_missouri
31
- address = EasyPost::Address.create(
32
- :company => 'Airport Shipping',
33
- :street1 => '601 Brasilia Avenue',
34
- :city => 'Kansas City',
35
- :state => 'MO',
36
- :zip => '64153',
37
- :phone => '314-924-0383',
38
- :email => 'kansas_shipping@example.com'
39
- )
40
- return address
41
- end
42
26
 
43
- def parcel_dimensions
44
- parcel = EasyPost::Parcel.create(
45
- :width => 15.2,
46
- :length => 18,
47
- :height => 9.5,
48
- :weight => 35.1
49
- )
50
- return parcel
51
- end
27
+ ADDRESS[:missouri] = EasyPost::Address.create(
28
+ :company => 'Airport Shipping',
29
+ :street1 => '601 Brasilia Avenue',
30
+ :city => 'Kansas City',
31
+ :state => 'MO',
32
+ :zip => '64153',
33
+ :phone => '314-924-0383',
34
+ :email => 'kansas_shipping@example.com'
35
+ )
52
36
 
53
- def parcel_package
54
- parcel = EasyPost::Parcel.create(
55
- :predefined_package => 'MediumFlatRateBox',
56
- :weight => 17
57
- )
58
- return parcel
59
- end
37
+ ADDRESS[:canada] = EasyPost::Address.create(
38
+ :name => 'Sawyer Bateman',
39
+ :street1 => '58 Larkspur Cres.',
40
+ :city => 'St. Albert',
41
+ :state => 'AB',
42
+ :zip => 'T8N2M4',
43
+ :country => 'CA',
44
+ :phone => '780-123-4567'
45
+ )
60
46
 
61
- def customs_info_poor
62
- customs_item = EasyPost::CustomsItem.create(
47
+ ADDRESS[:canada_no_phone] = {
48
+ :name => 'Sawyer Bateman',
49
+ :street1 => '58 Larkspur Cres.',
50
+ :city => 'St. Albert',
51
+ :state => 'AB',
52
+ :zip => 't8n2m4',
53
+ :country => 'CA',
54
+ :phone => '780-273-8374'
55
+ }
56
+
57
+ PARCEL = {}
58
+ PARCEL[:dimensions] = EasyPost::Parcel.create(
59
+ :width => 12,
60
+ :length => 16.5,
61
+ :height => 9.5,
62
+ :weight => 40.1
63
+ )
64
+
65
+ PARCEL[:dimensions_light] = EasyPost::Parcel.create(
66
+ :width => 15.2,
67
+ :length => 18,
68
+ :height => 9.5,
69
+ :weight => 3
70
+ )
71
+
72
+ PARCEL[:predefined_medium_flat_rate_box] = EasyPost::Parcel.create(
73
+ :predefined_package => 'MediumFlatRateBox',
74
+ :weight => 17
75
+ )
76
+
77
+ CUSTOMS_INFO = {}
78
+ CUSTOMS_INFO[:shirt] = EasyPost::CustomsInfo.create(
79
+ :integrated_form_type => 'form_2976',
80
+ :customs_certify => true,
81
+ :customs_signer => 'Dr. Pepper',
82
+ :contents_type => 'gift',
83
+ :contents_explanation => '', # only required when contents_type => 'other'
84
+ :eel_pfc => 'NOEEI 30.37(a)',
85
+ :non_delivery_option => 'abandon',
86
+ :restriction_type => 'none',
87
+ :restriction_comments => '',
88
+ :customs_items => [{
63
89
  :description => 'EasyPost T-shirts',
64
90
  :quantity => 2,
65
91
  :value => 23.56,
66
- :weight => 33,
92
+ :weight => 20,
67
93
  :origin_country => 'us',
68
94
  :hs_tariff_number => 123456
69
- )
70
- customs_info = EasyPost::CustomsInfo.create(
71
- :integrated_form_type => 'form_2976',
72
- :customs_certify => true,
73
- :customs_signer => 'Dr. Pepper',
74
- :contents_type => 'gift',
75
- :contents_explanation => '', # only required when contents_type => 'other'
76
- :eel_pfc => 'NOEEI 30.37(a)',
77
- :non_delivery_option => 'abandon',
78
- :restriction_type => 'none',
79
- :restriction_comments => '',
80
- :customs_items => [customs_item]
81
- )
82
- return customs_info
83
- end
95
+ }]
96
+ )
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ups domestic' do
4
+ before(:all) do
5
+ @rates = {}
6
+ end
7
+
8
+ it 'buys an air label' do
9
+ shipment = EasyPost::Shipment.create(
10
+ :to_address => ADDRESS[:california],
11
+ :from_address => ADDRESS[:missouri],
12
+ :parcel => PARCEL[:dimensions]
13
+ )
14
+ shipment.buy(:rate => shipment.lowest_rate("ups", "NextDayAir"))
15
+ label = open(shipment.postage_label.label_url)
16
+
17
+
18
+ expect(shipment).to be_an_instance_of(EasyPost::Shipment)
19
+ expect(shipment.selected_rate).to be_an_instance_of(EasyPost::Rate)
20
+ expect(shipment.selected_rate.service).to eq("NextDayAir")
21
+ expect(shipment.postage_label.label_url).to end_with(".png")
22
+ expect(shipment.tracking_code).to start_with("1Z")
23
+ expect(label.size).to be > 5000
24
+
25
+ @rates[:next_day_air] = shipment.selected_rate
26
+ end
27
+
28
+ it 'buys a residential ground label' do
29
+ shipment = EasyPost::Shipment.create(
30
+ :to_address => ADDRESS[:california],
31
+ :from_address => ADDRESS[:missouri],
32
+ :parcel => PARCEL[:dimensions],
33
+ :options => {:residential_to_address => true}
34
+ )
35
+ shipment.buy(:rate => shipment.lowest_rate("ups", "Ground"))
36
+ label = open(shipment.postage_label.label_url)
37
+
38
+ expect(shipment.selected_rate.service).to eq("Ground")
39
+ expect(shipment.tracking_code).to start_with("1Z")
40
+ expect(label.size).to be > 5000
41
+
42
+ @rates[:ground] = shipment.selected_rate
43
+ end
44
+
45
+ it 'buys a label for an alcoholic shipment and epl2 label' do
46
+ shipment = EasyPost::Shipment.create(
47
+ :to_address => ADDRESS[:california],
48
+ :from_address => ADDRESS[:missouri],
49
+ :parcel => PARCEL[:dimensions],
50
+ :options => {alcohol: true, label_format: "epl2"}
51
+ )
52
+ shipment.buy(:rate => shipment.lowest_rate("ups", "Ground"))
53
+
54
+ expect(shipment.postage_label.label_url).to end_with(".epl2")
55
+ end
56
+
57
+ after(:all) do
58
+ begin
59
+ expect(@rates[:next_day_air].rate.to_i).to be > @rates[:ground].rate.to_i
60
+ rescue
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ups international' do
4
+ before(:all) do
5
+ @rates = {}
6
+ end
7
+
8
+ it 'buys a UPSStandard label' do
9
+ shipment = EasyPost::Shipment.create(
10
+ :to_address => ADDRESS[:canada],
11
+ :from_address => ADDRESS[:california],
12
+ :parcel => PARCEL[:dimensions],
13
+ :customs_info => CUSTOMS_INFO[:shirt]
14
+ )
15
+ shipment.buy(:rate => shipment.lowest_rate("ups", "UPSStandard"))
16
+ label = open(shipment.postage_label.label_url)
17
+
18
+ expect(shipment).to be_an_instance_of(EasyPost::Shipment)
19
+ expect(shipment.selected_rate).to be_an_instance_of(EasyPost::Rate)
20
+ expect(shipment.selected_rate.service).to eq("UPSStandard")
21
+ expect(shipment.postage_label.label_url).to end_with(".png")
22
+ expect(shipment.tracking_code).to start_with("1Z")
23
+ expect(label.size).to be > 5000
24
+
25
+ @rates[:ground] = shipment.selected_rate
26
+ end
27
+
28
+ it 'buys an air label' do
29
+ shipment = EasyPost::Shipment.create(
30
+ :to_address => ADDRESS[:canada],
31
+ :from_address => ADDRESS[:california],
32
+ :parcel => PARCEL[:dimensions],
33
+ :customs_info => CUSTOMS_INFO[:shirt]
34
+ )
35
+ shipment.buy(:rate => shipment.lowest_rate("ups", "Expedited"))
36
+ label = open(shipment.postage_label.label_url)
37
+
38
+ expect(shipment.selected_rate.service).to eq("Expedited")
39
+ expect(shipment.tracking_code).to start_with("1Z")
40
+ expect(label.size).to be > 20000
41
+
42
+ @rates[:express] = shipment.selected_rate
43
+ end
44
+
45
+ it 'returns no rates for an alcohol shipment' do
46
+ shipment = EasyPost::Shipment.create(
47
+ :to_address => ADDRESS[:canada],
48
+ :from_address => ADDRESS[:california],
49
+ :parcel => PARCEL[:dimensions],
50
+ :customs_info => CUSTOMS_INFO[:shirt],
51
+ :options => {:alcohol => true}
52
+ )
53
+
54
+ expect { shipment.lowest_rate("ups") }.to raise_exception(EasyPost::Error, /No rates found/)
55
+ end
56
+
57
+ after(:all) do
58
+ begin
59
+ expect(@rates[:air].rate.to_i).to be > @rates[:ground].rate.to_i
60
+ rescue
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'usps domestic' do
4
+ before(:all) do
5
+ @first = EasyPost::Shipment.create(
6
+ :to_address => ADDRESS[:california],
7
+ :from_address => ADDRESS[:missouri],
8
+ :parcel => PARCEL[:dimensions_light]
9
+ )
10
+ @first.buy(:rate => @first.lowest_rate("usps", "first"))
11
+
12
+ @priority = EasyPost::Shipment.create(
13
+ :to_address => ADDRESS[:california],
14
+ :from_address => ADDRESS[:missouri],
15
+ :parcel => PARCEL[:dimensions]
16
+ )
17
+ @priority.buy(:rate => @priority.lowest_rate("usps", "priority"))
18
+
19
+ @return = EasyPost::Shipment.create(
20
+ :to_address => ADDRESS[:california],
21
+ :from_address => ADDRESS[:missouri],
22
+ :parcel => PARCEL[:dimensions],
23
+ :is_return => true
24
+ )
25
+ @return.buy(:rate => @return.lowest_rate("usps", "priority"))
26
+
27
+ end
28
+
29
+ it 'buys a first label' do
30
+ expect(@first).to be_an_instance_of(EasyPost::Shipment)
31
+ expect(@first.selected_rate).to be_an_instance_of(EasyPost::Rate)
32
+ expect(@first.selected_rate.service).to eq("First")
33
+ expect(@first.postage_label.label_url).to end_with(".png")
34
+ expect(@first.tracking_code).to eq("9499907123456123456781")
35
+
36
+ label = open(@first.postage_label.label_url)
37
+ expect(label.size).to be > 30000
38
+ end
39
+
40
+ it 'buys a priority label' do
41
+ expect(@priority.selected_rate.service).to eq("Priority")
42
+ expect(@priority.tracking_code).to eq("9499907123456123456781")
43
+
44
+ label = open(@priority.postage_label.label_url)
45
+ expect(label.size).to be > 30000
46
+ end
47
+
48
+ it 'buys a return label' do
49
+ expect(@priority.selected_rate.service).to eq("Priority")
50
+ expect(@priority.tracking_code).to eq("9499907123456123456781")
51
+
52
+ label = open(@priority.postage_label.label_url)
53
+ expect(label.size).to be > 30000
54
+ end
55
+
56
+ it 'omits rates for alcohol shipments' do
57
+ shipment = EasyPost::Shipment.create(
58
+ :to_address => ADDRESS[:california],
59
+ :from_address => ADDRESS[:missouri],
60
+ :parcel => PARCEL[:dimensions],
61
+ :options => {:alcohol => true}
62
+ )
63
+ expect { shipment.buy(rate: shipment.lowest_rate('usps')) }.to raise_exception
64
+ end
65
+
66
+ end
@@ -0,0 +1,94 @@
1
+ # require 'spec_helper'
2
+
3
+ # describe 'usps electronic merchandise return service' do
4
+ # before(:all) do
5
+ # @first = EasyPost::Shipment.create(
6
+ # :to_address => ADDRESS[:california],
7
+ # :from_address => ADDRESS[:missouri],
8
+ # :parcel => PARCEL[:dimensions_light],
9
+ # :is_return => true
10
+ # )
11
+ # @first.buy(:rate => @first.lowest_rate("USPSElectronicMerchandiseReturn",
12
+ # "First"))
13
+
14
+ # @priority = EasyPost::Shipment.create(
15
+ # :to_address => ADDRESS[:california],
16
+ # :from_address => ADDRESS[:missouri],
17
+ # :parcel => PARCEL[:dimensions],
18
+ # :is_return => true
19
+ # )
20
+ # @priority.buy(:rate => @priority.lowest_rate("USPSElectronicMerchandiseReturn",
21
+ # "Priority"))
22
+
23
+ # @bpm = EasyPost::Shipment.create(
24
+ # :to_address => ADDRESS[:california],
25
+ # :from_address => ADDRESS[:missouri],
26
+ # :parcel => PARCEL[:dimensions_light],
27
+ # :is_return => true
28
+ # )
29
+ # @bpm.buy(:rate => @bpm.lowest_rate("USPSElectronicMerchandiseReturn",
30
+ # "BoundPrintedMatter"))
31
+
32
+ # @media = EasyPost::Shipment.create(
33
+ # :to_address => ADDRESS[:california],
34
+ # :from_address => ADDRESS[:missouri],
35
+ # :parcel => PARCEL[:dimensions],
36
+ # :is_return => true
37
+ # )
38
+ # @media.buy(:rate => @media.lowest_rate("USPSElectronicMerchandiseReturn",
39
+ # "MediaMail"))
40
+
41
+ # @library = EasyPost::Shipment.create(
42
+ # :to_address => ADDRESS[:california],
43
+ # :from_address => ADDRESS[:missouri],
44
+ # :parcel => PARCEL[:dimensions],
45
+ # :is_return => true
46
+ # )
47
+ # @library.buy(:rate => @library.lowest_rate("USPSElectronicMerchandiseReturn",
48
+ # "LibraryMail"))
49
+ # end
50
+
51
+ # it 'buys a first label' do
52
+ # expect(@first).to be_an_instance_of(EasyPost::Shipment)
53
+ # expect(@first.selected_rate).to be_an_instance_of(EasyPost::Rate)
54
+ # expect(@first.selected_rate.service).to eq("First")
55
+ # expect(@first.postage_label.label_url).to end_with(".png")
56
+ # expect(@first.tracking_code).to eq("9499907123456123456781")
57
+
58
+ # label = open(@first.postage_label.label_url)
59
+ # expect(label.size).to be > 30000
60
+ # end
61
+
62
+ # it 'buys a priority label' do
63
+ # expect(@priority.selected_rate.service).to eq("Priority")
64
+ # expect(@priority.tracking_code).to eq("9499907123456123456781")
65
+
66
+ # label = open(@priority.postage_label.label_url)
67
+ # expect(label.size).to be > 30000
68
+ # end
69
+
70
+ # it 'buys a bpm label' do
71
+ # expect(@bpm.selected_rate.service).to eq("BoundPrintedMatter")
72
+ # expect(@bpm.tracking_code).to eq("9499907123456123456781")
73
+
74
+ # label = open(@bpm.postage_label.label_url)
75
+ # expect(label.size).to be > 30000
76
+ # end
77
+
78
+ # it 'buys a media mail label' do
79
+ # expect(@media.selected_rate.service).to eq("MediaMail")
80
+ # expect(@media.tracking_code).to eq("9499907123456123456781")
81
+
82
+ # label = open(@media.postage_label.label_url)
83
+ # expect(label.size).to be > 30000
84
+ # end
85
+
86
+ # it 'buys a library mail label' do
87
+ # expect(@library.selected_rate.service).to eq("LibraryMail")
88
+ # expect(@library.tracking_code).to eq("9499907123456123456781")
89
+
90
+ # label = open(@library.postage_label.label_url)
91
+ # expect(label.size).to be > 30000
92
+ # end
93
+
94
+ # end