fedex 3.4.0 → 3.6.0
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.
- data/.gitignore +1 -0
- data/Readme.md +18 -10
- data/fedex.gemspec +1 -0
- data/lib/fedex/request/address.rb +1 -1
- data/lib/fedex/request/base.rb +16 -11
- data/lib/fedex/request/rate.rb +2 -2
- data/lib/fedex/request/shipment.rb +3 -3
- data/lib/fedex/version.rb +2 -1
- data/spec/lib/fedex/document_spec.rb +1 -1
- data/spec/lib/fedex/rate_spec.rb +1 -1
- data/spec/lib/fedex/shipment_spec.rb +23 -0
- metadata +23 -12
data/.gitignore
CHANGED
data/Readme.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Fedex Rate Web Service
|
2
|
-
|
2
|
+
## Fedex API Shipment Version: 13
|
3
3
|
|
4
4
|
For more information visit [Fedex Web Services for Shipping](https://www.fedex.com/wpor/web/jsp/drclinks.jsp?links=wss/index.html).
|
5
5
|
|
@@ -11,14 +11,6 @@ Note: Please make sure to test your results.
|
|
11
11
|
|
12
12
|
# Installation:
|
13
13
|
|
14
|
-
Rails 3.x using Bundler's Gemfile:
|
15
|
-
|
16
|
-
```ruby
|
17
|
-
gem 'fedex'
|
18
|
-
````
|
19
|
-
|
20
|
-
Rails 2.x or without Rails or Bundler:
|
21
|
-
|
22
14
|
```ruby
|
23
15
|
gem install fedex
|
24
16
|
```
|
@@ -28,6 +20,7 @@ gem install fedex
|
|
28
20
|
Define the shipper:
|
29
21
|
|
30
22
|
```ruby
|
23
|
+
|
31
24
|
shipper = { :name => "Sender",
|
32
25
|
:company => "Company",
|
33
26
|
:phone_number => "555-555-5555",
|
@@ -68,7 +61,7 @@ packages << {
|
|
68
61
|
```
|
69
62
|
|
70
63
|
By default packaging type is "YOUR PACKAGING" and the drop off type is "REGULAR PICKUP".
|
71
|
-
If you need something different you can pass an extra hash for shipping options
|
64
|
+
If you need something different you can pass an extra hash for shipping options.
|
72
65
|
|
73
66
|
```ruby
|
74
67
|
shipping_options = {
|
@@ -77,6 +70,20 @@ shipping_options = {
|
|
77
70
|
}
|
78
71
|
```
|
79
72
|
|
73
|
+
By default the shipping charges will be assigned to the sender. If you may
|
74
|
+
change this by passing an extra hash of payment options.
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
payment_options = {
|
78
|
+
:type => "THIRD_PARTY",
|
79
|
+
:account_number => "123456789",
|
80
|
+
:name => "Third Party Payor",
|
81
|
+
:company => "Company",
|
82
|
+
:phone_number => "555-555-5555",
|
83
|
+
:country_code => "US"
|
84
|
+
}
|
85
|
+
```
|
86
|
+
|
80
87
|
Create a `Fedex::Shipment` object using your FedEx credentials; mode should be
|
81
88
|
either production or development depending on what Fedex environment you want to use.
|
82
89
|
|
@@ -252,6 +259,7 @@ Fedex::Shipment::DROP_OFF_TYPES
|
|
252
259
|
- [yevgenko] (https://github.com/yevgenko) (Yevgeniy Viktorov)
|
253
260
|
- [smartacus] (https://github.com/smartacus) (Michael Lippold)
|
254
261
|
- [jonathandean] (https://github.com/jonathandean) (Jonathan Dean)
|
262
|
+
- and more... (https://github.com/jazminschroeder/fedex/graphs/contributors)
|
255
263
|
|
256
264
|
# Copyright/License:
|
257
265
|
Copyright 2011 [Jazmin Schroeder](http://jazminschroeder.com)
|
data/fedex.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_development_dependency "rspec", '~> 2.9.0'
|
23
23
|
s.add_development_dependency 'vcr', '~> 2.0.0'
|
24
24
|
s.add_development_dependency 'webmock', '~> 1.8.0'
|
25
|
+
s.add_development_dependency 'pry'
|
25
26
|
# s.add_runtime_dependency "rest-client"
|
26
27
|
|
27
28
|
s.files = `git ls-files`.split("\n")
|
@@ -36,7 +36,7 @@ module Fedex
|
|
36
36
|
# Build xml Fedex Web Service request
|
37
37
|
def build_xml
|
38
38
|
builder = Nokogiri::XML::Builder.new do |xml|
|
39
|
-
xml.AddressValidationRequest(:xmlns => "http://fedex.com/ws/addressvalidation/
|
39
|
+
xml.AddressValidationRequest(:xmlns => "http://fedex.com/ws/addressvalidation/v#{service[:version]}"){
|
40
40
|
add_web_authentication_detail(xml)
|
41
41
|
add_client_detail(xml)
|
42
42
|
add_version(xml)
|
data/lib/fedex/request/base.rb
CHANGED
@@ -32,6 +32,9 @@ module Fedex
|
|
32
32
|
# Recipient Custom ID Type
|
33
33
|
RECIPIENT_CUSTOM_ID_TYPE = %w(COMPANY INDIVIDUAL PASSPORT)
|
34
34
|
|
35
|
+
# List of available Payment Types
|
36
|
+
PAYMENT_TYPE = %w(RECIPIENT SENDER THIRD_PARTY)
|
37
|
+
|
35
38
|
# In order to use Fedex rates API you must first apply for a developer(and later production keys),
|
36
39
|
# Visit {http://www.fedex.com/us/developer/ Fedex Developer Center} for more information about how to obtain your keys.
|
37
40
|
# @param [String] key - Fedex web service key
|
@@ -44,9 +47,11 @@ module Fedex
|
|
44
47
|
def initialize(credentials, options={})
|
45
48
|
requires!(options, :shipper, :recipient, :packages)
|
46
49
|
@credentials = credentials
|
47
|
-
@shipper, @recipient, @packages, @service_type, @
|
50
|
+
@shipper, @recipient, @packages, @service_type, @customs_clearance_detail, @debug = options[:shipper], options[:recipient], options[:packages], options[:service_type], options[:customs_clearance_detail], options[:debug]
|
48
51
|
@debug = ENV['DEBUG'] == 'true'
|
49
52
|
@shipping_options = options[:shipping_options] ||={}
|
53
|
+
@payment_options = options[:payment_options] ||={}
|
54
|
+
requires!(@payment_options, :type, :account_number, :name, :company, :phone_number, :country_code) if @payment_options.length > 0
|
50
55
|
# Expects hash with addr and port
|
51
56
|
if options[:http_proxy]
|
52
57
|
self.class.http_proxy options[:http_proxy][:host], options[:http_proxy][:port]
|
@@ -101,7 +106,7 @@ module Fedex
|
|
101
106
|
add_shipper(xml)
|
102
107
|
add_recipient(xml)
|
103
108
|
add_shipping_charges_payment(xml)
|
104
|
-
add_customs_clearance(xml) if @
|
109
|
+
add_customs_clearance(xml) if @customs_clearance_detail
|
105
110
|
xml.RateRequestTypes "ACCOUNT"
|
106
111
|
add_packages(xml)
|
107
112
|
}
|
@@ -151,20 +156,20 @@ module Fedex
|
|
151
156
|
# Add shipping charges to xml request
|
152
157
|
def add_shipping_charges_payment(xml)
|
153
158
|
xml.ShippingChargesPayment{
|
154
|
-
xml.PaymentType "SENDER"
|
159
|
+
xml.PaymentType @payment_options[:type] || "SENDER"
|
155
160
|
xml.Payor{
|
156
|
-
if service[:version] >=
|
161
|
+
if service[:version].to_i >= Fedex::API_VERSION.to_i
|
157
162
|
xml.ResponsibleParty {
|
158
|
-
xml.AccountNumber @credentials.account_number
|
163
|
+
xml.AccountNumber @payment_options[:account_number] || @credentials.account_number
|
159
164
|
xml.Contact {
|
160
|
-
xml.PersonName @shipper[:name]
|
161
|
-
xml.CompanyName @shipper[:company]
|
162
|
-
xml.PhoneNumber @shipper[:phone_number]
|
165
|
+
xml.PersonName @payment_options[:name] || @shipper[:name]
|
166
|
+
xml.CompanyName @payment_options[:company] || @shipper[:company]
|
167
|
+
xml.PhoneNumber @payment_options[:phone_number] || @shipper[:phone_number]
|
163
168
|
}
|
164
169
|
}
|
165
170
|
else
|
166
|
-
xml.AccountNumber @credentials.account_number
|
167
|
-
xml.CountryCode @shipper[:country_code]
|
171
|
+
xml.AccountNumber @payment_options[:account_number] || @credentials.account_number
|
172
|
+
xml.CountryCode @payment_options[:country_code] || @shipper[:country_code]
|
168
173
|
end
|
169
174
|
}
|
170
175
|
}
|
@@ -271,7 +276,7 @@ module Fedex
|
|
271
276
|
# Add customs clearance(for international shipments)
|
272
277
|
def add_customs_clearance(xml)
|
273
278
|
xml.CustomsClearanceDetail{
|
274
|
-
hash_to_xml(xml, @
|
279
|
+
hash_to_xml(xml, @customs_clearance_detail)
|
275
280
|
}
|
276
281
|
end
|
277
282
|
|
data/lib/fedex/request/rate.rb
CHANGED
@@ -38,7 +38,7 @@ module Fedex
|
|
38
38
|
add_shipper(xml)
|
39
39
|
add_recipient(xml)
|
40
40
|
add_shipping_charges_payment(xml)
|
41
|
-
add_customs_clearance(xml) if @
|
41
|
+
add_customs_clearance(xml) if @customs_clearance_detail
|
42
42
|
xml.RateRequestTypes "ACCOUNT"
|
43
43
|
add_packages(xml)
|
44
44
|
}
|
@@ -59,7 +59,7 @@ module Fedex
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def service
|
62
|
-
{ :id => 'crs', :version =>
|
62
|
+
{ :id => 'crs', :version => Fedex::API_VERSION }
|
63
63
|
end
|
64
64
|
|
65
65
|
# Successful request
|
@@ -45,7 +45,7 @@ module Fedex
|
|
45
45
|
add_recipient(xml)
|
46
46
|
add_shipping_charges_payment(xml)
|
47
47
|
add_special_services(xml) if @shipping_options[:return_reason]
|
48
|
-
add_customs_clearance(xml) if @
|
48
|
+
add_customs_clearance(xml) if @customs_clearance_detail
|
49
49
|
add_custom_components(xml)
|
50
50
|
xml.RateRequestTypes "ACCOUNT"
|
51
51
|
add_packages(xml)
|
@@ -96,7 +96,7 @@ module Fedex
|
|
96
96
|
# Build xml Fedex Web Service request
|
97
97
|
def build_xml
|
98
98
|
builder = Nokogiri::XML::Builder.new do |xml|
|
99
|
-
xml.ProcessShipmentRequest(:xmlns => "http://fedex.com/ws/ship/
|
99
|
+
xml.ProcessShipmentRequest(:xmlns => "http://fedex.com/ws/ship/v#{service[:version]}"){
|
100
100
|
add_web_authentication_detail(xml)
|
101
101
|
add_client_detail(xml)
|
102
102
|
add_version(xml)
|
@@ -107,7 +107,7 @@ module Fedex
|
|
107
107
|
end
|
108
108
|
|
109
109
|
def service
|
110
|
-
{ :id => 'ship', :version =>
|
110
|
+
{ :id => 'ship', :version => Fedex::API_VERSION }
|
111
111
|
end
|
112
112
|
|
113
113
|
# Successful request
|
data/lib/fedex/version.rb
CHANGED
@@ -93,7 +93,7 @@ module Fedex
|
|
93
93
|
:packages => packages,
|
94
94
|
:service_type => "INTERNATIONAL_PRIORITY",
|
95
95
|
:shipping_details => shipping_options,
|
96
|
-
:
|
96
|
+
:customs_clearance_detail => customs,
|
97
97
|
:shipping_document => document,
|
98
98
|
:filenames => filenames
|
99
99
|
}
|
data/spec/lib/fedex/rate_spec.rb
CHANGED
@@ -21,6 +21,9 @@ describe Fedex::Request::Shipment do
|
|
21
21
|
let(:shipping_options) do
|
22
22
|
{ :packaging_type => "YOUR_PACKAGING", :drop_off_type => "REGULAR_PICKUP" }
|
23
23
|
end
|
24
|
+
let(:payment_options) do
|
25
|
+
{ :type => "SENDER", :account_number => fedex_credentials[:account_number], :name => "Sender", :company => "Company", :phone_number => "555-555-5555", :country_code => "US" }
|
26
|
+
end
|
24
27
|
|
25
28
|
let(:filename) {
|
26
29
|
require 'tmpdir'
|
@@ -39,6 +42,15 @@ describe Fedex::Request::Shipment do
|
|
39
42
|
|
40
43
|
@shipment.class.should_not == Fedex::RateError
|
41
44
|
end
|
45
|
+
|
46
|
+
it "succeeds with payments_options" do
|
47
|
+
expect {
|
48
|
+
@shipment = fedex.ship(options.merge(:payment_options => payment_options))
|
49
|
+
}.to_not raise_error
|
50
|
+
|
51
|
+
@shipment.class.should_not == Fedex::RateError
|
52
|
+
end
|
53
|
+
|
42
54
|
end
|
43
55
|
|
44
56
|
context 'without service_type specified', :vcr do
|
@@ -51,7 +63,18 @@ describe Fedex::Request::Shipment do
|
|
51
63
|
@shipment = fedex.ship(options)
|
52
64
|
}.to raise_error('Missing Required Parameter service_type')
|
53
65
|
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'with invalid payment_options' do
|
69
|
+
let(:options) do
|
70
|
+
{:shipper => shipper, :recipient => recipient, :packages => packages, :filename => filename, :payment_options => payment_options.merge(:account_number => nil)}
|
71
|
+
end
|
54
72
|
|
73
|
+
it 'raises error' do
|
74
|
+
expect {
|
75
|
+
@shipment = fedex.ship(options)
|
76
|
+
}.to raise_error('Missing Required Parameter account_number')
|
77
|
+
end
|
55
78
|
end
|
56
79
|
|
57
80
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fedex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-03-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
16
|
-
requirement: &
|
16
|
+
requirement: &70272120492060 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.12.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70272120492060
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: nokogiri
|
27
|
-
requirement: &
|
27
|
+
requirement: &70272120491560 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.6.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70272120491560
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70272120491080 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 2.9.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70272120491080
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: vcr
|
49
|
-
requirement: &
|
49
|
+
requirement: &70272120490580 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 2.0.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70272120490580
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: webmock
|
60
|
-
requirement: &
|
60
|
+
requirement: &70272120490100 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,7 +65,18 @@ dependencies:
|
|
65
65
|
version: 1.8.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70272120490100
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: &70272120489720 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70272120489720
|
69
80
|
description: Provides an interface to Fedex Web Services(version 10) - shipping rates,
|
70
81
|
generate labels and address validation
|
71
82
|
email:
|