package_tracker 0.0.2 → 0.0.3
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/VERSION +1 -1
- data/lib/package_tracker/carriers/fedex.rb +4 -5
- data/lib/package_tracker/carriers/ups.rb +7 -2
- data/lib/package_tracker/response.rb +5 -1
- data/package_tracker.gemspec +2 -2
- data/spec/carrier/fedex_spec.rb +20 -0
- data/spec/carrier/ups_spec.rb +22 -9
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -76,11 +76,10 @@ module PackageTracker
|
|
76
76
|
|
77
77
|
tracking_response = Response.new(tracking_number, self)
|
78
78
|
Nokogiri::XML(response.body).xpath("//v3:Events").each do |event|
|
79
|
-
location =
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
"#{event.xpath("v3:Address//v3:CountryCode").text}"
|
79
|
+
location = unless event.xpath("v3:Address//v3:City").empty?
|
80
|
+
"#{event.xpath("v3:Address//v3:City").text}, " +
|
81
|
+
"#{event.xpath("v3:Address//v3:StateOrProvinceCode").text}, " +
|
82
|
+
"#{event.xpath("v3:Address//v3:CountryCode").text}"
|
84
83
|
end
|
85
84
|
|
86
85
|
tracking_response.add_status(
|
@@ -58,10 +58,15 @@ module PackageTracker
|
|
58
58
|
|
59
59
|
tracking_response = Response.new(tracking_number, self)
|
60
60
|
Nokogiri::XML(response.body).css("Package Activity").each do |activity|
|
61
|
+
location = ""
|
62
|
+
location += "#{activity.css("City").text}, " unless activity.css("City").empty?
|
63
|
+
location += "#{activity.css("StateProvinceCode").text}, " unless activity.css("StateProvinceCode").empty?
|
64
|
+
location += "#{activity.css("CountryCode").text}"
|
65
|
+
|
61
66
|
tracking_response.add_status(
|
62
67
|
activity.css("Status Description").text,
|
63
|
-
Time.parse(activity.css("Date").text
|
64
|
-
|
68
|
+
Time.parse(activity.css("Date").text + activity.css("Time").text),
|
69
|
+
location
|
65
70
|
)
|
66
71
|
end
|
67
72
|
tracking_response
|
@@ -14,11 +14,15 @@ module PackageTracker
|
|
14
14
|
@statuses << { :message => message, :time => time, :location => location }
|
15
15
|
sort_statuses!
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def current_status
|
19
19
|
@statuses.first
|
20
20
|
end
|
21
21
|
|
22
|
+
def current_location
|
23
|
+
current_status[:location]
|
24
|
+
end
|
25
|
+
|
22
26
|
def delivered?
|
23
27
|
current_status[:message] == @carrier.delivered_status
|
24
28
|
end
|
data/package_tracker.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{package_tracker}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Taras"]
|
12
|
-
s.date = %q{2011-05-
|
12
|
+
s.date = %q{2011-05-19}
|
13
13
|
s.description = %q{PackageTracker is a ruby gem for fetching the status of a packages(UPS, FedEx, etc...) with a simple API.}
|
14
14
|
s.email = %q{michaeltaras@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/carrier/fedex_spec.rb
CHANGED
@@ -63,4 +63,24 @@ describe 'FedEx' do
|
|
63
63
|
it 'should return the correct number of statuses' do
|
64
64
|
@client.track(@valid_tracking_number).statuses.length.should == 8
|
65
65
|
end
|
66
|
+
|
67
|
+
it 'should be able to verify delivery' do
|
68
|
+
@client.track(@valid_tracking_number).delivered?.should be true
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should properly parse the location the statuses' do
|
72
|
+
response = @client.track(@valid_tracking_number)
|
73
|
+
statuses = response.statuses
|
74
|
+
|
75
|
+
statuses[0][:location].should == "San Francisco, CA, US"
|
76
|
+
statuses[4][:location].should == "SACRAMENTO, CA, US"
|
77
|
+
statuses[7][:location].should be nil
|
78
|
+
|
79
|
+
response.current_location.should == "San Francisco, CA, US"
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should return the statuses in chronological order' do
|
83
|
+
statuses = @client.track(@valid_tracking_number).statuses
|
84
|
+
statuses.should == statuses.sort_by { |status| status[:time] }.reverse
|
85
|
+
end
|
66
86
|
end
|
data/spec/carrier/ups_spec.rb
CHANGED
@@ -10,20 +10,17 @@ describe "UPS" do
|
|
10
10
|
@client = PackageTracker::Client.new(:ups => @valid_credentials)
|
11
11
|
@invalid_credentials_client = PackageTracker::Client.new(:ups => @invalid_credentials)
|
12
12
|
|
13
|
-
stub_request(:post, "http://
|
13
|
+
stub_request(:post, "http://wwwcie.ups.com/ups.app/xml/Track")
|
14
14
|
.with(:body => PackageTracker::Carriers::UPS.send(:request_data, @valid_tracking_number, @valid_credentials))
|
15
15
|
.to_return(:body => File.new("spec/fixtures/responses/ups/valid.xml"), :status => 200)
|
16
16
|
|
17
|
-
stub_request(:post, "http://
|
17
|
+
stub_request(:post, "http://wwwcie.ups.com/ups.app/xml/Track")
|
18
18
|
.with(:body => PackageTracker::Carriers::UPS.send(:request_data, @valid_tracking_number, @invalid_credentials))
|
19
19
|
.to_return(:body => File.new("spec/fixtures/responses/ups/invalid_credentials.xml"), :status => 200)
|
20
20
|
|
21
|
-
stub_request(:post, "http://
|
21
|
+
stub_request(:post, "http://wwwcie.ups.com/ups.app/xml/Track")
|
22
22
|
.with(:body => PackageTracker::Carriers::UPS.send(:request_data, @invalid_tracking_number, @valid_credentials))
|
23
23
|
.to_return(:body => File.new("spec/fixtures/responses/ups/invalid_tracking_number.xml"), :status => 200)
|
24
|
-
|
25
|
-
stub_request(:post, "http://wwwcie.ups.com/ups.app/xml/Track")
|
26
|
-
.to_return(:body => File.new("spec/fixtures/responses/ups/valid.xml"), :status => 200)
|
27
24
|
end
|
28
25
|
|
29
26
|
it 'should send requests to the test server when in test mode' do
|
@@ -35,7 +32,7 @@ describe "UPS" do
|
|
35
32
|
|
36
33
|
it 'should send requests to the live server when in production mode' do
|
37
34
|
@client.track(@valid_tracking_number)
|
38
|
-
WebMock.should have_requested(:post, "http://
|
35
|
+
WebMock.should have_requested(:post, "http://wwwcie.ups.com/ups.app/xml/Track")
|
39
36
|
end
|
40
37
|
|
41
38
|
it 'should handle missing credentials' do
|
@@ -66,10 +63,26 @@ describe "UPS" do
|
|
66
63
|
end
|
67
64
|
|
68
65
|
it 'should return the correct number of status activities' do
|
69
|
-
@client.track(@valid_tracking_number).statuses.length.should
|
66
|
+
@client.track(@valid_tracking_number).statuses.length.should be 13
|
70
67
|
end
|
71
68
|
|
72
69
|
it 'should be able to verify delivery' do
|
73
|
-
@client.track(@valid_tracking_number).delivered?.should
|
70
|
+
@client.track(@valid_tracking_number).delivered?.should be true
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should properly parse the location the statuses' do
|
74
|
+
response = @client.track(@valid_tracking_number)
|
75
|
+
statuses = response.statuses
|
76
|
+
|
77
|
+
statuses[0][:location].should == "SAN FRANCISCO, CA, US"
|
78
|
+
statuses[6][:location].should == "SAN PABLO, CA, US"
|
79
|
+
statuses[12][:location].should == "US"
|
80
|
+
|
81
|
+
response.current_location.should == "SAN FRANCISCO, CA, US"
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should return the statuses in chronological order' do
|
85
|
+
statuses = @client.track(@valid_tracking_number).statuses
|
86
|
+
statuses.should == statuses.sort_by { |status| status[:time] }.reverse
|
74
87
|
end
|
75
88
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Michael Taras
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-05-
|
17
|
+
date: 2011-05-19 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -173,7 +173,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
173
173
|
requirements:
|
174
174
|
- - ">="
|
175
175
|
- !ruby/object:Gem::Version
|
176
|
-
hash:
|
176
|
+
hash: -1791949551278866099
|
177
177
|
segments:
|
178
178
|
- 0
|
179
179
|
version: "0"
|