binarylogic-shippinglogic 1.0.8 → 1.1.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/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,8 @@
1
+ == 1.1.0 released 2009-07-16
2
+
3
+ * Added another layer to tracking. You dont get an array of events anymore, you get a Shippinglogic::Fedex::Track::Details object that has information the single shipment. Such as delivery date, signature name, etc. To access the events you just call the events method on this object.
4
+ * Added speed to rates.
5
+
1
6
  == 1.0.8 released 2009-07-09
2
7
 
3
8
  * Fix insurance request format.
data/README.rdoc CHANGED
@@ -148,7 +148,7 @@ Here is what I did in an application of mine and it worked out great. I also hav
148
148
 
149
149
  class Shipment < ActiveRecord::Base
150
150
  class Service
151
- attr_accessor :carrier, :name, delivered_by, :rate
151
+ attr_accessor :carrier, :name, "delivered_by, :rate
152
152
  end
153
153
 
154
154
  def services
@@ -157,7 +157,7 @@ Here is what I did in an application of mine and it worked out great. I also hav
157
157
 
158
158
  private
159
159
  def fedex_services
160
- rate_options = {} # fill me with options accepted by Shippinglogic::FedEx::Rate
160
+ rate_options = {} # replace me with your own options accepted by Shippinglogic::FedEx::Rate
161
161
  fedex.rate(rate_options).collect do |rate|
162
162
  service = Service.new
163
163
  service.carrier = :fedex
data/Rakefile CHANGED
@@ -15,9 +15,7 @@ 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 do |rubyforge|
19
- rubyforge.doc_task = nil
20
- end
18
+ Jeweler::RubyforgeTasks.new
21
19
  rescue LoadError
22
20
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
23
21
  end
@@ -34,4 +32,6 @@ Spec::Rake::SpecTask.new(:rcov) do |spec|
34
32
  spec.rcov = true
35
33
  end
36
34
 
35
+ task :spec => :check_dependencies
36
+
37
37
  task :default => :spec
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 0
3
- :patch: 8
2
+ :minor: 1
3
+ :patch: 0
4
4
  :major: 1
@@ -1,5 +1,6 @@
1
1
  require "shippinglogic/fedex/enumerations"
2
2
  require "shippinglogic/fedex/error"
3
+ require "shippinglogic/fedex/proxy"
3
4
  require "shippinglogic/fedex/service"
4
5
  require "shippinglogic/fedex/cancel"
5
6
  require "shippinglogic/fedex/rate"
@@ -0,0 +1,21 @@
1
+ module Shippinglogic
2
+ class FedEx
3
+ class Proxy
4
+ alias_method :real_class, :class
5
+ instance_methods.each { |m| undef_method m unless m =~ /(^__|^real_class$|^send$|^object_id$)/ }
6
+
7
+ attr_accessor :target
8
+
9
+ def initialize(target)
10
+ self.target = target
11
+ end
12
+
13
+ protected
14
+ # We undefined a lot of methods at the beginning of this class. The only methods present in this
15
+ # class are ones that we need, everything else is delegated to our target object.
16
+ def method_missing(name, *args, &block)
17
+ target.send(name, *args, &block)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -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, :delivered_by, :rate, :currency; end
90
+ class Service; attr_accessor :name, :type, :saturday, :delivered_by, :speed, :rate, :currency; end
91
91
 
92
92
  VERSION = {:major => 6, :intermediate => 0, :minor => 0}
93
93
 
@@ -176,6 +176,14 @@ module Shippinglogic
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
+ speed = case details[:service_type]
180
+ when /overnight/i
181
+ 1.day
182
+ when /2_day/i
183
+ 2.days
184
+ else
185
+ 3.days
186
+ end
179
187
 
180
188
  if meets_deadline?(delivered_by)
181
189
  service = Service.new
@@ -183,6 +191,7 @@ module Shippinglogic
183
191
  service.type = details[:service_type]
184
192
  service.saturday = details[:applied_options] == "SATURDAY_DELIVERY"
185
193
  service.delivered_by = delivered_by
194
+ service.speed = speed
186
195
  service.rate = BigDecimal.new(cost[:amount])
187
196
  service.currency = cost[:currency]
188
197
  service
@@ -5,10 +5,7 @@ require "shippinglogic/fedex/validation"
5
5
 
6
6
  module Shippinglogic
7
7
  class FedEx
8
- class Service
9
- alias_method :real_class, :class
10
- instance_methods.each { |m| undef_method m unless m =~ /(^__|^real_class$|^send$|^object_id$)/ }
11
-
8
+ class Service < Proxy
12
9
  include Attributes
13
10
  include HTTParty
14
11
  include Request
@@ -25,12 +22,6 @@ module Shippinglogic
25
22
  end
26
23
 
27
24
  private
28
- # We undefined a lot of methods at the beginning of this class. The only methods present in this
29
- # class are ones that we need, everything else is delegated to our target object.
30
- def method_missing(name, *args, &block)
31
- target.send(name, *args, &block)
32
- end
33
-
34
25
  # Allows the cached response to be reset, specifically when an attribute changes
35
26
  def reset_target
36
27
  @target = nil
@@ -27,8 +27,66 @@ module Shippinglogic
27
27
  # be fairly simple to add, but I could not think of a reason why anyone would want to track
28
28
  # a package with anything other than a tracking number.
29
29
  class Track < Service
30
- # Each tracking result is an object of this class
31
- class Event; attr_accessor :name, :type, :occured_at, :city, :state, :postal_code, :country, :residential; end
30
+ class Details
31
+ # Each tracking result is an object of this class
32
+ class Event; attr_accessor :name, :type, :occured_at, :city, :state, :postal_code, :country, :residential; end
33
+
34
+ attr_accessor :origin_city,
35
+ :origin_state,
36
+ :origin_country,
37
+ :origin_residential,
38
+ :destination_city,
39
+ :destination_state,
40
+ :destination_country,
41
+ :destination_residential,
42
+ :signature_name,
43
+ :service_type,
44
+ :status,
45
+ :delivery_at,
46
+ :tracking_number,
47
+ :events
48
+
49
+ def origin_residential?
50
+ origin_residential == true
51
+ end
52
+
53
+ def destination_residential?
54
+ destination_residential == true
55
+ end
56
+
57
+ def initialize(response)
58
+ details = response[:track_details]
59
+
60
+ self.origin_city = details[:origin_location_address][:city]
61
+ self.origin_state = details[:origin_location_address][:state_or_province_code]
62
+ self.origin_country = details[:origin_location_address][:country_code]
63
+ self.origin_residential = details[:origin_location_address][:residential] == "true"
64
+
65
+ self.destination_city = details[:destination_address][:city]
66
+ self.destination_state = details[:destination_address][:state_or_province_code]
67
+ self.destination_country = details[:destination_address][:country_code]
68
+ self.destination_residential = details[:destination_address][:residential] == "true"
69
+
70
+ self.signature_name = details[:delivery_signature_name]
71
+ self.service_type = details[:service_type]
72
+ self.status = details[:status_description]
73
+ self.delivery_at = Time.parse(details[:actual_delivery_timestamp])
74
+ self.tracking_number = details[:tracking_number]
75
+
76
+ self.events = response[:track_details][:events].collect do |details|
77
+ event = Event.new
78
+ event.name = details[:event_description]
79
+ event.type = details[:event_type]
80
+ event.occured_at = Time.parse(details[:timestamp])
81
+ event.city = details[:address][:city]
82
+ event.state = details[:address][:state_or_province_code]
83
+ event.postal_code = details[:address][:postal_code]
84
+ event.country = details[:address][:country_code]
85
+ event.residential = details[:address][:residential] == "true"
86
+ event
87
+ end
88
+ end
89
+ end
32
90
 
33
91
  VERSION = {:major => 3, :intermediate => 0, :minor => 0}
34
92
 
@@ -38,7 +96,7 @@ module Shippinglogic
38
96
  # The parent class Service requires that we define this method. This is our kicker. This method is only
39
97
  # called when we need to deal with information from FedEx. Notice the caching into the @target variable.
40
98
  def target
41
- @target ||= parse_response(request(build_request))
99
+ @target ||= Details.new(request(build_request))
42
100
  end
43
101
 
44
102
  # Just building some XML to send off to FedEx. FedEx require this particualr format.
@@ -56,23 +114,6 @@ module Shippinglogic
56
114
  b.IncludeDetailedScans true
57
115
  end
58
116
  end
59
-
60
- # Grabbing the response from FedEx and making sense of it. There is a lot of unneeded information
61
- # in the response.
62
- def parse_response(response)
63
- response[:track_details][:events].collect do |details|
64
- event = Event.new
65
- event.name = details[:event_description]
66
- event.type = details[:event_type]
67
- event.occured_at = Time.parse(details[:timestamp])
68
- event.city = details[:address][:city]
69
- event.state = details[:address][:state_or_province_code]
70
- event.postal_code = details[:address][:postal_code]
71
- event.country = details[:address][:country_code]
72
- event.residential = details[:address][:residential] == "true"
73
- event
74
- end
75
- end
76
117
  end
77
118
  end
78
119
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{shippinglogic}
8
- s.version = "1.0.8"
8
+ s.version = "1.1.0"
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"]
12
- s.date = %q{2009-08-09}
12
+ s.date = %q{2009-08-16}
13
13
  s.description = %q{Easily use FedEx, UPS, USPS web services with an elegant and simple syntax.}
14
14
  s.email = %q{bjohnson@binarylogic.com}
15
15
  s.extra_rdoc_files = [
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
30
30
  "lib/shippinglogic/fedex/cancel.rb",
31
31
  "lib/shippinglogic/fedex/enumerations.rb",
32
32
  "lib/shippinglogic/fedex/error.rb",
33
+ "lib/shippinglogic/fedex/proxy.rb",
33
34
  "lib/shippinglogic/fedex/rate.rb",
34
35
  "lib/shippinglogic/fedex/request.rb",
35
36
  "lib/shippinglogic/fedex/response.rb",
@@ -17,6 +17,7 @@ describe "FedEx Rate" do
17
17
  rate.type.should == "FIRST_OVERNIGHT"
18
18
  rate.saturday.should == false
19
19
  rate.delivered_by.should == Time.parse("Fri Aug 07 08:00:00 -0400 2009")
20
+ rate.speed.should == 1.day
20
21
  rate.rate.should == 70.01
21
22
  rate.currency.should == "USD"
22
23
  end
@@ -39,6 +40,7 @@ describe "FedEx Rate" do
39
40
  rate.type.should == "FIRST_OVERNIGHT"
40
41
  rate.saturday.should == false
41
42
  rate.delivered_by.should == Time.parse("Mon Aug 10 08:00:00 -0400 2009")
43
+ rate.speed.should == 1.day
42
44
  rate.rate.should == 50.43
43
45
  rate.currency.should == "USD"
44
46
  end
@@ -14,6 +14,6 @@ describe "FedEx Service" do
14
14
 
15
15
  it "should delegate the class method to the target" do
16
16
  use_response(:track_defaults)
17
- new_fedex.track(:tracking_number => fedex_tracking_number).class.should == Array
17
+ new_fedex.track(:tracking_number => fedex_tracking_number).class.should == Shippinglogic::FedEx::Track::Details
18
18
  end
19
19
  end
@@ -5,10 +5,26 @@ describe "FedEx Track" do
5
5
  use_response(:track_defaults)
6
6
 
7
7
  fedex = new_fedex
8
- events = fedex.track(:tracking_number => fedex_tracking_number)
8
+ track_details = fedex.track(:tracking_number => fedex_tracking_number)
9
9
 
10
- events.size.should == 7
11
- event = events.first
10
+ track_details.origin_city.should == "NASHVILLE"
11
+ track_details.origin_state.should == "TN"
12
+ track_details.origin_country.should == "US"
13
+ track_details.should_not be_origin_residential
14
+
15
+ track_details.destination_city.should == "Sacramento"
16
+ track_details.destination_state.should == "CA"
17
+ track_details.destination_country.should == "US"
18
+ track_details.should_not be_destination_residential
19
+
20
+ track_details.signature_name.should == "KKING"
21
+ track_details.service_type.should == "FEDEX_GROUND"
22
+ track_details.status.should == "Delivered"
23
+ track_details.delivery_at.should == Time.parse("2008-12-08T07:43:37-08:00")
24
+ track_details.tracking_number.should == "077973360403984"
25
+
26
+ track_details.events.size.should == 7
27
+ event = track_details.events.first
12
28
  event.name.should == "Delivered"
13
29
  event.type.should == "DL"
14
30
  event.occured_at.should == Time.parse("Mon Dec 08 10:43:37 -0500 2008")
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.8
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Johnson of Binary Logic
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-09 00:00:00 -07:00
12
+ date: 2009-08-16 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -65,6 +65,7 @@ files:
65
65
  - lib/shippinglogic/fedex/cancel.rb
66
66
  - lib/shippinglogic/fedex/enumerations.rb
67
67
  - lib/shippinglogic/fedex/error.rb
68
+ - lib/shippinglogic/fedex/proxy.rb
68
69
  - lib/shippinglogic/fedex/rate.rb
69
70
  - lib/shippinglogic/fedex/request.rb
70
71
  - lib/shippinglogic/fedex/response.rb