fedex 2.0.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -1
- data/Readme.md +81 -3
- data/fedex.gemspec +2 -2
- data/lib/fedex/address.rb +30 -0
- data/lib/fedex/helpers.rb +5 -4
- data/lib/fedex/label.rb +44 -3
- data/lib/fedex/request/address.rb +92 -0
- data/lib/fedex/request/base.rb +39 -26
- data/lib/fedex/request/label.rb +10 -75
- data/lib/fedex/request/rate.rb +3 -3
- data/lib/fedex/request/shipment.rb +106 -0
- data/lib/fedex/request/tracking_information.rb +89 -0
- data/lib/fedex/shipment.rb +23 -1
- data/lib/fedex/tracking_information.rb +49 -0
- data/lib/fedex/tracking_information/event.rb +19 -0
- data/lib/fedex/version.rb +1 -1
- data/spec/lib/fedex/address_spec.rb +39 -0
- data/spec/lib/fedex/label_spec.rb +33 -18
- data/spec/lib/fedex/rate_spec.rb +149 -0
- data/spec/lib/fedex/shipment_spec.rb +33 -138
- data/spec/lib/fedex/track_spec.rb +50 -0
- data/spec/spec_helper.rb +4 -2
- data/spec/support/credentials.rb +15 -0
- metadata +29 -14
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
|
2
|
+
require 'tmpdir'
|
3
3
|
module Fedex
|
4
4
|
describe Label do
|
5
5
|
describe "ship service for label" do
|
@@ -21,34 +21,49 @@ module Fedex
|
|
21
21
|
let(:shipping_options) do
|
22
22
|
{ :packaging_type => "YOUR_PACKAGING", :drop_off_type => "REGULAR_PICKUP" }
|
23
23
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
File.join(Dir.tmpdir, "label#{rand(15000)}.pdf")
|
24
|
+
|
25
|
+
let(:label_specification) do
|
26
|
+
{ :label_format_type => 'COMMON2D',
|
27
|
+
:image_type => 'PNG',
|
29
28
|
}
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:filename) {
|
32
|
+
require 'tmpdir'
|
33
|
+
File.join(Dir.tmpdir, "label#{rand(15000)}.pdf")
|
34
|
+
}
|
35
|
+
|
36
|
+
let(:options) do
|
37
|
+
{ :shipper => shipper,
|
38
|
+
:recipient => recipient,
|
39
|
+
:packages => packages,
|
40
|
+
:service_type => "FEDEX_GROUND",
|
41
|
+
:label_specification => label_specification,
|
42
|
+
:filename => filename
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "label", :vcr do
|
34
47
|
before do
|
35
48
|
@label = fedex.label(options)
|
36
49
|
end
|
37
|
-
|
38
|
-
it "
|
39
|
-
@label.should be_an_instance_of(Label)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "creates a label file" do
|
50
|
+
|
51
|
+
it "should create a label" do
|
43
52
|
File.should exist(filename)
|
44
53
|
end
|
45
|
-
|
54
|
+
|
55
|
+
it "should return tracking number" do
|
56
|
+
@label.should respond_to('tracking_number')
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should expose complete response" do
|
60
|
+
@label.should respond_to('response_details')
|
61
|
+
end
|
46
62
|
after do
|
47
63
|
require 'fileutils'
|
48
64
|
FileUtils.rm_r(filename) if File.exist?(filename)
|
49
65
|
end
|
50
66
|
end
|
51
|
-
|
52
67
|
end
|
53
68
|
end
|
54
69
|
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Fedex
|
4
|
+
describe Shipment do
|
5
|
+
context "missing required parameters" do
|
6
|
+
it "should raise Rate exception" do
|
7
|
+
lambda{ Shipment.new}.should raise_error(RateError)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context "required parameters present" do
|
12
|
+
subject { Shipment.new(fedex_credentials) }
|
13
|
+
it "should create a valid instance" do
|
14
|
+
subject.should be_an_instance_of(Shipment)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "rate service" do
|
19
|
+
let(:fedex) { Shipment.new(fedex_credentials) }
|
20
|
+
let(:shipper) do
|
21
|
+
{:name => "Sender", :company => "Company", :phone_number => "555-555-5555", :address => "Main Street", :city => "Harrison", :state => "AR", :postal_code => "72601", :country_code => "US"}
|
22
|
+
end
|
23
|
+
let(:recipient) do
|
24
|
+
{:name => "Recipient", :company => "Company", :phone_number => "555-555-5555", :address => "Main Street", :city => "Frankin Park", :state => "IL", :postal_code => "60131", :country_code => "US", :residential => true }
|
25
|
+
end
|
26
|
+
let(:packages) do
|
27
|
+
[
|
28
|
+
{
|
29
|
+
:weight => {:units => "LB", :value => 2},
|
30
|
+
:dimensions => {:length => 10, :width => 5, :height => 4, :units => "IN" }
|
31
|
+
},
|
32
|
+
{
|
33
|
+
:weight => {:units => "LB", :value => 6},
|
34
|
+
:dimensions => {:length => 5, :width => 5, :height => 4, :units => "IN" }
|
35
|
+
}
|
36
|
+
]
|
37
|
+
end
|
38
|
+
let(:shipping_options) do
|
39
|
+
{ :packaging_type => "YOUR_PACKAGING", :drop_off_type => "REGULAR_PICKUP" }
|
40
|
+
end
|
41
|
+
|
42
|
+
context "domestic shipment", :vcr do
|
43
|
+
it "should return a rate" do
|
44
|
+
rate = fedex.rate({:shipper => shipper, :recipient => recipient, :packages => packages, :service_type => "FEDEX_GROUND"})
|
45
|
+
rate.should be_an_instance_of(Rate)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "canadian shipment", :vcr do
|
50
|
+
it "should return a rate" do
|
51
|
+
canadian_recipient = {:name => "Recipient", :company => "Company", :phone_number => "555-555-5555", :address=>"Address Line 1", :city => "Richmond", :state => "BC", :postal_code => "V7C4V4", :country_code => "CA", :residential => "true" }
|
52
|
+
rate = fedex.rate({:shipper => shipper, :recipient => canadian_recipient, :packages => packages, :service_type => "FEDEX_GROUND"})
|
53
|
+
rate.should be_an_instance_of(Rate)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "canadian shipment including customs", :vcr do
|
58
|
+
it "should return a rate including international fees" do
|
59
|
+
canadian_recipient = {:name => "Recipient", :company => "Company", :phone_number => "555-555-5555", :address=>"Address Line 1", :city => "Richmond", :state => "BC", :postal_code => "V7C4V4", :country_code => "CA", :residential => "true" }
|
60
|
+
broker = {
|
61
|
+
:account_number => "510087143",
|
62
|
+
:tins => { :tin_type => "BUSINESS_NATIONAL",
|
63
|
+
:number => "431870271",
|
64
|
+
:usage => "Usage" },
|
65
|
+
:contact => { :contact_id => "1",
|
66
|
+
:person_name => "Broker Name",
|
67
|
+
:title => "Broker",
|
68
|
+
:company_name => "Broker One",
|
69
|
+
:phone_number => "555-555-5555",
|
70
|
+
:phone_extension => "555-555-5555",
|
71
|
+
:pager_number => "555",
|
72
|
+
:fax_number=> "555-555-5555",
|
73
|
+
:e_mail_address => "contact@me.com" },
|
74
|
+
:address => { :street_lines => "Main Street",
|
75
|
+
:city => "Franklin Park",
|
76
|
+
:state_or_province_code => 'IL',
|
77
|
+
:postal_code => '60131',
|
78
|
+
:urbanization_code => '123',
|
79
|
+
:country_code => 'US',
|
80
|
+
:residential => 'false' }
|
81
|
+
}
|
82
|
+
|
83
|
+
clearance_brokerage = "BROKER_INCLUSIVE"
|
84
|
+
|
85
|
+
importer_of_record= {
|
86
|
+
:account_number => "22222",
|
87
|
+
:tins => { :tin_type => "BUSINESS_NATIONAL",
|
88
|
+
:number => "22222",
|
89
|
+
:usage => "Usage" },
|
90
|
+
:contact => { :contact_id => "1",
|
91
|
+
:person_name => "Importer Name",
|
92
|
+
:title => "Importer",
|
93
|
+
:company_name => "Importer One",
|
94
|
+
:phone_number => "555-555-5555",
|
95
|
+
:phone_extension => "555-555-5555",
|
96
|
+
:pager_number => "555",
|
97
|
+
:fax_number=> "555-555-5555",
|
98
|
+
:e_mail_address => "contact@me.com" },
|
99
|
+
:address => { :street_lines => "Main Street",
|
100
|
+
:city => "Chicago",
|
101
|
+
:state_or_province_code => 'IL',
|
102
|
+
:postal_code => '60611',
|
103
|
+
:urbanization_code => '2308',
|
104
|
+
:country_code => 'US',
|
105
|
+
:residential => 'false' }
|
106
|
+
}
|
107
|
+
|
108
|
+
recipient_customs_id = { :type => 'COMPANY',
|
109
|
+
:value => '1254587' }
|
110
|
+
|
111
|
+
|
112
|
+
duties_payment = { :payment_type => "SENDER",
|
113
|
+
:payor => { :account_number => "510087143",
|
114
|
+
:country_code => "US" } }
|
115
|
+
|
116
|
+
customs_value = { :currency => "USD",
|
117
|
+
:amount => "200" }
|
118
|
+
commodities = [{
|
119
|
+
:name => "Cotton Coat",
|
120
|
+
:number_of_pieces => "2",
|
121
|
+
:description => "Cotton Coat",
|
122
|
+
:country_of_manufacture => "US",
|
123
|
+
:harmonized_code => "6103320000",
|
124
|
+
:weight => {:units => "LB", :value => "2"},
|
125
|
+
:quantity => "3",
|
126
|
+
:unit_price => {:currency => "USD", :amount => "50" },
|
127
|
+
:customs_value => {:currency => "USD", :amount => "150" }
|
128
|
+
},
|
129
|
+
{
|
130
|
+
:name => "Poster",
|
131
|
+
:number_of_pieces => "1",
|
132
|
+
:description => "Paper Poster",
|
133
|
+
:country_of_manufacture => "US",
|
134
|
+
:harmonized_code => "4817100000",
|
135
|
+
:weight => {:units => "LB", :value => "0.2"},
|
136
|
+
:quantity => "3",
|
137
|
+
:unit_price => {:currency => "USD", :amount => "50" },
|
138
|
+
:customs_value => {:currency => "USD", :amount => "150" }
|
139
|
+
}
|
140
|
+
]
|
141
|
+
|
142
|
+
customs_clearance = { :broker => broker, :clearance_brokerage => clearance_brokerage, :importer_of_record => importer_of_record, :recipient_customs_id => recipient_customs_id, :duties_payment => duties_payment, :commodities => commodities }
|
143
|
+
rate = fedex.rate({:shipper => shipper, :recipient => canadian_recipient, :packages => packages, :service_type => "FEDEX_GROUND", :customs_clearance => customs_clearance})
|
144
|
+
rate.should be_an_instance_of(Rate)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -1,149 +1,44 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'fedex/shipment'
|
2
3
|
|
3
|
-
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
4
|
+
describe Fedex::Request::Shipment do
|
5
|
+
describe "ship service" do
|
6
|
+
let(:fedex) { Fedex::Shipment.new(fedex_credentials) }
|
7
|
+
let(:shipper) do
|
8
|
+
{:name => "Sender", :company => "Company", :phone_number => "555-555-5555", :address => "Main Street", :city => "Harrison", :state => "AR", :postal_code => "72601", :country_code => "US"}
|
9
9
|
end
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
let(:recipient) do
|
11
|
+
{:name => "Recipient", :company => "Company", :phone_number => "555-555-5555", :address => "Main Street", :city => "Frankin Park", :state => "IL", :postal_code => "60131", :country_code => "US", :residential => true }
|
12
|
+
end
|
13
|
+
let(:packages) do
|
14
|
+
[
|
15
|
+
{
|
16
|
+
:weight => {:units => "LB", :value => 2},
|
17
|
+
:dimensions => {:length => 10, :width => 5, :height => 4, :units => "IN" }
|
18
|
+
}
|
19
|
+
]
|
20
|
+
end
|
21
|
+
let(:shipping_options) do
|
22
|
+
{ :packaging_type => "YOUR_PACKAGING", :drop_off_type => "REGULAR_PICKUP" }
|
16
23
|
end
|
17
24
|
|
18
|
-
|
19
|
-
let(:
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
let(:
|
24
|
-
{:
|
25
|
-
end
|
26
|
-
let(:packages) do
|
27
|
-
[
|
28
|
-
{
|
29
|
-
:weight => {:units => "LB", :value => 2},
|
30
|
-
:dimensions => {:length => 10, :width => 5, :height => 4, :units => "IN" }
|
31
|
-
},
|
32
|
-
{
|
33
|
-
:weight => {:units => "LB", :value => 6},
|
34
|
-
:dimensions => {:length => 5, :width => 5, :height => 4, :units => "IN" }
|
35
|
-
}
|
36
|
-
]
|
37
|
-
end
|
38
|
-
let(:shipping_options) do
|
39
|
-
{ :packaging_type => "YOUR_PACKAGING", :drop_off_type => "REGULAR_PICKUP" }
|
40
|
-
end
|
41
|
-
|
42
|
-
context "domestic shipment", :vcr do
|
43
|
-
it "should return a rate" do
|
44
|
-
rate = fedex.rate({:shipper => shipper, :recipient => recipient, :packages => packages, :service_type => "FEDEX_GROUND"})
|
45
|
-
rate.should be_an_instance_of(Rate)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context "canadian shipment", :vcr do
|
50
|
-
it "should return a rate" do
|
51
|
-
canadian_recipient = {:name => "Recipient", :company => "Company", :phone_number => "555-555-5555", :address=>"Address Line 1", :city => "Richmond", :state => "BC", :postal_code => "V7C4V4", :country_code => "CA", :residential => "true" }
|
52
|
-
rate = fedex.rate({:shipper => shipper, :recipient => canadian_recipient, :packages => packages, :service_type => "FEDEX_GROUND"})
|
53
|
-
rate.should be_an_instance_of(Rate)
|
54
|
-
end
|
25
|
+
context "domestic shipment", :vcr do
|
26
|
+
let(:filename) {
|
27
|
+
require 'tmpdir'
|
28
|
+
File.join(Dir.tmpdir, "label#{rand(15000)}.pdf")
|
29
|
+
}
|
30
|
+
let(:options) do
|
31
|
+
{:shipper => shipper, :recipient => recipient, :packages => packages, :service_type => "FEDEX_GROUND", :filename => filename}
|
55
32
|
end
|
56
33
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
:account_number => "510087143",
|
62
|
-
:tins => { :tin_type => "BUSINESS_NATIONAL",
|
63
|
-
:number => "431870271",
|
64
|
-
:usage => "Usage" },
|
65
|
-
:contact => { :contact_id => "1",
|
66
|
-
:person_name => "Broker Name",
|
67
|
-
:title => "Broker",
|
68
|
-
:company_name => "Broker One",
|
69
|
-
:phone_number => "555-555-5555",
|
70
|
-
:phone_extension => "555-555-5555",
|
71
|
-
:pager_number => "555",
|
72
|
-
:fax_number=> "555-555-5555",
|
73
|
-
:e_mail_address => "contact@me.com" },
|
74
|
-
:address => { :street_lines => "Main Street",
|
75
|
-
:city => "Franklin Park",
|
76
|
-
:state_or_province_code => 'IL',
|
77
|
-
:postal_code => '60131',
|
78
|
-
:urbanization_code => '123',
|
79
|
-
:country_code => 'US',
|
80
|
-
:residential => 'false' }
|
81
|
-
}
|
82
|
-
|
83
|
-
clearance_brokerage = "BROKER_INCLUSIVE"
|
84
|
-
|
85
|
-
importer_of_record= {
|
86
|
-
:account_number => "22222",
|
87
|
-
:tins => { :tin_type => "BUSINESS_NATIONAL",
|
88
|
-
:number => "22222",
|
89
|
-
:usage => "Usage" },
|
90
|
-
:contact => { :contact_id => "1",
|
91
|
-
:person_name => "Importer Name",
|
92
|
-
:title => "Importer",
|
93
|
-
:company_name => "Importer One",
|
94
|
-
:phone_number => "555-555-5555",
|
95
|
-
:phone_extension => "555-555-5555",
|
96
|
-
:pager_number => "555",
|
97
|
-
:fax_number=> "555-555-5555",
|
98
|
-
:e_mail_address => "contact@me.com" },
|
99
|
-
:address => { :street_lines => "Main Street",
|
100
|
-
:city => "Chicago",
|
101
|
-
:state_or_province_code => 'IL',
|
102
|
-
:postal_code => '60611',
|
103
|
-
:urbanization_code => '2308',
|
104
|
-
:country_code => 'US',
|
105
|
-
:residential => 'false' }
|
106
|
-
}
|
107
|
-
|
108
|
-
recipient_customs_id = { :type => 'COMPANY',
|
109
|
-
:value => '1254587' }
|
34
|
+
it "succeeds" do
|
35
|
+
expect {
|
36
|
+
@shipment = fedex.ship(options)
|
37
|
+
}.to_not raise_error
|
110
38
|
|
111
|
-
|
112
|
-
duties_payment = { :payment_type => "SENDER",
|
113
|
-
:payor => { :account_number => "510087143",
|
114
|
-
:country_code => "US" } }
|
115
|
-
|
116
|
-
customs_value = { :currency => "USD",
|
117
|
-
:amount => "200" }
|
118
|
-
commodities = [{
|
119
|
-
:name => "Cotton Coat",
|
120
|
-
:number_of_pieces => "2",
|
121
|
-
:description => "Cotton Coat",
|
122
|
-
:country_of_manufacture => "US",
|
123
|
-
:harmonized_code => "6103320000",
|
124
|
-
:weight => {:units => "LB", :value => "2"},
|
125
|
-
:quantity => "3",
|
126
|
-
:unit_price => {:currency => "USD", :amount => "50" },
|
127
|
-
:customs_value => {:currency => "USD", :amount => "150" }
|
128
|
-
},
|
129
|
-
{
|
130
|
-
:name => "Poster",
|
131
|
-
:number_of_pieces => "1",
|
132
|
-
:description => "Paper Poster",
|
133
|
-
:country_of_manufacture => "US",
|
134
|
-
:harmonized_code => "4817100000",
|
135
|
-
:weight => {:units => "LB", :value => "0.2"},
|
136
|
-
:quantity => "3",
|
137
|
-
:unit_price => {:currency => "USD", :amount => "50" },
|
138
|
-
:customs_value => {:currency => "USD", :amount => "150" }
|
139
|
-
}
|
140
|
-
]
|
141
|
-
|
142
|
-
customs_clearance = { :broker => broker, :clearance_brokerage => clearance_brokerage, :importer_of_record => importer_of_record, :recipient_customs_id => recipient_customs_id, :duties_payment => duties_payment, :commodities => commodities }
|
143
|
-
rate = fedex.rate({:shipper => shipper, :recipient => canadian_recipient, :packages => packages, :service_type => "FEDEX_GROUND", :customs_clearance => customs_clearance})
|
144
|
-
rate.should be_an_instance_of(Rate)
|
145
|
-
end
|
39
|
+
@shipment.class.should_not == Fedex::RateError
|
146
40
|
end
|
147
41
|
end
|
42
|
+
|
148
43
|
end
|
149
|
-
end
|
44
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Fedex
|
4
|
+
describe TrackingInformation do
|
5
|
+
let(:fedex) { Shipment.new(fedex_credentials) }
|
6
|
+
|
7
|
+
context "shipments with tracking number", :vcr, :focus do
|
8
|
+
let(:options) do
|
9
|
+
{ :package_id => "077973360403984",
|
10
|
+
:package_type => "TRACKING_NUMBER_OR_DOORTAG",
|
11
|
+
:include_detailed_scans => true
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns events with tracking information" do
|
16
|
+
tracking_info = fedex.track(options)
|
17
|
+
|
18
|
+
tracking_info.events.count.should == 7
|
19
|
+
end
|
20
|
+
|
21
|
+
it "fails if using an invalid package type" do
|
22
|
+
fail_options = options
|
23
|
+
|
24
|
+
fail_options[:package_type] = "UNKNOWN_PACKAGE"
|
25
|
+
|
26
|
+
lambda { fedex.track(options) }.should raise_error
|
27
|
+
end
|
28
|
+
|
29
|
+
it "allows short hand tracking number queries" do
|
30
|
+
shorthand_options = options
|
31
|
+
|
32
|
+
shorthand_options.delete(:package_type)
|
33
|
+
tracking_number = shorthand_options.delete(:package_id)
|
34
|
+
|
35
|
+
shorthand_options[:tracking_number] = tracking_number
|
36
|
+
|
37
|
+
tracking_info = fedex.track(shorthand_options)
|
38
|
+
|
39
|
+
tracking_info.tracking_number.should == tracking_number
|
40
|
+
end
|
41
|
+
|
42
|
+
it "reports the status of the package" do
|
43
|
+
tracking_info = fedex.track(options)
|
44
|
+
|
45
|
+
tracking_info.status.should == "Delivered"
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|