trackerific 0.6.2 → 0.7.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.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rspec +1 -2
- data/Gemfile +3 -22
- data/Gemfile.lock +33 -107
- data/README.rdoc +35 -61
- data/Rakefile +10 -36
- data/lib/trackerific/configuration.rb +3 -46
- data/lib/trackerific/details.rb +2 -71
- data/lib/trackerific/event.rb +5 -49
- data/lib/trackerific/services/base.rb +45 -0
- data/lib/trackerific/services/fedex.rb +75 -85
- data/lib/trackerific/services/mock_service.rb +43 -54
- data/lib/trackerific/services/ups.rb +94 -103
- data/lib/trackerific/services/usps.rb +182 -186
- data/lib/trackerific/services.rb +41 -0
- data/lib/trackerific/version.rb +3 -0
- data/lib/trackerific.rb +30 -73
- data/spec/fixtures/{fedex_error_response.xml → fedex/error.xml} +0 -0
- data/spec/fixtures/{fedex_success_response.xml → fedex/success.xml} +0 -0
- data/spec/fixtures/{ups_error_response.xml → ups/error.xml} +0 -0
- data/spec/fixtures/{ups_success_response.xml → ups/success.xml} +0 -0
- data/spec/fixtures/{usps_city_state_lookup_response.xml → usps/city_state_lookup.xml} +0 -0
- data/spec/fixtures/{usps_error_response.xml → usps/error.xml} +0 -0
- data/spec/fixtures/{usps_success_response.xml → usps/success.xml} +0 -0
- data/spec/lib/trackerific/configuration_spec.rb +8 -39
- data/spec/lib/trackerific/details_spec.rb +13 -78
- data/spec/lib/trackerific/error_spec.rb +1 -5
- data/spec/lib/trackerific/event_spec.rb +14 -43
- data/spec/lib/trackerific/services/base_spec.rb +13 -0
- data/spec/lib/trackerific/services/fedex_spec.rb +59 -62
- data/spec/lib/trackerific/services/mock_service_spec.rb +33 -46
- data/spec/lib/trackerific/services/ups_spec.rb +46 -66
- data/spec/lib/trackerific/services/usps_spec.rb +80 -94
- data/spec/lib/trackerific/services_spec.rb +37 -0
- data/spec/lib/trackerific/version_spec.rb +5 -0
- data/spec/lib/trackerific_spec.rb +15 -53
- data/spec/spec_helper.rb +2 -9
- data/spec/support/fixtures.rb +4 -18
- data/spec/support/test_services.rb +23 -0
- data/trackerific.gemspec +24 -102
- metadata +151 -185
- data/VERSION +0 -1
- data/changelog +0 -9
- data/examples/custom_service_spec.rb +0 -44
- data/lib/helpers/options_helper.rb +0 -23
- data/lib/trackerific/service.rb +0 -100
- data/spec/lib/helpers/options_helper_spec.rb +0 -82
- data/spec/lib/trackerific/service_spec.rb +0 -44
- data/spec/support/trackerific.rb +0 -21
@@ -1,82 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Trackerific::Details do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
context "with required options only" do
|
18
|
-
before { @details = Trackerific::Details.new(@required_details) }
|
19
|
-
|
20
|
-
describe :events do
|
21
|
-
subject { @details.events }
|
22
|
-
it { should be_a Array }
|
23
|
-
end
|
24
|
-
|
25
|
-
describe :package_id do
|
26
|
-
subject { @details.package_id }
|
27
|
-
it { should be_a String }
|
28
|
-
end
|
29
|
-
|
30
|
-
describe :summary do
|
31
|
-
subject { @details.summary }
|
32
|
-
it { should be_a String }
|
33
|
-
end
|
34
|
-
|
35
|
-
describe :weight do
|
36
|
-
subject { @details.weight }
|
37
|
-
it { should be_nil }
|
38
|
-
end
|
39
|
-
|
40
|
-
describe :via do
|
41
|
-
subject { @details.via }
|
42
|
-
it { should be_nil }
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "with all options" do
|
47
|
-
before { @details = Trackerific::Details.new(@required_details.merge(@valid_options)) }
|
48
|
-
|
49
|
-
describe :events do
|
50
|
-
subject { @details.events }
|
51
|
-
it { should be_a Array }
|
52
|
-
end
|
53
|
-
|
54
|
-
describe :package_id do
|
55
|
-
subject { @details.package_id }
|
56
|
-
it { should be_a String }
|
57
|
-
end
|
58
|
-
|
59
|
-
describe :summary do
|
60
|
-
subject { @details.summary }
|
61
|
-
it { should be_a String }
|
62
|
-
end
|
63
|
-
|
64
|
-
describe :weight do
|
65
|
-
subject { @details.weight }
|
66
|
-
it { should be_a Hash }
|
67
|
-
end
|
68
|
-
|
69
|
-
describe :via do
|
70
|
-
subject { @details.via }
|
71
|
-
it { should be_a String }
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context "with no options" do
|
76
|
-
specify { lambda { Trackerific::Details.new }.should raise_error(ArgumentError) }
|
77
|
-
end
|
78
|
-
|
79
|
-
context "with invalid options" do
|
80
|
-
specify { lambda { Trackerific::Details.new(:hello => "world")}.should raise_error(ArgumentError) }
|
81
|
-
end
|
4
|
+
let(:id) { "PACKAGE ID" }
|
5
|
+
let(:summary) { "SUMMARY" }
|
6
|
+
let(:events) { ["THESE", "EVENTS"] }
|
7
|
+
let(:weight) { "100lbs" }
|
8
|
+
let(:via) { "USPS" }
|
9
|
+
|
10
|
+
subject { described_class.new(id, summary, events, weight, via) }
|
11
|
+
|
12
|
+
its(:package_id) { should eq id }
|
13
|
+
its(:summary) { should eq summary }
|
14
|
+
its(:events) { should eq events }
|
15
|
+
its(:weight) { should eq weight }
|
16
|
+
its(:via) { should eq via }
|
82
17
|
end
|
@@ -1,48 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Trackerific::Event do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
before { @event = Trackerific::Event.new(@required_parameters) }
|
18
|
-
|
19
|
-
describe :date do
|
20
|
-
subject { @event.date }
|
21
|
-
it { should be @date }
|
22
|
-
end
|
23
|
-
|
24
|
-
describe :description do
|
25
|
-
subject { @event.description }
|
26
|
-
it { should be @description }
|
27
|
-
end
|
28
|
-
|
29
|
-
describe :location do
|
30
|
-
subject { @event.location }
|
31
|
-
it { should be @location }
|
32
|
-
end
|
33
|
-
|
34
|
-
describe :to_s do
|
35
|
-
before { @regex = /(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (0[1-9]|[1-2][0-9]|3[01]) \d{2}:\d{2} (am|pm).*/ }
|
36
|
-
subject { @event.to_s }
|
37
|
-
it("should be in format mmm dd hh:mm am/pm.*") { should =~ @regex }
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context "missing some options" do
|
42
|
-
specify { lambda { Trackerific::Event.new(:date => Time.now, :description => '') }.should raise_error(ArgumentError) }
|
43
|
-
end
|
44
|
-
|
45
|
-
context "with invalid options" do
|
46
|
-
specify { lambda { Trackerific::Event.new(:hello => "world") }.should raise_error(ArgumentError) }
|
4
|
+
let(:date) { Time.now }
|
5
|
+
let(:description) { "DESCRIPTION" }
|
6
|
+
let(:location) { "LOCATION" }
|
7
|
+
|
8
|
+
subject { described_class.new(date, description, location) }
|
9
|
+
|
10
|
+
its(:date) { should eq date }
|
11
|
+
its(:description) { should eq description }
|
12
|
+
its(:location) { should eq location }
|
13
|
+
|
14
|
+
|
15
|
+
let(:to_s_regex) do
|
16
|
+
/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (0[1-9]|[1-2][0-9]|3[01]) \d{2}:\d{2} (am|pm).*/
|
47
17
|
end
|
18
|
+
its(:to_s) { should =~ to_s_regex }
|
48
19
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Trackerific::Services::Base do
|
4
|
+
describe "#register" do
|
5
|
+
it "should register the service" do
|
6
|
+
# these classes were set up in support/test_services.rb
|
7
|
+
Trackerific::Services[:test].should eq TestService
|
8
|
+
Trackerific::Services[:another_test_service].should eq AnotherTestService
|
9
|
+
TestService.name.should eq :test
|
10
|
+
AnotherTestService.name.should eq :another_test_service
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,76 +1,73 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'fakeweb'
|
3
2
|
|
4
3
|
FEDEX_TRACK_URL = "https://gateway.fedex.com/GatewayDC"
|
5
4
|
|
6
|
-
describe Trackerific::FedEx do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
Trackerific::
|
11
|
-
|
12
|
-
|
13
|
-
describe :required_parameters do
|
14
|
-
subject { Trackerific::FedEx.required_parameters }
|
15
|
-
it { should include(:account) }
|
16
|
-
it { should include(:meter) }
|
5
|
+
describe Trackerific::Services::FedEx do
|
6
|
+
it { should be_a Trackerific::Services::Base }
|
7
|
+
|
8
|
+
it "should be registered" do
|
9
|
+
Trackerific::Services[:fedex].should eq Trackerific::Services::FedEx
|
10
|
+
described_class.name.should eq :fedex
|
17
11
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
12
|
+
|
13
|
+
let(:valid_ids) { ["183689015000001", "999999999999999"] }
|
14
|
+
let(:invalid_ids) { %w[these are not fedex tracking ids] }
|
15
|
+
|
16
|
+
it "should match valid FedEx ids" do
|
17
|
+
valid_ids.all? {|id| described_class.can_track?(id) }.should be_true
|
26
18
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
it("should be an Array of Regexp") { should each { |m| m.should be_a Regexp } }
|
19
|
+
|
20
|
+
it "should not match invalid FedEx ids" do
|
21
|
+
invalid_ids.all? {|id| described_class.can_track?(id) }.should be_false
|
31
22
|
end
|
32
|
-
|
33
|
-
describe
|
34
|
-
|
35
|
-
|
36
|
-
|
23
|
+
|
24
|
+
describe "#track" do
|
25
|
+
let(:id) { "183689015000001" }
|
26
|
+
let(:credentials) { { account: "123456789", meter: "123456789" } }
|
27
|
+
let(:fedex) { described_class.new(credentials) }
|
28
|
+
|
29
|
+
before do
|
30
|
+
FakeWeb.register_uri(:post, FEDEX_TRACK_URL, body: fixture)
|
37
31
|
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
32
|
+
|
33
|
+
after { FakeWeb.clean_registry }
|
34
|
+
|
35
|
+
context "with a successful response" do
|
36
|
+
let(:fixture) { Fixture.read('fedex/success.xml') }
|
37
|
+
subject { fedex.track(id) }
|
38
|
+
it { should be_a Trackerific::Details }
|
39
|
+
its(:package_id) { should eq id }
|
40
|
+
its(:summary) { should eq "Delivered" }
|
41
|
+
|
42
|
+
describe "#events" do
|
43
|
+
subject { fedex.track(id).events }
|
44
|
+
its(:length) { should eq 3 }
|
45
|
+
|
46
|
+
it "should be an Array of Trackerific::Event" do
|
47
|
+
subject.all? {|el| el.is_a?(Trackerific::Event) }.should be_true
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should have the correct event values" do
|
51
|
+
subject[0].date.to_s.should eq "2010-07-01 10:43:51 -0600"
|
52
|
+
subject[0].description.should eq "Delivered"
|
53
|
+
subject[0].location.should eq "GA 30506"
|
54
|
+
subject[1].date.to_s.should eq "2010-07-01 08:48:00 -0600"
|
55
|
+
subject[1].description.should eq "On FedEx vehicle for delivery"
|
56
|
+
subject[1].location.should eq "GA 30601"
|
57
|
+
subject[2].date.to_s.should eq "2010-07-01 05:07:00 -0600"
|
58
|
+
subject[2].description.should eq "At local FedEx facility"
|
59
|
+
subject[2].location.should eq "GA 30601"
|
60
|
+
end
|
60
61
|
end
|
61
|
-
|
62
62
|
end
|
63
|
-
|
64
|
-
context "with an error response
|
65
|
-
|
66
|
-
|
67
|
-
|
63
|
+
|
64
|
+
context "with an error response" do
|
65
|
+
let(:fixture) { Fixture.read('fedex/error.xml') }
|
66
|
+
it "should raise a Trackerific::Error" do
|
67
|
+
expect {
|
68
|
+
fedex.track(id)
|
69
|
+
}.to raise_error Trackerific::Error
|
68
70
|
end
|
69
|
-
|
70
|
-
specify { lambda { @fedex.track_package("invalid package id") }.should raise_error(Trackerific::Error) }
|
71
|
-
|
72
71
|
end
|
73
|
-
|
74
72
|
end
|
75
|
-
|
76
73
|
end
|
@@ -1,56 +1,43 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'trackerific/services/mock_service'
|
2
3
|
|
3
|
-
describe Trackerific::MockService do
|
4
|
+
describe Trackerific::Services::MockService do
|
5
|
+
it { should be_a Trackerific::Services::Base }
|
4
6
|
|
5
|
-
|
6
|
-
Trackerific::
|
7
|
-
}
|
8
|
-
|
9
|
-
describe :required_parameters do
|
10
|
-
subject { Trackerific::MockService.required_parameters }
|
11
|
-
it { should be_empty }
|
7
|
+
it "should be registered" do
|
8
|
+
Trackerific::Services[:mock_service].should eq described_class
|
12
9
|
end
|
13
|
-
|
14
|
-
describe
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
it("should be an Array of Regexp") { should each { |m| m.should be_a Regexp } }
|
19
|
-
end
|
20
|
-
|
21
|
-
context "when in production mode" do
|
22
|
-
before { Rails.env = "production" }
|
23
|
-
subject { Trackerific::MockService.package_id_matchers }
|
24
|
-
it { should be_empty }
|
25
|
-
after { Rails.env = "test"}
|
26
|
-
end
|
10
|
+
|
11
|
+
describe "#package_id_matchers" do
|
12
|
+
subject { described_class.package_id_matchers }
|
13
|
+
it { should include /XXXXXXXXXX/ }
|
14
|
+
it { should include /XXXxxxxxxx/ }
|
27
15
|
end
|
28
|
-
|
29
|
-
describe
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
describe :summary do
|
45
|
-
subject { @tracking.summary }
|
46
|
-
it { should_not be_empty }
|
16
|
+
|
17
|
+
describe "#track" do
|
18
|
+
let(:service) { described_class.new }
|
19
|
+
|
20
|
+
context "with a valid id" do
|
21
|
+
let(:id) { "XXXXXXXXXX" }
|
22
|
+
subject { service.track(id) }
|
23
|
+
it { should be_a Trackerific::Details }
|
24
|
+
its(:package_id) { should eq id }
|
25
|
+
its(:summary) { should eq "Your package was delivered." }
|
26
|
+
its(:events) { should be_a Array }
|
27
|
+
|
28
|
+
describe "#events" do
|
29
|
+
subject { service.track(id).events }
|
30
|
+
it { should be_a Array }
|
31
|
+
its(:count) { should eq 3 }
|
47
32
|
end
|
48
33
|
end
|
49
|
-
|
50
|
-
context "with invalid
|
51
|
-
|
34
|
+
|
35
|
+
context "with an invalid id" do
|
36
|
+
it "should raise a Trackerific::Error" do
|
37
|
+
expect {
|
38
|
+
service.track("XXXxxxxxxx")
|
39
|
+
}.to raise_error Trackerific::Error
|
40
|
+
end
|
52
41
|
end
|
53
|
-
|
54
42
|
end
|
55
|
-
|
56
43
|
end
|
@@ -1,79 +1,59 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'fakeweb'
|
3
2
|
|
4
3
|
UPS_TRACK_URL = 'https://wwwcie.ups.com/ups.app/xml/Track'
|
5
4
|
|
6
|
-
describe
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
subject { Trackerific::UPS.required_parameters }
|
15
|
-
it { should include(:key) }
|
16
|
-
it { should include(:user_id) }
|
17
|
-
it { should include(:password) }
|
18
|
-
end
|
19
|
-
|
20
|
-
describe :valid_options do
|
21
|
-
it "should include required_parameters" do
|
22
|
-
valid = Trackerific::UPS.valid_options
|
23
|
-
Trackerific::UPS.required_parameters.each do |opt|
|
24
|
-
valid.should include opt
|
25
|
-
end
|
26
|
-
end
|
5
|
+
describe Trackerific::Services::UPS do
|
6
|
+
it { should be_a Trackerific::Services::Base }
|
7
|
+
|
8
|
+
let(:valid_ids) { ["1Z12345E0291980793"] }
|
9
|
+
let(:invalid_ids) { %w[these are not valid tracking ids] }
|
10
|
+
|
11
|
+
it "should match valid tracking ids" do
|
12
|
+
valid_ids.all? {|id| described_class.can_track?(id) }.should be_true
|
27
13
|
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
it("should be an Array of Regexp") { should each { |m| m.should be_a Regexp } }
|
14
|
+
|
15
|
+
it "should not match invalid tracking ids" do
|
16
|
+
invalid_ids.all? {|id| described_class.can_track?(id) }.should be_false
|
32
17
|
end
|
33
|
-
|
34
|
-
describe
|
35
|
-
|
36
|
-
|
37
|
-
|
18
|
+
|
19
|
+
describe "#track" do
|
20
|
+
let(:id) { "1Z12345E0291980793" }
|
21
|
+
let(:credentials) { { key: 'testkey', user_id: 'testuser', password: 'secret' } }
|
22
|
+
let(:ups) { described_class.new(credentials) }
|
23
|
+
|
24
|
+
before do
|
25
|
+
FakeWeb.register_uri(:post, UPS_TRACK_URL, body: fixture)
|
38
26
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
subject { @tracking.summary }
|
60
|
-
it { should_not be_empty }
|
27
|
+
|
28
|
+
after { FakeWeb.clean_registry }
|
29
|
+
|
30
|
+
context "with a successful response" do
|
31
|
+
let(:fixture) { Fixture.read('ups/success.xml') }
|
32
|
+
subject { ups.track(id) }
|
33
|
+
it { should be_a Trackerific::Details }
|
34
|
+
its(:package_id) { should eq id }
|
35
|
+
its(:summary) { should eq "DELIVERED" }
|
36
|
+
its(:weight) { should be_nil }
|
37
|
+
its(:via) { should be_nil }
|
38
|
+
|
39
|
+
describe "#events" do
|
40
|
+
subject { ups.track(id).events }
|
41
|
+
its(:length) { should eq 1 }
|
42
|
+
it "should have the correct values" do
|
43
|
+
subject[0].date.to_s.should eq "2003-03-13T16:00:00+00:00"
|
44
|
+
subject[0].description.should eq "DELIVERED"
|
45
|
+
subject[0].location.should eq "MAYSVILLE 26833 9700 US"
|
46
|
+
end
|
61
47
|
end
|
62
|
-
|
63
48
|
end
|
64
|
-
|
65
|
-
context "with an error response
|
66
|
-
|
67
|
-
|
68
|
-
|
49
|
+
|
50
|
+
context "with an error response" do
|
51
|
+
let(:fixture) { Fixture.read('ups/error.xml') }
|
52
|
+
it "should raise a Trackerific::Error" do
|
53
|
+
expect {
|
54
|
+
ups.track(id)
|
55
|
+
}.to raise_error Trackerific::Error
|
69
56
|
end
|
70
|
-
|
71
|
-
specify { lambda { @ups.track_package("invalid package id") }.should raise_error(Trackerific::Error) }
|
72
|
-
|
73
57
|
end
|
74
|
-
|
75
|
-
pending "when server returns corrupted xml"
|
76
|
-
|
77
58
|
end
|
78
|
-
|
79
59
|
end
|