takuhai_status 1.8.9 → 1.9.2

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: 6f6ac61ac18877912736c4c2c53a9c3ff34403477ada3d8ed2e0ac7844e0c545
4
- data.tar.gz: c272dab2cc9f290cbd510c9f9d7c471c53188dde6188b61638acdff469c8b82b
3
+ metadata.gz: e522f263b0eb304f8608b2a75f409e56fa82bf189df9e16526be9078287612d2
4
+ data.tar.gz: e51c2802c0b787e2d8cee70808f70110afbe4d85604a62085f04a12cc81c6691
5
5
  SHA512:
6
- metadata.gz: 854508184c8f05885867d3a227437d9e388622480a9f10e299918e6c68c37c001422fbdfa900b8df841dc0a41da3dbc309e0919ccc29552bca80518fc9824d3f
7
- data.tar.gz: a956f50442f3d675e7fb7605292e93572cae82e9c71be3ac842850567a26700be0d69a8546b1198c50fcf010f9323cd4928f35f04ab39cc23d37208b3a6b6e73
6
+ metadata.gz: bf3f2e9f09a240136aca68ccc4daf6482af80509c8c388392982b36832c72cab04c461ebf4efe0c5375415421ad4c0a19d6b253e2d71724a821ce07a8704b288
7
+ data.tar.gz: 593cc21411fe24e2eb91689a751a39336251b872c220b358d6c4013619323fc622efa8764b8e1a2b67b8bc2ee40906b46ef6af8cdf630552313745c61c866d74
data/.travis.yml CHANGED
@@ -4,9 +4,9 @@ cache: bundler
4
4
  before_install:
5
5
  - gem install bundler -v '> 1.5.0'
6
6
  rvm:
7
- - 2.4.5
8
- - 2.5.2
9
- - 2.6.0
7
+ - 2.5.8
8
+ - 2.6.6
9
+ - 2.7.1
10
10
  deploy:
11
11
  provider: rubygems
12
12
  api_key:
@@ -19,7 +19,7 @@ module TakuhaiStatus
19
19
  private
20
20
  def check
21
21
  uri = "https://trackings.post.japanpost.jp/services/srv/search/direct?reqCodeNo1=#{@key}"
22
- doc = Nokogiri(open(uri, &:read))
22
+ doc = Nokogiri(URI.open(uri, &:read))
23
23
 
24
24
  begin
25
25
  begin
@@ -20,22 +20,21 @@ module TakuhaiStatus
20
20
  def check
21
21
  conn = Faraday.new(url: 'http://toi.kuronekoyamato.co.jp/')
22
22
  res = conn.post('/cgi-bin/tneko', {number00: '1', number01: @key})
23
- doc = Nokogiri(res.body)
23
+ doc = Nokogiri(res.body.force_encoding('UTF-8'))
24
24
 
25
25
  begin
26
- tr = doc.css('.meisai')[0].css('tr').last
27
- state = tr.css('td')[1].text
28
- sday = tr.css('td')[2].text
29
- stime = tr.css('td')[3].text
30
- time = Time.parse("#{sday} #{stime}")
26
+ current = doc.css('.tracking-invoice-block-detail ol li').last
27
+ state = "#{current.css('.item').text} [#{current.css('.name').text}]"
28
+ month, day, hour, minute = current.css('.date').text.split(/[^\d]+/)
29
+ time = Time.local(Time.now.year, month, day, hour, minute)
31
30
 
32
- if state == '国内到着'
33
- begin
34
- time, state = global_state(doc)
35
- rescue
36
- $stderr.puts "error in yamato global, about #{key}"
37
- end
38
- end
31
+ #if state == '国内到着'
32
+ # begin
33
+ # time, state = global_state(doc)
34
+ # rescue
35
+ # $stderr.puts "error in yamato global, about #{key}"
36
+ # end
37
+ #end
39
38
 
40
39
  return time, state
41
40
  rescue NoMethodError
@@ -1,5 +1,4 @@
1
- require 'faraday'
2
- require 'nokogiri'
1
+ require 'mechanize'
3
2
 
4
3
  module TakuhaiStatus
5
4
  class Sagawa
@@ -13,31 +12,34 @@ module TakuhaiStatus
13
12
  end
14
13
 
15
14
  def finish?
16
- return !!(@state =~ /営業所へお問い合わせ下さい。|配達は終了致しました。$|^配達完了|引渡完了/)
15
+ return !!(@state =~ /営業所へお問い合わせください。|配達は終了致しました。$|^配達完了|引渡完了/)
17
16
  end
18
17
 
19
18
  private
20
19
  def check
21
- conn = Faraday.new(url: 'http://k2k.sagawa-exp.co.jp')
22
- res = conn.post('/p/web/okurijosearch.do', {okurijoNo: @key})
23
- doc = Nokogiri(res.body)
20
+ agent = Mechanize.new
21
+ page = agent.get('https://k2k.sagawa-exp.co.jp/p/sagawa/web/okurijoinput.jsp')
22
+ form = page.form_with('main')
23
+ form['main:no1'] = @key
24
+ button = form.button_with('main:toiStart')
25
+ result = agent.submit(form, button)
24
26
 
25
27
  begin
26
- cells = doc.css('.table_okurijo_detail2').css('tr').last.css('td')
27
- state = "#{cells[0].text.strip} [#{cells[2].text.strip}]".sub(/^./, '')
28
- time = Time.parse(cells[1].text.strip) rescue Time.now
29
- return time, state
30
- rescue NoMethodError # detail2 table not found, use detail table
31
- begin
28
+ row = result.css('#detail1 tr')
29
+ cells = row[row.size - 1].css('td')
30
+ if cells.size == 3 #has detail
31
+ state = "#{cells[0].text.strip[1,100]} [#{cells[2].text.strip}]"
32
+ time = Time.parse(cells[1].text.strip) rescue Time.now
33
+ else # finished?
34
+ state = cells[0].text.strip
32
35
  time = Time.now
33
- state = doc.css('.table_okurijo_detail').first.css('tr').last.css('td').text.strip
34
- if state =~ /恐れ入りますが、お問い合せ送り状NOをお確かめください。|お荷物データが登録されておりません。/
35
- raise NotMyKey.new('invalid key')
36
- end
37
- return time, state
38
- rescue NoMethodError
39
- raise NotMyKey.new('invalid response')
40
36
  end
37
+ if state =~ /恐れ入りますが、お問い合せ送り状NOをお確かめください。|お荷物データが登録されておりません。/
38
+ raise NotMyKey.new('invalid key')
39
+ end
40
+ return time, state
41
+ rescue NoMethodError
42
+ raise NotMyKey.new('invalid response')
41
43
  rescue ArgumentError
42
44
  return Time.now, ''
43
45
  end
@@ -1,3 +1,3 @@
1
1
  module TakuhaiStatus
2
- VERSION = "1.8.9"
2
+ VERSION = "1.9.2"
3
3
  end
@@ -14,13 +14,23 @@ module TakuhaiStatus
14
14
 
15
15
  # loading plugins
16
16
  @@services = []
17
- def self.add_service(service_name)
18
- @@services << service_name
17
+ # service_class as class
18
+ def self.add_service(service_class)
19
+ @@services << service_class
19
20
  end
20
21
  Dir.glob("#{File.dirname(__FILE__)}/takuhai_status/*.rb") do |plugin|
21
22
  require plugin
22
23
  end
23
24
 
25
+ # service_name as symbol, cf. :USPS
26
+ def self.ignore_service(service_name)
27
+ begin
28
+ @@services.delete(TakuhaiStatus.const_get(service_name))
29
+ rescue NameError
30
+ return nil
31
+ end
32
+ end
33
+
24
34
  def self.scan(key, timeout: 10, logger: Logger.new(nil))
25
35
  services = []
26
36
  [].tap{|threads|
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_runtime_dependency "faraday_middleware"
26
26
 
27
27
  spec.add_development_dependency "bundler"
28
- spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rake", "~> 12.0"
29
29
  spec.add_development_dependency "rspec"
30
30
  spec.add_development_dependency "pry"
31
31
  spec.add_development_dependency "travis"
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.8.9
4
+ version: 1.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - TADA Tadashi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-14 00:00:00.000000000 Z
11
+ date: 2021-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '10.0'
89
+ version: '12.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '10.0'
96
+ version: '12.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rspec
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
180
  - !ruby/object:Gem::Version
181
181
  version: '0'
182
182
  requirements: []
183
- rubygems_version: 3.0.1
183
+ rubygems_version: 3.2.22
184
184
  signing_key:
185
185
  specification_version: 4
186
186
  summary: get delivery status of Takuhai-bin in Japan