takuhai_status 1.7.4 → 1.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b2d9df719ff93529a07fd9a359399e5dda950f12a82d71c55fc392de213b287
4
- data.tar.gz: c905145465061cc9e12449cfd68f766f490812c0919ebc48fb4baa294c18b518
3
+ metadata.gz: ed2db8aae5fed40752347a6f60e990a97b5c81077525919d2dc6426055f832b9
4
+ data.tar.gz: 6b72759578390a483719d6b7b643b57ff99dbc6c71df38634fe3d14d68644825
5
5
  SHA512:
6
- metadata.gz: dfe5a1243581f3d7493e0a92dad32c9f5cec11799ac4179ee50270e4d93c553f2bc1985c9f3635291b018810cb8a0abf50904d3e81806bf64e5dc11be9febe94
7
- data.tar.gz: 554e86b9e8b3262de54de788f615ba3ee011ce79a95ccb908ff7a30358495d0645a1fd4d22f507ec816bfa8436bef5a5bee7361e8e7b615dae2cce9cee9d6122
6
+ metadata.gz: ebd4cf407b922c128980e234fd0a6fc52cb22aba452784ba0d4d7216a5d2aefd952910fb4bab1defc662ff351d3c4ab2e82280aa5406077e3b685da4c7359190
7
+ data.tar.gz: 1e97d4d8e8f4c52d1395202cad34158b751c25b81a14aa1a721d34fbae1fe88f7b595ab112c3193463173264478be18eab02d6ee57217ba4e095c77384f1328e
data/.travis.yml CHANGED
@@ -1,4 +1,13 @@
1
1
  language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+ before_install:
5
+ - gem install bundler -v '> 1.5.0'
2
6
  rvm:
3
- - 2.2.2
4
- before_install: gem install bundler -v 1.10.5
7
+ - 2.5.2
8
+ deploy:
9
+ provider: rubygems
10
+ api_key:
11
+ secure: anktbhiTQ2FuZn7EqJBVVCyJjMMXKz2f25ETuqMlriKOCYcKEUKtCGo91F69oxf6SAkAkZCARqTF0IxUrpadiU+x+7n0FD3x2s4BMQqvvPpLPM5sUgAZXIZGsNyfi5Pi5E9HIQ/yuKAAzuNPIlcfVo3f3Os9b/gOICr5j7NcyD6h5zU6qDEW7fskc3HA9w0DDhcxARzGl/O9wiU7NJBNVZQO25/9e1N412VlI3F8+EtLMDeHf3GgHaqwBGIdMLEvN+tb9poA4oLz1Koz3YqgHVMpHrCWWHyLIZ1FmrdhF0gLq4G0Kuas9Nrr3deAh8jAqkX/UMt4WOoOjzi9H/xb6F2CfgAq74FOdOf1SpZkpmFAiC+vtDrGJxgpNQMpoqZ8NdRSfGbEy27HlCznSYZaCm6B9KX7PdstBaqIYJGfByAktgGQnLOIIW24TJpPasMOMmG6r5o2J31fdCv4e8gWoUSRvsJmE7vS8RsL5bG6BtiEqh4akpriBQS8dQ+b2orPQ60yEcRMQVP7E7V0mhzO88j0/Cm+mhjmVo9DPd6PTEMTMOKaYCGR15PUQFmYl11f9WFMKLLzhcUBjDR6ltnDtH5Vow4AUk9oPbPbVLHk1EzM3CsPrmOMie1jlPAZyNhkpTKg385Wq5CSAVcgeLQs2wxABbrB1hJqJlf8K8zy2vU=
12
+ on:
13
+ tags: true
data/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  * TMG (Amazonの荷物のみ)
9
9
  * UPS
10
10
  * FedEx (国外の移動のみ)
11
-
11
+ * USPS (国外の移動のみ)
12
12
 
13
13
  ## Installation
14
14
 
@@ -1,11 +1,3 @@
1
- require "takuhai_status/version"
2
- require "takuhai_status/japanpost"
3
- require "takuhai_status/kuronekoyamato"
4
- require "takuhai_status/sagawa"
5
- require "takuhai_status/tmg_cargo"
6
- require "takuhai_status/ups"
7
- require "takuhai_status/fedex"
8
-
9
1
  require "logger"
10
2
  require "timeout"
11
3
 
@@ -20,10 +12,19 @@ module TakuhaiStatus
20
12
  end
21
13
  end
22
14
 
15
+ # loading plugins
16
+ @@services = []
17
+ def self.add_service(service_name)
18
+ @@services << service_name
19
+ end
20
+ Dir.glob("#{File.dirname(__FILE__)}/takuhai_status/*.rb") do |plugin|
21
+ require plugin
22
+ end
23
+
23
24
  def self.scan(key, timeout: 10, logger: Logger.new(nil))
24
25
  services = []
25
26
  [].tap{|threads|
26
- [Sagawa, JapanPost, KuronekoYamato, TMGCargo, UPS, FedEx].each do |service|
27
+ @@services.each do |service|
27
28
  threads.push(Thread.new{
28
29
  if Thread.method_defined?(:report_on_exception)
29
30
  Thread.current.report_on_exception = false
@@ -4,6 +4,7 @@ require 'json'
4
4
  module TakuhaiStatus
5
5
  class FedEx
6
6
  attr_reader :key, :time, :state
7
+ TakuhaiStatus.add_service(self)
7
8
 
8
9
  def initialize(key)
9
10
  @key = key
@@ -4,9 +4,11 @@ require 'nokogiri'
4
4
  module TakuhaiStatus
5
5
  class JapanPost
6
6
  attr_reader :key, :time, :state
7
+ TakuhaiStatus.add_service(self)
7
8
 
8
9
  def initialize(key)
9
- @key = key.gsub(/[^a-zA-Z0-9]/, '')
10
+ @key = key.strip
11
+ raise NotMyKey.new('invalid key format') unless @key =~ /\A[a-zA-Z0-9]+\Z/
10
12
  @time, @state = check
11
13
  end
12
14
 
@@ -4,9 +4,11 @@ require 'nokogiri'
4
4
  module TakuhaiStatus
5
5
  class KuronekoYamato
6
6
  attr_reader :key, :time, :state
7
+ TakuhaiStatus.add_service(self)
7
8
 
8
9
  def initialize(key)
9
- @key = key.gsub(/[^0-9]/, '')
10
+ @key = key.strip
11
+ raise NotMyKey.new('invalid key format') unless @key =~ /\A[0-9]+\Z/
10
12
  @time, @state = check
11
13
  end
12
14
 
@@ -4,9 +4,11 @@ require 'nokogiri'
4
4
  module TakuhaiStatus
5
5
  class Sagawa
6
6
  attr_reader :key, :time, :state
7
+ TakuhaiStatus.add_service(self)
7
8
 
8
9
  def initialize(key)
9
- @key = key.gsub(/[^0-9]/, '')
10
+ @key = key.strip
11
+ raise NotMyKey.new('invalid key format') unless @key =~ /\A[0-9]+\Z/
10
12
  @time, @state = check
11
13
  end
12
14
 
@@ -5,10 +5,12 @@ require 'nokogiri'
5
5
  module TakuhaiStatus
6
6
  class TMGCargo
7
7
  attr_reader :key, :time, :state
8
+ TakuhaiStatus.add_service(self)
8
9
  @@conn = nil
9
10
 
10
11
  def initialize(key)
11
- @key = key.gsub(/[^0-9]/, '')
12
+ @key = key.strip
13
+ raise NotMyKey.new('invalid key format') unless @key =~ /\A[0-9]+\Z/
12
14
  @time, @state = check
13
15
  end
14
16
 
@@ -18,7 +20,7 @@ module TakuhaiStatus
18
20
 
19
21
  private
20
22
  def check
21
- @@conn = Faraday.new(url: 'http://track-a.tmg-group.jp'){|builder|
23
+ @@conn = Faraday.new(url: 'https://track-a.tmg-group.jp'){|builder|
22
24
  builder.use :cookie_jar
23
25
  builder.request :url_encoded
24
26
  builder.adapter :net_http
@@ -5,10 +5,12 @@ require 'nokogiri'
5
5
  module TakuhaiStatus
6
6
  class UPS
7
7
  attr_reader :key, :time, :state
8
+ TakuhaiStatus.add_service(self)
8
9
  @@conn = nil
9
10
 
10
11
  def initialize(key)
11
- @key = key.gsub(/[^a-zA-Z0-9]/, '')
12
+ @key = key.strip
13
+ raise NotMyKey.new('invalid key format') unless @key =~ /\A[a-zA-Z0-9]+\Z/
12
14
  @time, @state = check
13
15
  end
14
16
 
@@ -0,0 +1,35 @@
1
+ require 'faraday'
2
+ require 'nokogiri'
3
+
4
+ module TakuhaiStatus
5
+ class USPS
6
+ attr_reader :key, :time, :state
7
+ TakuhaiStatus.add_service(self)
8
+
9
+ def initialize(key)
10
+ @key = key.strip
11
+ raise NotMyKey.new('invalid key format') unless @key =~ /\A[a-zA-Z0-9]+\Z/
12
+ @time, @state = check
13
+ end
14
+
15
+ def finish?
16
+ return !!(@state =~ /^Delivered/)
17
+ end
18
+
19
+ private
20
+ def check
21
+ url = "https://tools.usps.com/go/TrackConfirmAction?tLabels=#{@key}"
22
+ html = Faraday.new(url: url).get.body
23
+ date, status, detail = Nokogiri(html).css('div.status_feed p');
24
+ date_str = date.text.strip
25
+ status_str = status.text.gsub(/\u00A0/, ' ').strip
26
+ detail_str = detail.text.gsub(/\u00A0/, ' ').strip
27
+
28
+ unless date_str.empty?
29
+ return Time.parse(date_str), "#{status_str} (#{detail_str})"
30
+ else
31
+ raise NotMyKey
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,3 +1,3 @@
1
1
  module TakuhaiStatus
2
- VERSION = "1.7.4"
2
+ VERSION = "1.8.1"
3
3
  end
@@ -27,4 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency "rake", "~> 10.0"
28
28
  spec.add_development_dependency "rspec"
29
29
  spec.add_development_dependency "pry"
30
+ spec.add_development_dependency "travis"
30
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: takuhai_status
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.4
4
+ version: 1.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - TADA Tadashi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-06 00:00:00.000000000 Z
11
+ date: 2018-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: travis
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description: get delivery status of Takuhai-bin in Japan
112
126
  email:
113
127
  - t@tdtds.jp
@@ -132,6 +146,7 @@ files:
132
146
  - lib/takuhai_status/sagawa.rb
133
147
  - lib/takuhai_status/tmg_cargo.rb
134
148
  - lib/takuhai_status/ups.rb
149
+ - lib/takuhai_status/usps.rb
135
150
  - lib/takuhai_status/version.rb
136
151
  - takuhai_status.gemspec
137
152
  homepage: https://github.com/tdtds/takuhai_status
@@ -154,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
169
  version: '0'
155
170
  requirements: []
156
171
  rubyforge_project:
157
- rubygems_version: 2.7.6
172
+ rubygems_version: 2.7.7
158
173
  signing_key:
159
174
  specification_version: 4
160
175
  summary: get delivery status of Takuhai-bin in Japan