takuhai_status 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +13 -2
- data/lib/takuhai_status/ups.rb +36 -0
- data/lib/takuhai_status/version.rb +1 -1
- data/lib/takuhai_status.rb +2 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96d67dacb52e05760c7973c6b99456f1cf45c7b7
|
4
|
+
data.tar.gz: 387af7f70369463218498988511870c0b3786346
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb3d04f77dd701b0abea40914335f03560c60f0661c1f4fd65e1bcee3f49271ee7ff21e8d70916464c35e1e4a43e66e49c46b290e8c2a4538f5aa7923dc54f3a
|
7
|
+
data.tar.gz: 55f75f03530b696bcbe1ba652e1d9a798325126f630ae6edf62f5f27c799f978ff183ad5d6d3b231b6c685bcea08654028f3cc1d6ec3f988c6fae4d76c956ee9
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# TakuhaiStatus
|
2
2
|
|
3
|
-
|
3
|
+
日本国内外の宅配便の配達ステータスを統一的に得る
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -20,7 +20,18 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
23
|
+
```ruby
|
24
|
+
require 'takuhai_status'
|
25
|
+
|
26
|
+
code = '123456789012' # code of a devivery service
|
27
|
+
s = TakuhaiStatus.scan(code) #=> an instance of services
|
28
|
+
s.stat #=> status string of this service as String
|
29
|
+
s.time #=> Time instance of status changed
|
30
|
+
s.finish? #=> dose the cargo derivering finished?
|
31
|
+
|
32
|
+
# or make new instance of a service directly
|
33
|
+
s = TakuhaiStatus::KuronekoYamato.new(code)
|
34
|
+
```
|
24
35
|
|
25
36
|
## Development
|
26
37
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
module TakuhaiStatus
|
5
|
+
class UPS
|
6
|
+
attr_reader :key, :time, :state
|
7
|
+
|
8
|
+
def initialize(key)
|
9
|
+
@key = key.gsub(/[^a-zA-Z0-9]/, '')
|
10
|
+
@time, @state = check
|
11
|
+
end
|
12
|
+
|
13
|
+
def finish?
|
14
|
+
return !!(@state =~ /配達済み/)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def check
|
19
|
+
uri = "http://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")
|
24
|
+
|
25
|
+
begin
|
26
|
+
state = doc.css('.newstatus #ttc_tt_spStatus h3')[0].text.strip
|
27
|
+
time = "#{doc.css('.secHead ul li')[0].text.match(/\d{4}\/\d{2}\/\d{2} \d{1,2}:\d{2}/)[0]}+5000)"
|
28
|
+
return Time.parse(time), state
|
29
|
+
rescue NoMethodError
|
30
|
+
raise NotMyKey
|
31
|
+
rescue ArgumentError
|
32
|
+
return Time.now, ''
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/takuhai_status.rb
CHANGED
@@ -3,13 +3,14 @@ require "takuhai_status/japanpost"
|
|
3
3
|
require "takuhai_status/kuronekoyamato"
|
4
4
|
require "takuhai_status/sagawa"
|
5
5
|
require "takuhai_status/tmg_cargo"
|
6
|
+
require "takuhai_status/ups"
|
6
7
|
|
7
8
|
module TakuhaiStatus
|
8
9
|
class NotFound < StandardError; end
|
9
10
|
class NotMyKey < StandardError; end
|
10
11
|
|
11
12
|
def self.scan(key)
|
12
|
-
[JapanPost, KuronekoYamato, Sagawa, TMGCargo].each do |service|
|
13
|
+
[JapanPost, KuronekoYamato, Sagawa, TMGCargo, UPS].each do |service|
|
13
14
|
begin
|
14
15
|
return service.new(key)
|
15
16
|
rescue NotMyKey
|
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.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TADA Tadashi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- lib/takuhai_status/kuronekoyamato.rb
|
130
130
|
- lib/takuhai_status/sagawa.rb
|
131
131
|
- lib/takuhai_status/tmg_cargo.rb
|
132
|
+
- lib/takuhai_status/ups.rb
|
132
133
|
- lib/takuhai_status/version.rb
|
133
134
|
- takuhai_status.gemspec
|
134
135
|
homepage: https://github.com/tdtds/takuhai_status
|
@@ -151,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
152
|
version: '0'
|
152
153
|
requirements: []
|
153
154
|
rubyforge_project:
|
154
|
-
rubygems_version: 2.4.5
|
155
|
+
rubygems_version: 2.4.5.1
|
155
156
|
signing_key:
|
156
157
|
specification_version: 4
|
157
158
|
summary: get delivery status of Takuhai-bin in Japan
|