binarylogic-shippinglogic 1.1.0 → 1.1.1
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 +5 -0
- data/README.rdoc +25 -18
- data/VERSION.yml +1 -1
- data/lib/shippinglogic/fedex/rate.rb +20 -0
- data/lib/shippinglogic/fedex/request.rb +3 -1
- data/lib/shippinglogic/fedex/ship.rb +17 -1
- data/lib/shippinglogic/fedex/track.rb +10 -5
- data/shippinglogic.gemspec +2 -2
- data/spec/fedex/ship_spec.rb +27 -12
- data/spec/spec_helper.rb +6 -0
- metadata +2 -2
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
== 1.1.1 released 2009-07-17
|
2
|
+
|
3
|
+
* Added :just_validate options for creating shipments, that leverages FedExs validation option without creating a shipment.
|
4
|
+
* Added more shipper and recipient options, also standardized those options between rating and shipping to create consistency.
|
5
|
+
|
1
6
|
== 1.1.0 released 2009-07-16
|
2
7
|
|
3
8
|
* 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.
|
data/README.rdoc
CHANGED
@@ -36,24 +36,30 @@ See below for usage examples.
|
|
36
36
|
What I think is unique about this library is it's usage / syntax:
|
37
37
|
|
38
38
|
fedex = Shippinglogic::FedEx.new(key, password, account, meter)
|
39
|
-
|
39
|
+
tracking_details = fedex.track(:tracking_number => "XXXXXXXXXXXXXXXXX")
|
40
40
|
# => A proxy object that delegates calls to an array of Shippinglogic::FedEx::Track::Event objects
|
41
41
|
|
42
42
|
# this shows that the tracking object is a proxy for the underlying array
|
43
|
-
|
43
|
+
tracking_details.tracking_number
|
44
44
|
# => "XXXXXXXXXXXXXXXXX"
|
45
45
|
|
46
|
-
|
46
|
+
tracking_details.tracking_number = "YYYYYYYYYYYYYYYYYY"
|
47
47
|
# => "YYYYYYYYYYYYYYYYYY"
|
48
48
|
|
49
|
-
|
50
|
-
# =>
|
49
|
+
tracking_details.class
|
50
|
+
# => Shippinglogic::FedEx::Track::Details
|
51
51
|
|
52
|
-
|
52
|
+
tracking_details.status
|
53
|
+
# => "Delivered"
|
54
|
+
|
55
|
+
tracking_details.signature_name
|
56
|
+
# => "KKING"
|
57
|
+
|
58
|
+
tracking_details.events.first
|
53
59
|
# => #<Shippinglogic::FedEx::Track::Event @postal_code="95817", @name="Delivered", @state="CA", @residential=false,
|
54
60
|
# @city="Sacramento", @type="DL", @country="US", @occured_at=Mon Dec 08 10:43:37 -0500 2008>
|
55
61
|
|
56
|
-
|
62
|
+
tracking_details.first.name
|
57
63
|
# => "Delivered"
|
58
64
|
|
59
65
|
== Calls to the web services are lazy
|
@@ -69,21 +75,21 @@ This is similar to how ActiveRecord's association proxies work. When you call "u
|
|
69
75
|
You will notice above we assign the result of the 'track' method to a variable called 'tracking'. That object has more to it:
|
70
76
|
|
71
77
|
# Initializing
|
72
|
-
|
73
|
-
|
78
|
+
tracking_details = fedex.track(:tracking_number => "XXXXXXXXXXXXX")
|
79
|
+
tracking_details.tracking_number
|
74
80
|
# => "XXXXXXXXXXXXX"
|
75
81
|
|
76
82
|
# Attribute accessors
|
77
|
-
|
78
|
-
|
83
|
+
tracking_details.tracking_number = "YYYYYYYYYYYYYYY"
|
84
|
+
tracking_details.tracking_number
|
79
85
|
# => "YYYYYYYYYYYYYYY"
|
80
86
|
|
81
87
|
# Mass attribute setting
|
82
|
-
|
83
|
-
|
88
|
+
tracking_details.attributes = {:tracking_number => "ZZZZZZZZZZZZZZZZ"}
|
89
|
+
tracking_details.tracking_number
|
84
90
|
# => "ZZZZZZZZZZZZZZZZ"
|
85
91
|
|
86
|
-
|
92
|
+
tracking_details.attributes
|
87
93
|
# => {:tracking_number => "ZZZZZZZZZZZZZZZZ"}
|
88
94
|
|
89
95
|
== Available services and their features
|
@@ -110,11 +116,11 @@ What's nice about having an object is that you can pass it around. Let's say you
|
|
110
116
|
|
111
117
|
class TrackingController < ApplicationController
|
112
118
|
def new
|
113
|
-
@
|
119
|
+
@tracking_details = fedex.track(params[:tracking])
|
114
120
|
end
|
115
121
|
|
116
122
|
def create
|
117
|
-
@
|
123
|
+
@tracking_details = fedex.track(params[:tracking])
|
118
124
|
render :action => :new if !@tracking.successful?
|
119
125
|
end
|
120
126
|
|
@@ -127,7 +133,7 @@ What's nice about having an object is that you can pass it around. Let's say you
|
|
127
133
|
That's pretty simple. Now check out your form:
|
128
134
|
|
129
135
|
# new.html.haml
|
130
|
-
- form_for @
|
136
|
+
- form_for @tracking_details do |f|
|
131
137
|
= f.error_messages
|
132
138
|
= f.text_field :tracking_number
|
133
139
|
= f.submit "Track"
|
@@ -135,7 +141,8 @@ That's pretty simple. Now check out your form:
|
|
135
141
|
Then your results:
|
136
142
|
|
137
143
|
# create.html.haml
|
138
|
-
|
144
|
+
.signature_name= @tracking_details.signature_name
|
145
|
+
- @tracking_details.events.each do |event|
|
139
146
|
.event
|
140
147
|
.name= event.name
|
141
148
|
.occured_at= event.occured_at.to_s(:long)
|
data/VERSION.yml
CHANGED
@@ -6,6 +6,11 @@ module Shippinglogic
|
|
6
6
|
# == Options
|
7
7
|
# === Shipper options
|
8
8
|
#
|
9
|
+
# * <tt>shipper_name</tt> - name of the shipper.
|
10
|
+
# * <tt>shipper_title</tt> - title of the shipper.
|
11
|
+
# * <tt>shipper_company_name</tt> - company name of the shipper.
|
12
|
+
# * <tt>shipper_phone_number</tt> - phone number of the shipper.
|
13
|
+
# * <tt>shipper_email</tt> - email of the shipper.
|
9
14
|
# * <tt>shipper_streets</tt> - street part of the address, separate multiple streets with a new line, dont include blank lines.
|
10
15
|
# * <tt>shipper_city</tt> - city part of the address.
|
11
16
|
# * <tt>shipper_state_</tt> - state part of the address, use state abreviations.
|
@@ -15,6 +20,11 @@ module Shippinglogic
|
|
15
20
|
#
|
16
21
|
# === Recipient options
|
17
22
|
#
|
23
|
+
# * <tt>recipient_name</tt> - name of the recipient.
|
24
|
+
# * <tt>recipient_title</tt> - title of the recipient.
|
25
|
+
# * <tt>recipient_company_name</tt> - company name of the recipient.
|
26
|
+
# * <tt>recipient_phone_number</tt> - phone number of the recipient.
|
27
|
+
# * <tt>recipient_email</tt> - email of the recipient.
|
18
28
|
# * <tt>recipient_streets</tt> - street part of the address, separate multiple streets with a new line, dont include blank lines.
|
19
29
|
# * <tt>recipient_city</tt> - city part of the address.
|
20
30
|
# * <tt>recipient_state</tt> - state part of the address, use state abreviations.
|
@@ -92,6 +102,11 @@ module Shippinglogic
|
|
92
102
|
VERSION = {:major => 6, :intermediate => 0, :minor => 0}
|
93
103
|
|
94
104
|
# shipper options
|
105
|
+
attribute :shipper_name, :string
|
106
|
+
attribute :shipper_title, :string
|
107
|
+
attribute :shipper_company_name, :string
|
108
|
+
attribute :shipper_phone_number, :string
|
109
|
+
attribute :shipper_email, :string
|
95
110
|
attribute :shipper_streets, :string
|
96
111
|
attribute :shipper_city, :string
|
97
112
|
attribute :shipper_state, :string
|
@@ -100,6 +115,11 @@ module Shippinglogic
|
|
100
115
|
attribute :shipper_residential, :boolean, :default => false
|
101
116
|
|
102
117
|
# recipient options
|
118
|
+
attribute :recipient_name, :string
|
119
|
+
attribute :recipient_title, :string
|
120
|
+
attribute :recipient_company_name, :string
|
121
|
+
attribute :recipient_phone_number, :string
|
122
|
+
attribute :recipient_email, :string
|
103
123
|
attribute :recipient_streets, :string
|
104
124
|
attribute :recipient_city, :string
|
105
125
|
attribute :recipient_state, :string
|
@@ -46,9 +46,11 @@ module Shippinglogic
|
|
46
46
|
# A convenience method for building the contact block in your XML request
|
47
47
|
def build_contact(b, type)
|
48
48
|
b.Contact do
|
49
|
-
b.
|
49
|
+
b.PersonName send("#{type}_name") if send("#{type}_name")
|
50
|
+
b.Title send("#{type}_title") if send("#{type}_title")
|
50
51
|
b.CompanyName send("#{type}_company_name") if send("#{type}_company_name")
|
51
52
|
b.PhoneNumber send("#{type}_phone_number") if send("#{type}_phone_number")
|
53
|
+
b.EmailAddress send("#{type}_email") if send("#{type}_email")
|
52
54
|
end
|
53
55
|
end
|
54
56
|
|
@@ -6,6 +6,11 @@ module Shippinglogic
|
|
6
6
|
# == Options
|
7
7
|
# === Shipper options
|
8
8
|
#
|
9
|
+
# * <tt>shipper_name</tt> - name of the shipper.
|
10
|
+
# * <tt>shipper_title</tt> - title of the shipper.
|
11
|
+
# * <tt>shipper_company_name</tt> - company name of the shipper.
|
12
|
+
# * <tt>shipper_phone_number</tt> - phone number of the shipper.
|
13
|
+
# * <tt>shipper_email</tt> - email of the shipper.
|
9
14
|
# * <tt>shipper_streets</tt> - street part of the address, separate multiple streets with a new line, dont include blank lines.
|
10
15
|
# * <tt>shipper_city</tt> - city part of the address.
|
11
16
|
# * <tt>shipper_state_</tt> - state part of the address, use state abreviations.
|
@@ -15,6 +20,11 @@ module Shippinglogic
|
|
15
20
|
#
|
16
21
|
# === Recipient options
|
17
22
|
#
|
23
|
+
# * <tt>recipient_name</tt> - name of the recipient.
|
24
|
+
# * <tt>recipient_title</tt> - title of the recipient.
|
25
|
+
# * <tt>recipient_company_name</tt> - company name of the recipient.
|
26
|
+
# * <tt>recipient_phone_number</tt> - phone number of the recipient.
|
27
|
+
# * <tt>recipient_email</tt> - email of the recipient.
|
18
28
|
# * <tt>recipient_streets</tt> - street part of the address, separate multiple streets with a new line, dont include blank lines.
|
19
29
|
# * <tt>recipient_city</tt> - city part of the address.
|
20
30
|
# * <tt>recipient_state</tt> - state part of the address, use state abreviations.
|
@@ -65,6 +75,7 @@ module Shippinglogic
|
|
65
75
|
#
|
66
76
|
# === Misc options
|
67
77
|
#
|
78
|
+
# * <tt>just_validate</tt> - will tell FedEx to ONLY validate the shipment, not actually create it. (default: false)
|
68
79
|
# * <tt>rate_request_types</tt> - one or more of RATE_REQUEST_TYPES. (default: ACCOUNT)
|
69
80
|
#
|
70
81
|
# == Simple Example
|
@@ -98,8 +109,10 @@ module Shippinglogic
|
|
98
109
|
|
99
110
|
# shipper options
|
100
111
|
attribute :shipper_name, :string
|
112
|
+
attribute :shipper_title, :string
|
101
113
|
attribute :shipper_company_name, :string
|
102
114
|
attribute :shipper_phone_number, :string
|
115
|
+
attribute :shipper_email, :string
|
103
116
|
attribute :shipper_streets, :string
|
104
117
|
attribute :shipper_city, :string
|
105
118
|
attribute :shipper_state, :string
|
@@ -109,8 +122,10 @@ module Shippinglogic
|
|
109
122
|
|
110
123
|
# recipient options
|
111
124
|
attribute :recipient_name, :string
|
125
|
+
attribute :recipient_title, :string
|
112
126
|
attribute :recipient_company_name, :string
|
113
127
|
attribute :recipient_phone_number, :string
|
128
|
+
attribute :recipient_email, :string
|
114
129
|
attribute :recipient_streets, :string
|
115
130
|
attribute :recipient_city, :string
|
116
131
|
attribute :recipient_state, :string
|
@@ -149,6 +164,7 @@ module Shippinglogic
|
|
149
164
|
attribute :signature, :string
|
150
165
|
|
151
166
|
# misc options
|
167
|
+
attribute :just_validate, :boolean, :default => false
|
152
168
|
attribute :rate_request_types, :array, :default => ["ACCOUNT"]
|
153
169
|
|
154
170
|
private
|
@@ -159,7 +175,7 @@ module Shippinglogic
|
|
159
175
|
# Just building some XML to send off to FedEx using our various options
|
160
176
|
def build_request
|
161
177
|
b = builder
|
162
|
-
xml = b.
|
178
|
+
xml = b.tag!(just_validate ? "ValidateShipmentRequest" : "ProcessShipmentRequest", :xmlns => "http://fedex.com/ws/ship/v#{VERSION[:major]}") do
|
163
179
|
build_authentication(b)
|
164
180
|
build_version(b, "ship", VERSION[:major], VERSION[:intermediate], VERSION[:minor])
|
165
181
|
b.SpecialServicesRequested special_services_requested.join(",") if special_services_requested.any?
|
@@ -12,12 +12,19 @@ module Shippinglogic
|
|
12
12
|
# Here is a very simple example:
|
13
13
|
#
|
14
14
|
# fedex = Shippinglogic::FedEx.new(key, password, account, meter)
|
15
|
-
#
|
16
|
-
#
|
15
|
+
# tracking_details = fedex.track(:tracking_number => "my number")
|
16
|
+
#
|
17
|
+
# tracking_details.status
|
18
|
+
# # => "Delivered"
|
19
|
+
#
|
20
|
+
# tracking_details.signature_name
|
21
|
+
# # => "KKING"
|
22
|
+
#
|
23
|
+
# tracking_details.events.first
|
17
24
|
# # => #<Shippinglogic::FedEx::Track::Event @postal_code="95817", @name="Delivered", @state="CA", @residential=false,
|
18
25
|
# # @city="Sacramento", @type="DL", @country="US", @occured_at=Mon Dec 08 10:43:37 -0500 2008>
|
19
26
|
#
|
20
|
-
#
|
27
|
+
# tracking_details.events.first.name
|
21
28
|
# # => "Delivered"
|
22
29
|
#
|
23
30
|
# === Note
|
@@ -43,7 +50,6 @@ module Shippinglogic
|
|
43
50
|
:service_type,
|
44
51
|
:status,
|
45
52
|
:delivery_at,
|
46
|
-
:tracking_number,
|
47
53
|
:events
|
48
54
|
|
49
55
|
def origin_residential?
|
@@ -71,7 +77,6 @@ module Shippinglogic
|
|
71
77
|
self.service_type = details[:service_type]
|
72
78
|
self.status = details[:status_description]
|
73
79
|
self.delivery_at = Time.parse(details[:actual_delivery_timestamp])
|
74
|
-
self.tracking_number = details[:tracking_number]
|
75
80
|
|
76
81
|
self.events = response[:track_details][:events].collect do |details|
|
77
82
|
event = Event.new
|
data/shippinglogic.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{shippinglogic}
|
8
|
-
s.version = "1.1.
|
8
|
+
s.version = "1.1.1"
|
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-
|
12
|
+
s.date = %q{2009-08-17}
|
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 = [
|
data/spec/fedex/ship_spec.rb
CHANGED
@@ -1,22 +1,37 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe "FedEx Ship" do
|
4
|
+
before(:each) do
|
5
|
+
fedex = new_fedex
|
6
|
+
@shipment = fedex.ship
|
7
|
+
|
8
|
+
@shipment.service_type = "FEDEX_2_DAY"
|
9
|
+
@shipment.attributes = fedex_shipper
|
10
|
+
@shipment.attributes = fedex_recipient
|
11
|
+
@shipment.attributes = fedex_package
|
12
|
+
end
|
13
|
+
|
4
14
|
it "should create a new shipment" do
|
5
15
|
use_response(:ship_defaults)
|
6
16
|
|
7
|
-
|
8
|
-
shipment
|
17
|
+
@shipment.rate.should == 17.02
|
18
|
+
@shipment.currency.should == "USD"
|
19
|
+
@shipment.delivery_date.should == Date.parse("Tue, 11 Aug 2009")
|
20
|
+
@shipment.tracking_number.should == "794797892957"
|
21
|
+
@shipment.label.should_not be_nil
|
22
|
+
@shipment.barcode.should_not be_nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should only validate the shipment" do
|
26
|
+
pending
|
27
|
+
DONT_SAVE = true
|
9
28
|
|
10
|
-
shipment.
|
11
|
-
shipment.attributes = fedex_shipper
|
12
|
-
shipment.attributes = fedex_recipient
|
13
|
-
shipment.attributes = fedex_package
|
29
|
+
@shipment.just_validate = true
|
14
30
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
shipment.barcode.should_not be_nil
|
31
|
+
begin
|
32
|
+
@shipment.rate.should == 'fdsf'
|
33
|
+
rescue Shippinglogic::FedEx::Error => e
|
34
|
+
raise e.request
|
35
|
+
end
|
21
36
|
end
|
22
37
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -46,8 +46,11 @@ Spec::Runner.configure do |config|
|
|
46
46
|
|
47
47
|
def fedex_shipper
|
48
48
|
{
|
49
|
+
:shipper_name => "Name",
|
50
|
+
:shipper_title => "Title",
|
49
51
|
:shipper_company_name => "Company",
|
50
52
|
:shipper_phone_number => "2222222222",
|
53
|
+
:shipper_email => "a@a.com",
|
51
54
|
:shipper_streets => "260 Broadway",
|
52
55
|
:shipper_city => "New York",
|
53
56
|
:shipper_state => "NY",
|
@@ -58,8 +61,11 @@ Spec::Runner.configure do |config|
|
|
58
61
|
|
59
62
|
def fedex_recipient
|
60
63
|
{
|
64
|
+
:recipient_name => "Name",
|
65
|
+
:recipient_title => "Title",
|
61
66
|
:recipient_company_name => "Dallas City Hall",
|
62
67
|
:recipient_phone_number => "2222222222",
|
68
|
+
:recipient_email => "a@a.com",
|
63
69
|
:recipient_streets => "1500 Marilla Street",
|
64
70
|
:recipient_city => "Dallas",
|
65
71
|
:recipient_state => "TX",
|
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.1.
|
4
|
+
version: 1.1.1
|
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-
|
12
|
+
date: 2009-08-17 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|