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 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 support at this time. More will come.
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
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 0
3
- :patch: 4
3
+ :patch: 5
4
4
  :major: 1
@@ -265,7 +265,7 @@ module Shippinglogic
265
265
  "United States" => "US"
266
266
  }
267
267
 
268
- STATE_CODES = {
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, use abbreviations, ex: 'US'
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, use abbreviations, ex: 'US'
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, :deadline, :rate, :currency; end
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
- deadline = details[:delivery_timestamp] && Time.parse(details[:delivery_timestamp])
178
+ delivered_by = details[:delivery_timestamp] && Time.parse(details[:delivery_timestamp])
179
179
 
180
- if meets_deadline?(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.deadline = details[:delivery_timestamp] && Time.parse(details[:delivery_timestamp])
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?(deadline)
193
+ def meets_deadline?(delivered_by)
194
194
  return true if !delivery_deadline
195
- deadline && deadline <= delivery_deadline
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(*args)
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, use abbreviations, ex: 'US'
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, use abbreviations, ex: 'US'
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{shippinglogic}
8
- s.version = "1.0.4"
8
+ s.version = "1.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ben Johnson of Binary Logic"]
@@ -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.deadline.should == Time.parse("Fri Aug 07 08:00:00 -0400 2009")
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.deadline.should == Time.parse("Mon Aug 10 08:00:00 -0400 2009")
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.deadline.should == Time.parse("Fri Aug 07 08:00:00 -0400 2009")
70
+ rates.first.delivered_by.should == Time.parse("Fri Aug 07 08:00:00 -0400 2009")
71
71
  end
72
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binarylogic-shippinglogic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Johnson of Binary Logic