binarylogic-shippinglogic 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -0
- data/README.rdoc +28 -1
- data/Rakefile +3 -1
- data/VERSION.yml +1 -1
- data/lib/shippinglogic/fedex/enumerations.rb +19 -1
- data/lib/shippinglogic/fedex/error.rb +5 -3
- data/lib/shippinglogic/fedex/rate.rb +11 -11
- data/lib/shippinglogic/fedex/response.rb +2 -2
- data/lib/shippinglogic/fedex/ship.rb +5 -5
- data/shippinglogic.gemspec +1 -1
- data/spec/fedex/rate_spec.rb +3 -3
- metadata +1 -1
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
== 1.0.5 released 2009-07-08
|
2
|
+
|
3
|
+
* Added request to error objects so you can see both the raw request and response.
|
4
|
+
|
1
5
|
== 1.0.4 released 2009-07-08
|
2
6
|
|
3
7
|
* Added state code mapping so that we can pass full state names and have it convert it to a FedEx friendly code behind the scenes.
|
data/README.rdoc
CHANGED
@@ -88,7 +88,7 @@ You will notice above we assign the result of the 'track' method to a variable c
|
|
88
88
|
|
89
89
|
== Available services and their features
|
90
90
|
|
91
|
-
This library is still very new, as a result only FedEx is
|
91
|
+
This library is still very new, as a result only FedEx is supported at this time. More will come.
|
92
92
|
|
93
93
|
I spent a lot of time on the documentation, for examples of how to use each service please see the docs for their respective classes.
|
94
94
|
|
@@ -142,6 +142,33 @@ Then your results:
|
|
142
142
|
.location== #{event.city}, #{event.state} #{event.postal_code}, #{event.country}
|
143
143
|
.residential= event.residential ? "Yes" : "No"
|
144
144
|
|
145
|
+
== Leave abstraction to your application
|
146
|
+
|
147
|
+
Here is what I did in an application of mine and it worked out great. I also have complete control of what I'm doing and the library is not limiting me:
|
148
|
+
|
149
|
+
class Shipment < ActiveRecord::Base
|
150
|
+
class Service
|
151
|
+
attr_accessor :carrier, :name, delivered_by, :rate
|
152
|
+
end
|
153
|
+
|
154
|
+
def services
|
155
|
+
@services ||= fedex_services # + some_other_services
|
156
|
+
end
|
157
|
+
|
158
|
+
private
|
159
|
+
def fedex_services
|
160
|
+
rate_options = {} # fill me with options accepted by Shippinglogic::FedEx::Rate
|
161
|
+
fedex.rate(rate_options).collect do |rate|
|
162
|
+
service = Service.new
|
163
|
+
service.carrier = :fedex
|
164
|
+
serivce.name = rate.name
|
165
|
+
service.rate = rate.rate
|
166
|
+
service.delivered_by = rate.delivered_by
|
167
|
+
service
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
145
172
|
== Copyright
|
146
173
|
|
147
174
|
Copyright (c) 2009 {Ben Johnson of Binary Logic}[http://www.binarylogic.com], released under the MIT license
|
data/Rakefile
CHANGED
@@ -15,7 +15,9 @@ begin
|
|
15
15
|
gem.add_dependency "activesupport", ">= 2.2.0"
|
16
16
|
gem.add_dependency "httparty", ">= 0.4.4"
|
17
17
|
end
|
18
|
-
Jeweler::RubyforgeTasks.new
|
18
|
+
Jeweler::RubyforgeTasks.new do |rubyforge|
|
19
|
+
rubyforge.doc_task = nil
|
20
|
+
end
|
19
21
|
rescue LoadError
|
20
22
|
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
21
23
|
end
|
data/VERSION.yml
CHANGED
@@ -265,7 +265,7 @@ module Shippinglogic
|
|
265
265
|
"United States" => "US"
|
266
266
|
}
|
267
267
|
|
268
|
-
|
268
|
+
US_STATE_CODES = {
|
269
269
|
"Alabama" => "AL",
|
270
270
|
"Alaska" => "AK",
|
271
271
|
"America Samoa" => "AS",
|
@@ -325,6 +325,24 @@ module Shippinglogic
|
|
325
325
|
"Wisconsin" => "WI",
|
326
326
|
"Wyoming" => "WY",
|
327
327
|
}
|
328
|
+
|
329
|
+
CANADA_STATE_CODES = {
|
330
|
+
"Alberta" => "AB",
|
331
|
+
"British Columbia" => "BC",
|
332
|
+
"Manitoba" => "MB",
|
333
|
+
"New Brunswick" => "NB",
|
334
|
+
"Newfoundland and Labrador" => "NL",
|
335
|
+
"Nova Scotia" => "NS",
|
336
|
+
"Northwest Territories" => "NT",
|
337
|
+
"Nunavut" => "NU",
|
338
|
+
"Ontario" => "ON",
|
339
|
+
"Prince Edward Island" => "PE",
|
340
|
+
"Quebec" => "QC",
|
341
|
+
"Saskatchewan" => "SK",
|
342
|
+
"Yukon" => "YT"
|
343
|
+
}
|
344
|
+
|
345
|
+
STATE_CODES = US_STATE_CODES.merge(CANADA_STATE_CODES)
|
328
346
|
end
|
329
347
|
end
|
330
348
|
end
|
@@ -6,19 +6,21 @@ module Shippinglogic
|
|
6
6
|
#
|
7
7
|
# === Tip
|
8
8
|
#
|
9
|
-
# If you want to see the raw respose catch the error object and call the response method. Ex:
|
9
|
+
# If you want to see the raw request / respose catch the error object and call the request / response method. Ex:
|
10
10
|
#
|
11
11
|
# begin
|
12
12
|
# # my fedex code
|
13
13
|
# rescue Shippinglogic::FedEx::Error => e
|
14
14
|
# # do whatever you want here, just do:
|
15
|
+
# # e.request
|
15
16
|
# # e.response
|
16
17
|
# # to get the raw response from fedex
|
17
18
|
# end
|
18
19
|
class Error < StandardError
|
19
|
-
attr_accessor :errors, :response
|
20
|
+
attr_accessor :errors, :request, :response
|
20
21
|
|
21
|
-
def initialize(response)
|
22
|
+
def initialize(request, response)
|
23
|
+
self.request = request
|
22
24
|
self.response = response
|
23
25
|
|
24
26
|
if response.blank?
|
@@ -10,7 +10,7 @@ module Shippinglogic
|
|
10
10
|
# * <tt>shipper_city</tt> - city part of the address.
|
11
11
|
# * <tt>shipper_state_</tt> - state part of the address, use state abreviations.
|
12
12
|
# * <tt>shipper_postal_code</tt> - postal code part of the address. Ex: zip for the US.
|
13
|
-
# * <tt>shipper_country</tt> - country code part of the address
|
13
|
+
# * <tt>shipper_country</tt> - country code part of the address. FedEx expects abbreviations, but Shippinglogic will convert full names to abbreviations for you.
|
14
14
|
# * <tt>shipper_residential</tt> - a boolean value representing if the address is redential or not (default: false)
|
15
15
|
#
|
16
16
|
# === Recipient options
|
@@ -19,7 +19,7 @@ module Shippinglogic
|
|
19
19
|
# * <tt>recipient_city</tt> - city part of the address.
|
20
20
|
# * <tt>recipient_state</tt> - state part of the address, use state abreviations.
|
21
21
|
# * <tt>recipient_postal_code</tt> - postal code part of the address. Ex: zip for the US.
|
22
|
-
# * <tt>recipient_country</tt> - country code part of the address
|
22
|
+
# * <tt>recipient_country</tt> - country code part of the address. FedEx expects abbreviations, but Shippinglogic will convert full names to abbreviations for you.
|
23
23
|
# * <tt>recipient_residential</tt> - a boolean value representing if the address is redential or not (default: false)
|
24
24
|
#
|
25
25
|
# === Packaging options
|
@@ -33,9 +33,9 @@ module Shippinglogic
|
|
33
33
|
# * <tt>package_count</tt> - the number of packages in your shipment. (default: 1)
|
34
34
|
# * <tt>package_weight</tt> - a single packages weight.
|
35
35
|
# * <tt>package_weight_units</tt> - either LB or KG. (default: LB)
|
36
|
-
# * <tt>package_length</tt> - a single packages length.
|
37
|
-
# * <tt>package_width</tt> - a single packages width.
|
38
|
-
# * <tt>package_height</tt> - a single packages height.
|
36
|
+
# * <tt>package_length</tt> - a single packages length, only required if using YOUR_PACKAGING for packaging_type.
|
37
|
+
# * <tt>package_width</tt> - a single packages width, only required if using YOUR_PACKAGING for packaging_type.
|
38
|
+
# * <tt>package_height</tt> - a single packages height, only required if using YOUR_PACKAGING for packaging_type.
|
39
39
|
# * <tt>package_dimension_units</tt> - either IN or CM. (default: IN)
|
40
40
|
#
|
41
41
|
# === Monetary options
|
@@ -87,7 +87,7 @@ module Shippinglogic
|
|
87
87
|
# # => "First Overnight"
|
88
88
|
class Rate < Service
|
89
89
|
# Each rate result is an object of this class
|
90
|
-
class Service; attr_accessor :name, :type, :saturday, :
|
90
|
+
class Service; attr_accessor :name, :type, :saturday, :delivered_by, :rate, :currency; end
|
91
91
|
|
92
92
|
VERSION = {:major => 6, :intermediate => 0, :minor => 0}
|
93
93
|
|
@@ -175,14 +175,14 @@ module Shippinglogic
|
|
175
175
|
response[:rate_reply_details].collect do |details|
|
176
176
|
shipment_detail = details[:rated_shipment_details].is_a?(Array) ? details[:rated_shipment_details].first : details[:rated_shipment_details]
|
177
177
|
cost = shipment_detail[:shipment_rate_detail][:total_net_charge]
|
178
|
-
|
178
|
+
delivered_by = details[:delivery_timestamp] && Time.parse(details[:delivery_timestamp])
|
179
179
|
|
180
|
-
if meets_deadline?(
|
180
|
+
if meets_deadline?(delivered_by)
|
181
181
|
service = Service.new
|
182
182
|
service.name = details[:service_type].titleize
|
183
183
|
service.type = details[:service_type]
|
184
184
|
service.saturday = details[:applied_options] == "SATURDAY_DELIVERY"
|
185
|
-
service.
|
185
|
+
service.delivered_by = delivered_by
|
186
186
|
service.rate = BigDecimal.new(cost[:amount])
|
187
187
|
service.currency = cost[:currency]
|
188
188
|
service
|
@@ -190,9 +190,9 @@ module Shippinglogic
|
|
190
190
|
end.compact
|
191
191
|
end
|
192
192
|
|
193
|
-
def meets_deadline?(
|
193
|
+
def meets_deadline?(delivered_by)
|
194
194
|
return true if !delivery_deadline
|
195
|
-
|
195
|
+
delivered_by && delivered_by <= delivery_deadline
|
196
196
|
end
|
197
197
|
end
|
198
198
|
end
|
@@ -6,13 +6,13 @@ module Shippinglogic
|
|
6
6
|
|
7
7
|
private
|
8
8
|
# Overwriting the request method to clean the response and handle errors.
|
9
|
-
def request(
|
9
|
+
def request(body)
|
10
10
|
response = clean_response(super)
|
11
11
|
|
12
12
|
if success?(response)
|
13
13
|
response
|
14
14
|
else
|
15
|
-
raise Error.new(response)
|
15
|
+
raise Error.new(body, response)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -10,7 +10,7 @@ module Shippinglogic
|
|
10
10
|
# * <tt>shipper_city</tt> - city part of the address.
|
11
11
|
# * <tt>shipper_state_</tt> - state part of the address, use state abreviations.
|
12
12
|
# * <tt>shipper_postal_code</tt> - postal code part of the address. Ex: zip for the US.
|
13
|
-
# * <tt>shipper_country</tt> - country code part of the address
|
13
|
+
# * <tt>shipper_country</tt> - country code part of the address. FedEx expects abbreviations, but Shippinglogic will convert full names to abbreviations for you.
|
14
14
|
# * <tt>shipper_residential</tt> - a boolean value representing if the address is redential or not (default: false)
|
15
15
|
#
|
16
16
|
# === Recipient options
|
@@ -19,7 +19,7 @@ module Shippinglogic
|
|
19
19
|
# * <tt>recipient_city</tt> - city part of the address.
|
20
20
|
# * <tt>recipient_state</tt> - state part of the address, use state abreviations.
|
21
21
|
# * <tt>recipient_postal_code</tt> - postal code part of the address. Ex: zip for the US.
|
22
|
-
# * <tt>recipient_country</tt> - country code part of the address
|
22
|
+
# * <tt>recipient_country</tt> - country code part of the address. FedEx expects abbreviations, but Shippinglogic will convert full names to abbreviations for you.
|
23
23
|
# * <tt>recipient_residential</tt> - a boolean value representing if the address is redential or not (default: false)
|
24
24
|
#
|
25
25
|
# === Label options
|
@@ -39,9 +39,9 @@ module Shippinglogic
|
|
39
39
|
# * <tt>package_count</tt> - the number of packages in your shipment. (default: 1)
|
40
40
|
# * <tt>package_weight</tt> - a single packages weight.
|
41
41
|
# * <tt>package_weight_units</tt> - either LB or KG. (default: LB)
|
42
|
-
# * <tt>package_length</tt> - a single packages length.
|
43
|
-
# * <tt>package_width</tt> - a single packages width.
|
44
|
-
# * <tt>package_height</tt> - a single packages height.
|
42
|
+
# * <tt>package_length</tt> - a single packages length, only required if using YOUR_PACKAGING for packaging_type.
|
43
|
+
# * <tt>package_width</tt> - a single packages width, only required if using YOUR_PACKAGING for packaging_type.
|
44
|
+
# * <tt>package_height</tt> - a single packages height, only required if using YOUR_PACKAGING for packaging_type.
|
45
45
|
# * <tt>package_dimension_units</tt> - either IN or CM. (default: IN)
|
46
46
|
#
|
47
47
|
# === Monetary options
|
data/shippinglogic.gemspec
CHANGED
data/spec/fedex/rate_spec.rb
CHANGED
@@ -16,7 +16,7 @@ describe "FedEx Rate" do
|
|
16
16
|
rate.name.should == "First Overnight"
|
17
17
|
rate.type.should == "FIRST_OVERNIGHT"
|
18
18
|
rate.saturday.should == false
|
19
|
-
rate.
|
19
|
+
rate.delivered_by.should == Time.parse("Fri Aug 07 08:00:00 -0400 2009")
|
20
20
|
rate.rate.should == 70.01
|
21
21
|
rate.currency.should == "USD"
|
22
22
|
end
|
@@ -38,7 +38,7 @@ describe "FedEx Rate" do
|
|
38
38
|
rate.name.should == "First Overnight"
|
39
39
|
rate.type.should == "FIRST_OVERNIGHT"
|
40
40
|
rate.saturday.should == false
|
41
|
-
rate.
|
41
|
+
rate.delivered_by.should == Time.parse("Mon Aug 10 08:00:00 -0400 2009")
|
42
42
|
rate.rate.should == 50.43
|
43
43
|
rate.currency.should == "USD"
|
44
44
|
end
|
@@ -67,6 +67,6 @@ describe "FedEx Rate" do
|
|
67
67
|
rates.attributes = fedex_package
|
68
68
|
rates.delivery_deadline = Time.parse("Aug 07 08:01:00 -0400 2009")
|
69
69
|
rates.size.should == 1
|
70
|
-
rates.first.
|
70
|
+
rates.first.delivered_by.should == Time.parse("Fri Aug 07 08:00:00 -0400 2009")
|
71
71
|
end
|
72
72
|
end
|