tracking_number 0.10.1 → 0.10.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -1
- data/{README.rdoc → README.md} +32 -17
- data/VERSION +1 -1
- data/lib/tracking_number.rb +1 -1
- data/lib/tracking_number/fedex.rb +0 -2
- data/lib/tracking_number/ups.rb +17 -1
- data/lib/tracking_number/usps.rb +15 -0
- data/lib/tracking_number/version.rb +1 -1
- data/test/ups_tracking_number_test.rb +17 -0
- data/test/usps_tracking_number_test.rb +6 -0
- data/tracking_number.gemspec +2 -4
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b29f70e5c8aca81b52b8e013d67345ee6dab7542
|
4
|
+
data.tar.gz: fd8291a569ba1ba082de8d318f6b2d8a82959030
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b762b796594d170ebee3e36d2ac81ba6de4ee5557c9bdff965c940fbd34218432bc4c8500ee9a84e3e9c50947d6cc571a0e3110ae6ce96c83bfe9b6b0560d99b
|
7
|
+
data.tar.gz: 64229ede64bae0dadaad30130ab2e7d16789e96fb39563e9474519d002ad7439135573483c4ecba54160c91a626caf6e2621eabcf33057751646db51b70447e9
|
data/Gemfile.lock
CHANGED
data/{README.rdoc → README.md}
RENAMED
@@ -1,36 +1,52 @@
|
|
1
|
-
|
1
|
+
## tracking_number
|
2
2
|
|
3
|
-
|
3
|
+
This gem identifies valid tracking numbers and the service they're associated with. It can also tell you a little bit about the package purely from the number—there's quite a bit of info tucked away into those numbers, it turns out.
|
4
4
|
|
5
|
+
This gem does not do tracking. That is left up to you.
|
6
|
+
|
7
|
+
```ruby
|
5
8
|
t = TrackingNumber.new("MYSTERY_TRACKING_NUMBER")
|
9
|
+
# => #<TrackingNumber::Unknown MYSTERY_TRACKING_NUMBER>
|
10
|
+
|
6
11
|
t.valid? #=> false
|
7
12
|
t.carrier #=> :unknown
|
8
13
|
|
9
14
|
t = TrackingNumber.new("1Z879E930346834440")
|
15
|
+
# => #<TrackingNumber::UPS 1Z879E930346834440>
|
16
|
+
|
10
17
|
t.valid? #=> true
|
11
18
|
t.carrier #=> :ups
|
12
|
-
|
19
|
+
```
|
13
20
|
Also can take a block of text and find all the valid tracking numbers within it
|
14
21
|
|
15
|
-
|
22
|
+
```ruby
|
23
|
+
TrackingNumber.search("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
|
24
|
+
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, 1Z879E930346834440
|
25
|
+
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
|
26
|
+
aute 9611020987654312345672 dolor in reprehenderit in voluptate velit esse cillum dolore eu
|
27
|
+
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
|
28
|
+
officia deserunt mollit anim id est laborum.")
|
16
29
|
|
17
|
-
#=> [TrackingNumber
|
30
|
+
#=> [#<TrackingNumber::UPS 1Z879E930346834440>, #<TrackingNumber::FedExGround96 9611020987654312345672>]
|
31
|
+
```
|
18
32
|
|
19
|
-
|
33
|
+
## ActiveModel validation
|
20
34
|
|
21
35
|
For Rails 3 (or any ActiveModel client), validate your fields as a tracking number:
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
36
|
+
```ruby
|
37
|
+
class Shipment < ActiveRecord::Base
|
38
|
+
validates :tracking, :tracking_number => true
|
39
|
+
end
|
40
|
+
```
|
27
41
|
Sometimes it's helpful to have a "magic" tracking number that isn't valid for any of the real carriers, and maybe will have other side effects (e.g., special treatment of a shipping email.)
|
28
42
|
|
29
|
-
|
30
|
-
|
31
|
-
|
43
|
+
```ruby
|
44
|
+
class Shipment < ActiveRecord::Base
|
45
|
+
validates :tracking, :tracking_number => { :except => 'magic-hand-delivery' }
|
46
|
+
end
|
47
|
+
```
|
32
48
|
|
33
|
-
|
49
|
+
## Contributing to tracking_number
|
34
50
|
|
35
51
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
36
52
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
@@ -40,8 +56,7 @@ Sometimes it's helpful to have a "magic" tracking number that isn't valid for an
|
|
40
56
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
41
57
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
42
58
|
|
43
|
-
|
59
|
+
## Copyright
|
44
60
|
|
45
61
|
Copyright (c) 2010 Jeff Keen. See LICENSE.txt for
|
46
62
|
further details.
|
47
|
-
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.10.
|
1
|
+
0.10.2
|
data/lib/tracking_number.rb
CHANGED
@@ -15,7 +15,7 @@ if defined?(ActiveModel::EachValidator)
|
|
15
15
|
end
|
16
16
|
|
17
17
|
module TrackingNumber
|
18
|
-
TYPES = [UPS, FedExExpress, FedExSmartPost, FedExGround, FedExGround18, FedExGround96, USPS91, USPS20, USPS13, DHLExpress, DHLExpressAir, OnTrac]
|
18
|
+
TYPES = [UPS, UPSTest, FedExExpress, FedExSmartPost, FedExGround, FedExGround18, FedExGround96, USPS91, USPS20, USPS13, USPSTest, DHLExpress, DHLExpressAir, OnTrac]
|
19
19
|
|
20
20
|
def self.search(body)
|
21
21
|
TYPES.collect { |type| type.search(body) }.flatten
|
data/lib/tracking_number/ups.rb
CHANGED
@@ -89,4 +89,20 @@ module TrackingNumber
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
|
+
class UPSTest < UPS
|
94
|
+
# Easypost UPS test numbers as described here:
|
95
|
+
# https://www.easypost.com/docs/api#tracking (scroll down a bit).
|
96
|
+
SEARCH_PATTERN = /^EZ(\d)00000000\1$/
|
97
|
+
VERIFY_PATTERN = SEARCH_PATTERN
|
98
|
+
|
99
|
+
def matches
|
100
|
+
self.tracking_number.scan(VERIFY_PATTERN).flatten
|
101
|
+
end
|
102
|
+
|
103
|
+
def valid_checksum?
|
104
|
+
sequence = tracking_number.scan(/[a-zA-Z0-9]+/).flatten.join
|
105
|
+
return sequence =~ /EZ(\d)00000000\1/
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
data/lib/tracking_number/usps.rb
CHANGED
@@ -148,4 +148,19 @@ module TrackingNumber
|
|
148
148
|
return check == check_digit
|
149
149
|
end
|
150
150
|
end
|
151
|
+
|
152
|
+
class USPSTest < USPS
|
153
|
+
# USPS Test Number From Easypost. IE: 9499 9071 2345 6123 4567 81
|
154
|
+
SEARCH_PATTERN = /(\b([0-9]\s*){22,22}\b)/
|
155
|
+
VERIFY_PATTERN = SEARCH_PATTERN
|
156
|
+
|
157
|
+
def matches
|
158
|
+
self.tracking_number.scan(VERIFY_PATTERN).flatten
|
159
|
+
end
|
160
|
+
|
161
|
+
def valid_checksum?
|
162
|
+
sequence = tracking_number.scan(/[0-9]+/).flatten.join
|
163
|
+
return sequence == "9499907123456123456781"
|
164
|
+
end
|
165
|
+
end
|
151
166
|
end
|
@@ -16,4 +16,21 @@ class UPSTrackingNumberTest < Minitest::Test
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
|
+
|
20
|
+
context "a UPS test tracking number" do
|
21
|
+
["EZ1000000001", "EZ2000000002", "EZ3000000003", "EZ4000000004", "EZ5000000005", "EZ6000000006", "EZ7000000007"].each do |valid_number|
|
22
|
+
should "return test for #{valid_number}" do
|
23
|
+
should_be_valid_number(valid_number, TrackingNumber::UPSTest, :ups)
|
24
|
+
end
|
25
|
+
|
26
|
+
should "fail on check digit changes on #{valid_number}" do
|
27
|
+
should_fail_on_check_digit_changes(valid_number)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
should "not detect an invalid number" do
|
32
|
+
results = TrackingNumber::UPSTest.search("C10999911320230")
|
33
|
+
assert_equal 0, results.size
|
34
|
+
end
|
35
|
+
end
|
19
36
|
end
|
@@ -63,5 +63,11 @@ class USPSTrackingNumberTest < Minitest::Test
|
|
63
63
|
should_fail_on_check_digit_changes(valid_number)
|
64
64
|
end
|
65
65
|
end
|
66
|
+
|
67
|
+
["9499907123456123456781", "94999 07123 45612 34567 81"].each do |valid_number|
|
68
|
+
should "return usps with test 22 digit number: #{valid_number}" do
|
69
|
+
should_be_valid_number(valid_number, TrackingNumber::USPSTest, :usps)
|
70
|
+
end
|
71
|
+
end
|
66
72
|
end
|
67
73
|
end
|
data/tracking_number.gemspec
CHANGED
@@ -9,12 +9,11 @@ Gem::Specification.new do |s|
|
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jeff Keen"]
|
12
|
-
s.date = %q{
|
13
|
-
s.description = %q{
|
12
|
+
s.date = %q{2017-02-21}
|
13
|
+
s.description = %q{This gem identifies valid tracking numbers and the service they're associated with. It can also tell you a little bit about the package purely from the number—there's quite a bit of info tucked away into those numbers, it turns out.}
|
14
14
|
s.email = %q{jeff@keen.me}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
17
|
-
"README.rdoc"
|
18
17
|
]
|
19
18
|
s.files = `git ls-files`.split("\n")
|
20
19
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -31,4 +30,3 @@ Gem::Specification.new do |s|
|
|
31
30
|
s.add_development_dependency('activemodel')
|
32
31
|
s.add_development_dependency('minitest','~> 5.5')
|
33
32
|
end
|
34
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tracking_number
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Keen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -80,14 +80,14 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '5.5'
|
83
|
-
description:
|
84
|
-
|
83
|
+
description: This gem identifies valid tracking numbers and the service they're associated
|
84
|
+
with. It can also tell you a little bit about the package purely from the number—there's
|
85
|
+
quite a bit of info tucked away into those numbers, it turns out.
|
85
86
|
email: jeff@keen.me
|
86
87
|
executables: []
|
87
88
|
extensions: []
|
88
89
|
extra_rdoc_files:
|
89
90
|
- LICENSE.txt
|
90
|
-
- README.rdoc
|
91
91
|
files:
|
92
92
|
- ".document"
|
93
93
|
- ".gitignore"
|
@@ -95,7 +95,7 @@ files:
|
|
95
95
|
- Gemfile
|
96
96
|
- Gemfile.lock
|
97
97
|
- LICENSE.txt
|
98
|
-
- README.
|
98
|
+
- README.md
|
99
99
|
- Rakefile
|
100
100
|
- VERSION
|
101
101
|
- lib/tracking_number.rb
|
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
version: '0'
|
137
137
|
requirements: []
|
138
138
|
rubyforge_project:
|
139
|
-
rubygems_version: 2.
|
139
|
+
rubygems_version: 2.5.1
|
140
140
|
signing_key:
|
141
141
|
specification_version: 4
|
142
142
|
summary: Identifies valid tracking numbers
|