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,111 +1,97 @@
1
1
  require 'spec_helper'
2
- require 'fakeweb'
3
2
 
4
3
  USPS_URL = %r|http://testing\.shippingapis\.com/.*|
5
4
 
6
- describe Trackerific::USPS do
7
- include Fixtures
8
-
9
- specify("it should descend from Trackerific::Service") {
10
- Trackerific::USPS.superclass.should be Trackerific::Service
11
- }
12
-
13
- describe :city_state_lookup do
14
-
15
- before(:all) do
16
- @usps = Trackerific::USPS.new :user_id => '123USERID4567'
5
+ describe Trackerific::Services::USPS do
6
+ it { should be_a Trackerific::Services::Base }
7
+
8
+ let(:valid_ids) { ["EJ958083578US"] }
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
13
+ end
14
+
15
+ it "should not match invalid tracking ids" do
16
+ invalid_ids.all? {|id| described_class.can_track?(id) }.should be_false
17
+ end
18
+
19
+ let(:credentials) { { user_id: '123USERID4567' } }
20
+ let(:usps) { described_class.new(credentials) }
21
+
22
+ describe "#city_state_lookup" do
23
+ before do
24
+ FakeWeb.register_uri(:get, USPS_URL, body: fixture)
17
25
  end
18
-
19
- context "with a successful response from the server" do
20
-
21
- before(:all) do
22
- FakeWeb.register_uri(:get, USPS_URL, :body => load_fixture(:usps_city_state_lookup_response))
23
- end
24
-
25
- before(:each) do
26
- @lookup = @usps.city_state_lookup("90210")
26
+
27
+ after(:all) { FakeWeb.clean_registry }
28
+
29
+ context "with a successful response" do
30
+ let(:fixture) { Fixture.read('usps/city_state_lookup.xml') }
31
+ subject { usps.city_state_lookup("90210") }
32
+ it "should have the correct values" do
33
+ subject[:city].should eq "BEVERLY HILLS"
34
+ subject[:state].should eq "CA"
35
+ subject[:zip].should eq "90210"
27
36
  end
28
-
29
- subject { @lookup }
30
- it { should include(:city) }
31
- it { should include(:state) }
32
- it { should include(:zip) }
33
-
34
37
  end
35
-
36
- context "with an error response from the server" do
37
-
38
- before(:all) do
39
- FakeWeb.register_uri(:get, USPS_URL, :body => load_fixture(:usps_error_response))
38
+
39
+ context "with an error response" do
40
+ let(:fixture) { Fixture.read('usps/error.xml') }
41
+ it "should raise a Trackerific::Error" do
42
+ expect {
43
+ usps.city_state_lookup("90210")
44
+ }.to raise_error Trackerific::Error
40
45
  end
41
-
42
- specify { lambda { @usps.city_state_lookup("90210") }.should raise_error(Trackerific::Error) }
43
-
44
46
  end
45
47
  end
46
-
47
- describe :track_package do
48
-
49
- before(:all) do
50
- @package_id = 'EJ958083578US'
51
- @usps = Trackerific::USPS.new :user_id => '123USERID4567'
52
- end
53
-
54
- context "with a successful response from the server" do
55
-
56
- before(:all) do
57
- FakeWeb.register_uri(:get, USPS_URL, :body => load_fixture(:usps_success_response))
58
- end
59
-
60
- before(:each) do
61
- @tracking = @usps.track_package(@package_id)
62
- end
63
-
64
- subject { @tracking }
65
- it("should return a Trackerific::Details") { should be_a Trackerific::Details }
66
-
67
- describe "events.length" do
68
- subject { @tracking.events.length }
69
- it { should >= 1 }
70
- end
71
-
72
- describe :summary do
73
- subject { @tracking.summary }
74
- it { should_not be_empty }
75
- end
76
-
48
+
49
+ describe "#track" do
50
+ let(:id) { 'EJ958083578US' }
51
+
52
+ before do
53
+ FakeWeb.register_uri(:get, USPS_URL, body: fixture)
77
54
  end
78
-
79
- pending "when use_city_state_lookup == true"
80
-
81
- context "with an error response from the server" do
82
-
83
- before(:all) do
84
- FakeWeb.register_uri(:get, USPS_URL, :body => load_fixture(:usps_error_response))
55
+
56
+ after(:all) { FakeWeb.clean_registry }
57
+
58
+ context "with a successful response" do
59
+ let(:fixture) { Fixture.read('usps/success.xml') }
60
+
61
+ subject { usps.track(id) }
62
+
63
+ it { should be_a Trackerific::Details }
64
+
65
+ its(:package_id) { should eq id }
66
+ its(:summary) { should eq "Your item was delivered at 8:10 am on June 1 in Wilmington DE 19801." }
67
+ its(:events) { should be_a Array }
68
+ its(:weight) { should be_nil }
69
+ its(:via) { should be_nil }
70
+
71
+ describe "#events" do
72
+ subject { usps.track(id).events }
73
+ its(:length) { should eq 3 }
74
+ it "should have the correct values" do
75
+ subject[0].date.to_s.should eq "2013-05-30T11:07:00+00:00"
76
+ subject[0].description.should eq "Notice left"
77
+ subject[0].location.should eq "WILMINGTON, DE 19801"
78
+ subject[1].date.to_s.should eq "2013-05-30T10:08:00+00:00"
79
+ subject[1].description.should eq "Arrival at unit"
80
+ subject[1].location.should eq "WILMINGTON, DE 19850"
81
+ subject[2].date.to_s.should eq "2013-05-29T09:55:00+00:00"
82
+ subject[2].description.should eq "Accept or pickup"
83
+ subject[2].location.should eq "EDGEWATER, NJ 07020"
84
+ end
85
85
  end
86
-
87
- specify { lambda { @usps.track_package(@package_id) }.should raise_error(Trackerific::Error) }
88
-
89
86
  end
90
- end
91
-
92
- describe :required_parameters do
93
- subject { Trackerific::USPS.required_parameters }
94
- it { should include(:user_id) }
95
- end
96
-
97
- describe :valid_options do
98
- it "should include required_parameters" do
99
- valid = Trackerific::USPS.valid_options
100
- Trackerific::USPS.required_parameters.each do |opt|
101
- valid.should include opt
87
+
88
+ context "with an error response" do
89
+ let(:fixture) { Fixture.read('usps/error.xml') }
90
+ it "should raise a Trackerific::Error" do
91
+ expect {
92
+ usps.track(id)
93
+ }.to raise_error Trackerific::Error
102
94
  end
103
95
  end
104
96
  end
105
-
106
- describe :package_id_matchers do
107
- subject { Trackerific::UPS.package_id_matchers }
108
- it("should be an Array of Regexp") { should each { |m| m.should be_a Regexp } }
109
- end
110
-
111
97
  end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Trackerific::Services do
4
+ describe "#[]=" do
5
+ context "with a Trackerific::Services::Base" do
6
+ it "should add service" do
7
+ Trackerific::Services[:test] = TestService
8
+ Trackerific::Services[:test].should eq TestService
9
+ end
10
+ end
11
+
12
+ context "with a class other than Trackerific::Services::Base" do
13
+ it "should raise an ArgumentError" do
14
+ expect {
15
+ Trackerific::Services[:string] = String
16
+ }.to raise_error ArgumentError
17
+ end
18
+ end
19
+ end
20
+
21
+ describe "#[]" do
22
+ it "should find registered services" do
23
+ Trackerific::Services[:another_test_service].should eq AnotherTestService
24
+ end
25
+
26
+ it "should return nil for unknown services" do
27
+ Trackerific::Services[:not_found].should be_nil
28
+ end
29
+ end
30
+
31
+ describe "#find_by_package_id" do
32
+ let(:id) { "TEST" }
33
+ subject { Trackerific::Services.find_by_package_id(id) }
34
+ it { should include TestService }
35
+ it { should include AnotherTestService }
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Trackerific::VERSION do
4
+ it { should eq "0.7.0" }
5
+ end
@@ -1,62 +1,24 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Trackerific do
4
- include Trackerific
5
-
6
- describe :services do
7
- subject { Trackerific.services }
8
- it("should be an Array of Symbols") { should each { |m| m.should be_a Symbol } }
4
+ describe "#configuration" do
5
+ subject { Trackerific.configuration }
6
+ it { should eq Trackerific::Configuration.config }
9
7
  end
10
-
11
- describe :service_get do
12
-
13
- context "with a valid service symbol" do
14
- subject { Trackerific.service_get(:fedex).superclass }
15
- it("should be a descendant of Trackerific::Service "){ should be Trackerific::Service }
16
- end
17
-
18
- context "with an invalid service symbol" do
19
- subject { Trackerific.service_get :ksjdfklsjdf }
20
- it { should be_nil }
21
- end
22
-
23
- end
24
-
25
- describe :tracking_service do
26
-
27
- context "when given a UPS tracking number" do
28
- subject { tracking_service "1Z12345E0291980793" }
29
- it { should be Trackerific::UPS}
30
- end
31
-
32
- context "when given a USPS tracking number" do
33
- subject { tracking_service "EJ958083578US" }
34
- it { should be Trackerific::USPS }
35
- end
36
-
37
- context "when given a FedEx tracking number" do
38
- subject { tracking_service "183689015000001" }
39
- it { should be Trackerific::FedEx }
40
- end
41
-
42
- context "when given an invalid tracking number" do
43
- subject { tracking_service "invalid tracking number" }
44
- it { should be_nil }
8
+
9
+ describe "#configure" do
10
+ it "should delegate to Trackerific::Configuration.configure" do
11
+ Trackerific.configure {|config| config.this = :value }
12
+ Trackerific.configuration.this.should eq :value
45
13
  end
46
-
47
14
  end
48
-
49
- describe :track_package do
50
-
51
- context "with a valid package id" do
52
- before { @details = track_package "XXXXXXXXXX" }
53
- subject { @details }
54
- it { should be_kind_of Trackerific::Details }
55
- end
56
-
57
- context "with an invalid package id" do
58
- specify { lambda { track_package "XXXxxxxxxx" }.should raise_error(Trackerific::Error) }
15
+
16
+ describe "#track" do
17
+ it "should return an Array of Trackerific::Details" do
18
+ results = Trackerific.track("TEST")
19
+ results.should be_a Array
20
+ results.count.should eq 2
21
+ results.all? {|r| r.should be_a Trackerific::Details }
59
22
  end
60
23
  end
61
-
62
24
  end
data/spec/spec_helper.rb CHANGED
@@ -1,16 +1,9 @@
1
- # Code coverage
2
- require 'simplecov'
3
- SimpleCov.start
1
+ ENV['RAILS_ENV'] = 'test'
4
2
 
5
3
  require 'rubygems'
6
4
  require 'bundler/setup'
7
5
  require 'trackerific'
8
- require 'rspec_multi_matchers'
6
+ require 'fakeweb'
9
7
 
10
8
  # load all the support files
11
9
  Dir["spec/support/**/*.rb"].each { |f| require File.expand_path(f) }
12
- require 'rspec/rails' # this has to be loaded after the support files
13
-
14
- RSpec.configure do |config|
15
- config.mock_with :rspec
16
- end
@@ -1,20 +1,6 @@
1
- # Provides easy access to XML fixtures
2
- module Fixtures
3
- # Gets the path to the fixtures
4
- # @return [String]
5
- # @api private
6
- def fixture_path
7
- File.join(File.dirname(__FILE__), "..", "fixtures")
8
- end
9
- # Loads a fixture
10
- # @param [Symbol] name the fixture to load
11
- # @param [Symbol] ext the exention of the fixture. defaults to :xml
12
- # @example Load ups_success_response.xml
13
- # response = load_fixture :ups_success_response
14
- # @return [String] the contents of the file
15
- # @api private
16
- def load_fixture(name, ext = :xml)
17
- file_name = File.join(fixture_path, "#{name.to_s}.#{ext.to_s}")
18
- File.read(file_name)
1
+ class Fixture
2
+ def self.read(name)
3
+ fixtures_path = File.expand_path("../../fixtures", __FILE__)
4
+ File.read(File.join(fixtures_path, name))
19
5
  end
20
6
  end
@@ -0,0 +1,23 @@
1
+ class TestService < Trackerific::Services::Base
2
+ self.register :test
3
+
4
+ def self.package_id_matchers
5
+ [ /^TEST$/ ]
6
+ end
7
+
8
+ def track(id)
9
+ return Trackerific::Details.new
10
+ end
11
+ end
12
+
13
+ class AnotherTestService < Trackerific::Services::Base
14
+ self.register :another_test_service
15
+
16
+ def self.package_id_matchers
17
+ [ /^TEST$/ ]
18
+ end
19
+
20
+ def track(id)
21
+ return Trackerific::Details.new
22
+ end
23
+ end
data/trackerific.gemspec CHANGED
@@ -1,107 +1,29 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'trackerific/version'
5
5
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{trackerific}
8
- s.version = "0.6.2"
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "trackerific"
8
+ spec.version = Trackerific::VERSION
9
+ spec.authors = ["Travis Haynes"]
10
+ spec.email = ["travis.j.haynes@gmail.com"]
11
+ spec.description = %q{Package tracking made easy. Currently supported services include FedEx, UPS, and USPS.}
12
+ spec.summary = %q{Package tracking made easy.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
9
15
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Travis Haynes"]
12
- s.date = %q{2011-06-27}
13
- s.description = %q{Package tracking made easy for Rails. Currently supported services include FedEx, UPS, and USPS.}
14
- s.email = %q{travis.j.haynes@gmail.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE.txt",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".rspec",
21
- "Gemfile",
22
- "Gemfile.lock",
23
- "LICENSE.txt",
24
- "README.rdoc",
25
- "Rakefile",
26
- "VERSION",
27
- "changelog",
28
- "examples/custom_service_spec.rb",
29
- "lib/helpers/options_helper.rb",
30
- "lib/trackerific.rb",
31
- "lib/trackerific/configuration.rb",
32
- "lib/trackerific/details.rb",
33
- "lib/trackerific/error.rb",
34
- "lib/trackerific/event.rb",
35
- "lib/trackerific/service.rb",
36
- "lib/trackerific/services/fedex.rb",
37
- "lib/trackerific/services/mock_service.rb",
38
- "lib/trackerific/services/ups.rb",
39
- "lib/trackerific/services/usps.rb",
40
- "spec/fixtures/fedex_error_response.xml",
41
- "spec/fixtures/fedex_success_response.xml",
42
- "spec/fixtures/ups_error_response.xml",
43
- "spec/fixtures/ups_success_response.xml",
44
- "spec/fixtures/usps_city_state_lookup_response.xml",
45
- "spec/fixtures/usps_error_response.xml",
46
- "spec/fixtures/usps_success_response.xml",
47
- "spec/lib/helpers/options_helper_spec.rb",
48
- "spec/lib/trackerific/configuration_spec.rb",
49
- "spec/lib/trackerific/details_spec.rb",
50
- "spec/lib/trackerific/error_spec.rb",
51
- "spec/lib/trackerific/event_spec.rb",
52
- "spec/lib/trackerific/service_spec.rb",
53
- "spec/lib/trackerific/services/fedex_spec.rb",
54
- "spec/lib/trackerific/services/mock_service_spec.rb",
55
- "spec/lib/trackerific/services/ups_spec.rb",
56
- "spec/lib/trackerific/services/usps_spec.rb",
57
- "spec/lib/trackerific_spec.rb",
58
- "spec/spec_helper.rb",
59
- "spec/support/fixtures.rb",
60
- "spec/support/trackerific.rb",
61
- "trackerific.gemspec"
62
- ]
63
- s.homepage = %q{http://github.com/travishaynes/trackerific}
64
- s.licenses = ["MIT"]
65
- s.require_paths = ["lib"]
66
- s.rubyforge_project = %q{trackerific}
67
- s.rubygems_version = %q{1.3.7}
68
- s.summary = %q{Trackerific provides package tracking to Rails.}
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
69
20
 
70
- if s.respond_to? :specification_version then
71
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
72
- s.specification_version = 3
21
+ spec.add_dependency 'httparty', '~> 0.12.0'
22
+ spec.add_dependency 'builder', '~> 3.2.2'
23
+ spec.add_dependency 'activesupport'
73
24
 
74
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
75
- s.add_runtime_dependency(%q<rails>, [">= 3.0.0"])
76
- s.add_runtime_dependency(%q<httparty>, [">= 0.7.7"])
77
- s.add_runtime_dependency(%q<builder>, [">= 2.1.2"])
78
- s.add_development_dependency(%q<bundler>, [">= 1.0.13"])
79
- s.add_development_dependency(%q<jeweler>, [">= 1.5.2"])
80
- s.add_development_dependency(%q<yardstick>, [">= 0.4.0"])
81
- s.add_development_dependency(%q<rspec-rails>, [">= 2.6.1"])
82
- s.add_development_dependency(%q<rspec_multi_matchers>, [">= 1.1.0"])
83
- s.add_development_dependency(%q<ruby-debug19>, [">= 0.11.6"])
84
- else
85
- s.add_dependency(%q<rails>, [">= 3.0.0"])
86
- s.add_dependency(%q<httparty>, [">= 0.7.7"])
87
- s.add_dependency(%q<builder>, [">= 2.1.2"])
88
- s.add_dependency(%q<bundler>, [">= 1.0.13"])
89
- s.add_dependency(%q<jeweler>, [">= 1.5.2"])
90
- s.add_dependency(%q<yardstick>, [">= 0.4.0"])
91
- s.add_dependency(%q<rspec-rails>, [">= 2.6.1"])
92
- s.add_dependency(%q<rspec_multi_matchers>, [">= 1.1.0"])
93
- s.add_dependency(%q<ruby-debug19>, [">= 0.11.6"])
94
- end
95
- else
96
- s.add_dependency(%q<rails>, [">= 3.0.0"])
97
- s.add_dependency(%q<httparty>, [">= 0.7.7"])
98
- s.add_dependency(%q<builder>, [">= 2.1.2"])
99
- s.add_dependency(%q<bundler>, [">= 1.0.13"])
100
- s.add_dependency(%q<jeweler>, [">= 1.5.2"])
101
- s.add_dependency(%q<yardstick>, [">= 0.4.0"])
102
- s.add_dependency(%q<rspec-rails>, [">= 2.6.1"])
103
- s.add_dependency(%q<rspec_multi_matchers>, [">= 1.1.0"])
104
- s.add_dependency(%q<ruby-debug19>, [">= 0.11.6"])
105
- end
25
+ spec.add_development_dependency 'bundler', '>= 1.3.5'
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'rspec', '~> 2.6.0'
28
+ spec.add_development_dependency 'fakeweb', '~> 1.3.0'
106
29
  end
107
-