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.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.rspec +1 -2
  4. data/Gemfile +3 -22
  5. data/Gemfile.lock +33 -107
  6. data/README.rdoc +35 -61
  7. data/Rakefile +10 -36
  8. data/lib/trackerific/configuration.rb +3 -46
  9. data/lib/trackerific/details.rb +2 -71
  10. data/lib/trackerific/event.rb +5 -49
  11. data/lib/trackerific/services/base.rb +45 -0
  12. data/lib/trackerific/services/fedex.rb +75 -85
  13. data/lib/trackerific/services/mock_service.rb +43 -54
  14. data/lib/trackerific/services/ups.rb +94 -103
  15. data/lib/trackerific/services/usps.rb +182 -186
  16. data/lib/trackerific/services.rb +41 -0
  17. data/lib/trackerific/version.rb +3 -0
  18. data/lib/trackerific.rb +30 -73
  19. data/spec/fixtures/{fedex_error_response.xml → fedex/error.xml} +0 -0
  20. data/spec/fixtures/{fedex_success_response.xml → fedex/success.xml} +0 -0
  21. data/spec/fixtures/{ups_error_response.xml → ups/error.xml} +0 -0
  22. data/spec/fixtures/{ups_success_response.xml → ups/success.xml} +0 -0
  23. data/spec/fixtures/{usps_city_state_lookup_response.xml → usps/city_state_lookup.xml} +0 -0
  24. data/spec/fixtures/{usps_error_response.xml → usps/error.xml} +0 -0
  25. data/spec/fixtures/{usps_success_response.xml → usps/success.xml} +0 -0
  26. data/spec/lib/trackerific/configuration_spec.rb +8 -39
  27. data/spec/lib/trackerific/details_spec.rb +13 -78
  28. data/spec/lib/trackerific/error_spec.rb +1 -5
  29. data/spec/lib/trackerific/event_spec.rb +14 -43
  30. data/spec/lib/trackerific/services/base_spec.rb +13 -0
  31. data/spec/lib/trackerific/services/fedex_spec.rb +59 -62
  32. data/spec/lib/trackerific/services/mock_service_spec.rb +33 -46
  33. data/spec/lib/trackerific/services/ups_spec.rb +46 -66
  34. data/spec/lib/trackerific/services/usps_spec.rb +80 -94
  35. data/spec/lib/trackerific/services_spec.rb +37 -0
  36. data/spec/lib/trackerific/version_spec.rb +5 -0
  37. data/spec/lib/trackerific_spec.rb +15 -53
  38. data/spec/spec_helper.rb +2 -9
  39. data/spec/support/fixtures.rb +4 -18
  40. data/spec/support/test_services.rb +23 -0
  41. data/trackerific.gemspec +24 -102
  42. metadata +151 -185
  43. data/VERSION +0 -1
  44. data/changelog +0 -9
  45. data/examples/custom_service_spec.rb +0 -44
  46. data/lib/helpers/options_helper.rb +0 -23
  47. data/lib/trackerific/service.rb +0 -100
  48. data/spec/lib/helpers/options_helper_spec.rb +0 -82
  49. data/spec/lib/trackerific/service_spec.rb +0 -44
  50. 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
- before do
6
- @required_details = {
7
- :package_id => String.new,
8
- :summary => String.new,
9
- :events => Array.new
10
- }
11
- @valid_options = {
12
- :weight => Hash.new,
13
- :via => String.new
14
- }
15
- end
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,9 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Trackerific::Error do
4
-
5
- before { @error = Trackerific::Error.new }
6
- subject { @error }
7
- specify { should be_a StandardError }
8
-
4
+ it { should be_a StandardError }
9
5
  end
@@ -1,48 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Trackerific::Event do
4
-
5
- before do
6
- @date = Time.now
7
- @description = 'description'
8
- @location = 'location'
9
- @required_parameters = {
10
- :date => @date,
11
- :description => @description,
12
- :location => @location
13
- }
14
- end
15
-
16
- context "with all required options" do
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
- include Fixtures
8
-
9
- specify("it should descend from Trackerific::Service") {
10
- Trackerific::FedEx.superclass.should be Trackerific::Service
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
- describe :valid_options do
20
- it "should include required_parameters" do
21
- valid = Trackerific::FedEx.valid_options
22
- Trackerific::FedEx.required_parameters.each do |opt|
23
- valid.should include opt
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
- describe :package_id_matchers do
29
- subject { Trackerific::FedEx.package_id_matchers }
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 :track_package do
34
- before(:all) do
35
- @package_id = "183689015000001"
36
- @fedex = Trackerific::FedEx.new :account => "123456789", :meter => "123456789"
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
- context "with a successful response from the server" do
40
-
41
- before(:all) do
42
- FakeWeb.register_uri(:post, FEDEX_TRACK_URL, :body => load_fixture(:fedex_success_response))
43
- end
44
-
45
- before(:each) do
46
- @tracking = @fedex.track_package(@package_id)
47
- end
48
-
49
- subject { @tracking }
50
- it("should return a Trackerific::Details") { should be_a Trackerific::Details }
51
-
52
- describe "events.length" do
53
- subject { @tracking.events.length }
54
- it { should >= 1}
55
- end
56
-
57
- describe :summary do
58
- subject { @tracking.summary }
59
- it { should_not be_empty }
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 from the server" do
65
-
66
- before(:all) do
67
- FakeWeb.register_uri(:post, FEDEX_TRACK_URL, :body => load_fixture(:fedex_error_response))
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
- specify("it should descend from Trackerific::Service") {
6
- Trackerific::MockService.superclass.should be Trackerific::Service
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 :package_id_matchers do
15
-
16
- context "when in development or test mode" do
17
- subject { Trackerific::MockService.package_id_matchers }
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 :track_package do
30
- before(:all) do
31
- @service = Trackerific::MockService.new
32
- end
33
-
34
- context "with valid package_id" do
35
- before { @tracking = @service.track_package("XXXXXXXXXX") }
36
- subject { @tracking }
37
- it("should return a Trackerific::Details") { should be_a Trackerific::Details }
38
-
39
- describe "events.length" do
40
- subject { @tracking.events.length }
41
- it { should >= 1}
42
- end
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 package_id" do
51
- specify { lambda { @service.track_package("XXXxxxxxxx") }.should raise_error(Trackerific::Error) }
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 "Trackerific::UPS" do
7
- include Fixtures
8
-
9
- specify("it should descend from Trackerific::Service") {
10
- Trackerific::UPS.superclass.should be Trackerific::Service
11
- }
12
-
13
- describe :required_parameters do
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
- describe :package_id_matchers do
30
- subject { Trackerific::UPS.package_id_matchers }
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 :track_package do
35
- before(:all) do
36
- @package_id = '1Z12345E0291980793'
37
- @ups = Trackerific::UPS.new :key => 'testkey', :user_id => 'testuser', :password => 'secret'
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
- context "with a successful response from the server" do
41
-
42
- before(:all) do
43
- FakeWeb.register_uri(:post, UPS_TRACK_URL, :body => load_fixture(:ups_success_response))
44
- end
45
-
46
- before(:each) do
47
- @tracking = @ups.track_package(@package_id)
48
- end
49
-
50
- subject { @tracking }
51
- it("should return a Trackerific::Details") { should be_a Trackerific::Details }
52
-
53
- describe "events.length" do
54
- subject { @tracking.events.length }
55
- it { should >= 1 }
56
- end
57
-
58
- describe :summary do
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 from the server" do
66
-
67
- before(:all) do
68
- FakeWeb.register_uri(:post, UPS_TRACK_URL, :body => load_fixture(:ups_error_response))
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