tracking_link 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +6 -0
- data/Rakefile +11 -0
- data/lib/tracking_link.rb +8 -0
- data/lib/tracking_link/base.rb +23 -0
- data/lib/tracking_link/services/fedex.rb +16 -0
- data/lib/tracking_link/services/ups.rb +13 -0
- data/lib/tracking_link/services/usps.rb +15 -0
- data/lib/tracking_link/version.rb +3 -0
- data/test/base_test.rb +20 -0
- data/test/fedex_test.rb +25 -0
- data/test/test_helper.rb +5 -0
- data/test/ups_test.rb +25 -0
- data/test/usps_test.rb +25 -0
- data/tracking_link.gemspec +24 -0
- metadata +65 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module TrackingLink
|
2
|
+
class Base
|
3
|
+
include Services
|
4
|
+
|
5
|
+
SERVICES = [UPS, Fedex, USPS]
|
6
|
+
|
7
|
+
def self.new(tracking_number)
|
8
|
+
service = self.detect(tracking_number)
|
9
|
+
if service
|
10
|
+
service.new(tracking_number)
|
11
|
+
else
|
12
|
+
raise ArgumentError, "Invalid tracking number"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.detect(tracking_number)
|
17
|
+
SERVICES.each do |service|
|
18
|
+
return service if service.detect(tracking_number)
|
19
|
+
end
|
20
|
+
false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module TrackingLink
|
2
|
+
module Services
|
3
|
+
class Fedex < Struct.new(:tracking_number)
|
4
|
+
def link
|
5
|
+
"http://www.fedex.com/Tracking?language=english&cntry_code=us&tracknumbers=#{tracking_number}"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.detect(tracking_number)
|
9
|
+
(tracking_number =~ /^([0-9]{11,11})([0-9])$/) ||
|
10
|
+
(tracking_number =~ /^96[0-9]{5,5}([0-9]{14,14})([0-9])$/) ||
|
11
|
+
(tracking_number =~ /^([0-9]{15,15})$/) ||
|
12
|
+
(tracking_number =~ /^[0-9]{2,2}([0-9]{15,15})([0-9])$/)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module TrackingLink
|
2
|
+
module Services
|
3
|
+
class UPS < Struct.new(:tracking_number)
|
4
|
+
def link
|
5
|
+
"http://wwwapps.ups.com/WebTracking/processInputRequest?sort_by=status&tracknums_displayed=1&TypeOfInquiryNumber=T&loc=en_us&InquiryNumber1=#{tracking_number}&track.x=0&track.y=0"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.detect(tracking_number)
|
9
|
+
tracking_number =~ /^1Z(\w{15,15})(\w)$/
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module TrackingLink
|
2
|
+
module Services
|
3
|
+
class USPS < Struct.new(:tracking_number)
|
4
|
+
def link
|
5
|
+
"http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do?origTrackNum=#{tracking_number}"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.detect(tracking_number)
|
9
|
+
(tracking_number =~ /^(91[0-9]{19,19})([0-9])$/) ||
|
10
|
+
(tracking_number =~ /^([0-9]{2,2})([0-9]{9,9})([0-9]{8,8})([0-9])$/) ||
|
11
|
+
(tracking_number =~ /^([A-Z]{2,2})([0-9]{9,9})([A-Z]{2,2})$/)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/test/base_test.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BaseTest < Test::Unit::TestCase
|
4
|
+
include TrackingLink
|
5
|
+
include TrackingLink::Services
|
6
|
+
|
7
|
+
def test_create_a_new_instance_detecting_service_of_tracking_number
|
8
|
+
assert_kind_of Fedex, Base.new("477179081230")
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_raise_error_with_invalid_tracking_number
|
12
|
+
assert_raise(ArgumentError) { Base.new("1234567890") }
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_detect_the_class_of_tracking_number
|
16
|
+
assert_equal Fedex, Base.detect("871371078356")
|
17
|
+
assert_equal UPS, Base.detect("1Z9999W99999999999")
|
18
|
+
assert_equal USPS, Base.detect("9101128882300879851252")
|
19
|
+
end
|
20
|
+
end
|
data/test/fedex_test.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class FedexTest < Test::Unit::TestCase
|
4
|
+
include TrackingLink
|
5
|
+
include TrackingLink::Services
|
6
|
+
|
7
|
+
def test_create_a_new_instance_detecting_service_of_tracking_number
|
8
|
+
assert_kind_of Fedex, Base.new("871371078356")
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_new_manually
|
12
|
+
assert_kind_of Fedex, Fedex.new("871371078356")
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_detect_if_is_a_tracking_number
|
16
|
+
assert Fedex.detect("871371078356")
|
17
|
+
assert !Fedex.detect("1Z9999W99999999999")
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_link
|
21
|
+
@tracking_number = Fedex.new("871371078356")
|
22
|
+
assert_equal "http://www.fedex.com/Tracking?language=english&cntry_code=us&tracknumbers=871371078356",
|
23
|
+
@tracking_number.link
|
24
|
+
end
|
25
|
+
end
|
data/test/test_helper.rb
ADDED
data/test/ups_test.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class UPSTest < Test::Unit::TestCase
|
4
|
+
include TrackingLink
|
5
|
+
include TrackingLink::Services
|
6
|
+
|
7
|
+
def test_create_a_new_instance_detecting_service_of_tracking_number
|
8
|
+
assert_kind_of UPS, Base.new("1Z9999W99999999999")
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_new_manually
|
12
|
+
assert_kind_of UPS, UPS.new("1Z9999W99999999999")
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_detect_if_is_a_tracking_number
|
16
|
+
assert UPS.detect("1Z9999W99999999999")
|
17
|
+
assert !UPS.detect("477179081230")
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_link
|
21
|
+
@tracking_number = UPS.new("1Z9999W99999999999")
|
22
|
+
assert_equal "http://wwwapps.ups.com/WebTracking/processInputRequest?sort_by=status&tracknums_displayed=1&TypeOfInquiryNumber=T&loc=en_us&InquiryNumber1=1Z9999W99999999999&track.x=0&track.y=0",
|
23
|
+
@tracking_number.link
|
24
|
+
end
|
25
|
+
end
|
data/test/usps_test.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class USPSTest < Test::Unit::TestCase
|
4
|
+
include TrackingLink
|
5
|
+
include TrackingLink::Services
|
6
|
+
|
7
|
+
def test_create_a_new_instance_detecting_service_of_tracking_number
|
8
|
+
assert_kind_of USPS, Base.new("9101128882300879851252")
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_new_manually
|
12
|
+
assert_kind_of USPS, USPS.new("9101128882300879851252")
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_detect_if_is_a_tracking_number
|
16
|
+
assert USPS.detect("9101128882300879851252")
|
17
|
+
assert !USPS.detect("477179081230")
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_link
|
21
|
+
@tracking_number = USPS.new("9101128882300879851252")
|
22
|
+
assert_equal "http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do?origTrackNum=9101128882300879851252",
|
23
|
+
@tracking_number.link
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "tracking_link/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "tracking_link"
|
7
|
+
s.version = TrackingLink::VERSION
|
8
|
+
s.authors = ["Guillermo Iguaran"]
|
9
|
+
s.email = ["guilleiguaran@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Get link for shipping tracking using tracking number}
|
12
|
+
s.description = %q{Get link for shipping tracking using tracking number}
|
13
|
+
|
14
|
+
s.rubyforge_project = "tracking_link"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tracking_link
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Guillermo Iguaran
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-09-28 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Get link for shipping tracking using tracking number
|
15
|
+
email:
|
16
|
+
- guilleiguaran@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- Rakefile
|
24
|
+
- lib/tracking_link.rb
|
25
|
+
- lib/tracking_link/base.rb
|
26
|
+
- lib/tracking_link/services/fedex.rb
|
27
|
+
- lib/tracking_link/services/ups.rb
|
28
|
+
- lib/tracking_link/services/usps.rb
|
29
|
+
- lib/tracking_link/version.rb
|
30
|
+
- test/base_test.rb
|
31
|
+
- test/fedex_test.rb
|
32
|
+
- test/test_helper.rb
|
33
|
+
- test/ups_test.rb
|
34
|
+
- test/usps_test.rb
|
35
|
+
- tracking_link.gemspec
|
36
|
+
homepage: ''
|
37
|
+
licenses: []
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project: tracking_link
|
56
|
+
rubygems_version: 1.8.10
|
57
|
+
signing_key:
|
58
|
+
specification_version: 3
|
59
|
+
summary: Get link for shipping tracking using tracking number
|
60
|
+
test_files:
|
61
|
+
- test/base_test.rb
|
62
|
+
- test/fedex_test.rb
|
63
|
+
- test/test_helper.rb
|
64
|
+
- test/ups_test.rb
|
65
|
+
- test/usps_test.rb
|