takuhai_status 1.5.4 → 1.5.5

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
  SHA1:
3
- metadata.gz: 7f14c1d5a4218cae9a9f0bb85cf852eae84487bc
4
- data.tar.gz: a888a2055a49d8d3eee4a59e3db6519aaf6cf68d
3
+ metadata.gz: 9be075febbf69c7a73c761d80ccf7d8589315d2c
4
+ data.tar.gz: f40577194d5dcff9daea8ae4b656904161d8205c
5
5
  SHA512:
6
- metadata.gz: 9264f0d3ab1cd3caa844a2f0a36d28f300d90fd9da0bb06708ef3d3f6cfdc70e237ffa751dee38ea8c5482be769fa37f256eddb837c6869d1968e74b2abc8b41
7
- data.tar.gz: e7b0a57618383160667333d964a1bd1188dfe49ab71bfd18f59d49c69afedd9e01ea64cabfff324fb0dd9c97083a8dc904ddca7a9a92a7fb111245399b9896d9
6
+ metadata.gz: ebcc0043195c97a5311a047b32f20620c1336dc330d606ad372e9c8652542d1421fb715dfc44a63e2627f4ed847f5d36db84dc97efa3cc20f131e37a53f49cc3
7
+ data.tar.gz: d372dca2d79255b2ec66ecf9e521cff2c655924e8219e2f3ac2842c7c533c50afe02ffbad0b12862d814a3fa6c7bed69d049e674b486d9dbdb9483cb13e2cd42
@@ -1,9 +1,11 @@
1
1
  require 'open-uri'
2
+ require 'faraday'
2
3
  require 'nokogiri'
3
4
 
4
5
  module TakuhaiStatus
5
6
  class UPS
6
7
  attr_reader :key, :time, :state
8
+ @@conn = nil
7
9
 
8
10
  def initialize(key)
9
11
  @key = key.gsub(/[^a-zA-Z0-9]/, '')
@@ -16,18 +18,26 @@ module TakuhaiStatus
16
18
 
17
19
  private
18
20
  def check
19
- uri = "https://www.ups.com/WebTracking/processInputRequest?loc=ja_JP&Requester=NES&tracknum=#{@key}"
20
- html = open(uri, &:read)
21
- # HTML中に謎の大量ヌル文字が含まれていてnokogiriのパースが止まる対策
22
- html.gsub!(/\u0000/,'')
23
- doc = Nokogiri::HTML.parse(html, uri, "utf-8")
21
+ @@conn = Faraday.new(url: 'https://wwwapps.ups.com/'){|builder|
22
+ builder.use :cookie_jar
23
+ builder.request :url_encoded
24
+ builder.adapter :net_http
25
+ } unless @@conn
26
+ @@conn.get('/WebTracking/track?loc=ja_JP') # once access to set cookie
27
+ res = @@conn.post('/WebTracking/track?loc=ja_JP', {
28
+ HTMLVersion: '5.0',
29
+ loc: 'ja',
30
+ trackNums: @key,
31
+ 'track.x' => 'Track'
32
+ })
33
+ doc = Nokogiri::HTML.parse(res.body)
24
34
 
25
35
  begin
26
36
  state = doc.css('.newstatus h3')[0].text.strip
27
37
  begin
28
- time = "#{doc.css('.secHead ul li')[0].text.match(/\d{4}\/\d\d\/\d\d \d{1,2}:\d\d/)[0]}+0500)"
38
+ time = "#{doc.css('#fontControlButtons li li').text.match(/\d{4}\/\d\d\/\d\d \d{1,2}:\d\d/)[0]}+0500)"
29
39
  rescue NoMethodError
30
- time = "#{doc.css('.secHead ul li')[0].text.match(/\d{4}\/\d\d\/\d\d/)[0]} 00:00:00+0500)"
40
+ time = "#{doc.css('#fontControlButtons li').text.match(/\d{4}\/\d\d\/\d\d/)[0]} 00:00:00+0500)"
31
41
  end
32
42
  return Time.parse(time).localtime, state
33
43
  rescue NoMethodError
@@ -1,3 +1,3 @@
1
1
  module TakuhaiStatus
2
- VERSION = "1.5.4"
2
+ VERSION = "1.5.5"
3
3
  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.5.4
4
+ version: 1.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - TADA Tadashi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-30 00:00:00.000000000 Z
11
+ date: 2017-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  version: '0'
155
155
  requirements: []
156
156
  rubyforge_project:
157
- rubygems_version: 2.6.4
157
+ rubygems_version: 2.6.11
158
158
  signing_key:
159
159
  specification_version: 4
160
160
  summary: get delivery status of Takuhai-bin in Japan