takuhai_status 1.4.2 → 1.5.0

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: ca5e2767e709bd9aa9a8991009c77ac7e00afd16
4
- data.tar.gz: 210a6a33b154a40ab185df723b607b3b6e138697
3
+ metadata.gz: c52ef367b12ed3bb07b1af389b3c3b1ea5c33380
4
+ data.tar.gz: e937f9c5c0a9253e8b1f382a5602aac4cbe8fbca
5
5
  SHA512:
6
- metadata.gz: 196e05de9e2fcf5f1af5f3cbf32c3b78f26db4a433f0f0a75b02e69b8d72bfb5a1f9c02696a8f4826836853ed55ce04d5a9df42e222adda1c4aef2bbbd133654
7
- data.tar.gz: 13aa79c96495f3186e6da4fa7e43447fe4a94bb6d586342aae6e3d154f88390031d8a336d63d4c06771355c8bc4fc3bc75edbb0fff86638699d7ce8f961f9a8f
6
+ metadata.gz: bd524690dd931e49e2ff04c1b2a2ae5750c4938d9a76099f00d9803d4c99d640617f9b0023d3049e6176382e6513c515cc11c71ec34a62f3b6c19eb6c38430e8
7
+ data.tar.gz: 1a95675c27df6a018459474f6388ba30f9c0e6af4529f8fce77844ffeb73d6250cd6b9aa285af127fa222fd726bf1bd69a9f399d7df40b18ea7938c8988dbe99
@@ -4,6 +4,7 @@ require "takuhai_status/kuronekoyamato"
4
4
  require "takuhai_status/sagawa"
5
5
  require "takuhai_status/tmg_cargo"
6
6
  require "takuhai_status/ups"
7
+ require "takuhai_status/fedex"
7
8
 
8
9
  module TakuhaiStatus
9
10
  class NotFound < StandardError; end
@@ -19,7 +20,7 @@ module TakuhaiStatus
19
20
  def self.scan(key)
20
21
  services = []
21
22
  [].tap{|threads|
22
- [Sagawa, JapanPost, KuronekoYamato, TMGCargo, UPS].each do |service|
23
+ [Sagawa, JapanPost, KuronekoYamato, TMGCargo, UPS, FedEx].each do |service|
23
24
  threads.push(Thread.new{service.new(key)})
24
25
  end
25
26
  }.each{|thread|
@@ -0,0 +1,71 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module TakuhaiStatus
5
+ class FedEx
6
+ attr_reader :key, :time, :state
7
+
8
+ def initialize(key)
9
+ @key = key.gsub(/[^0-9]/, '')
10
+ @time, @state = check
11
+ end
12
+
13
+ def finish?
14
+ return !!(@state =~ /認可済み業者に委託/)
15
+ end
16
+
17
+ private
18
+ def check
19
+ data = {
20
+ "TrackPackagesRequest": {
21
+ "appType": "WTRK",
22
+ "uniqueKey": "",
23
+ "processingParameters": {},
24
+ "trackingInfoList": [
25
+ {
26
+ "trackNumberInfo": {
27
+ "trackingNumber": @key,
28
+ "trackingQualifier": "",
29
+ "trackingCarrier": ""
30
+ }
31
+ }
32
+ ]
33
+ }
34
+ }
35
+ conn = Faraday.new(url: 'https://www.fedex.com'){|builder|
36
+ builder.request :url_encoded
37
+ builder.adapter :net_http
38
+ }
39
+ res = conn.post('/trackingCal/track', {
40
+ data: data.to_json,
41
+ action: 'trackpackages',
42
+ locale: 'ja_JP',
43
+ version: '1',
44
+ format: 'json'
45
+ })
46
+ begin
47
+ data = JSON.parse(res.body)
48
+ raise unless data["TrackPackagesResponse"]["successful"]
49
+
50
+ package = data["TrackPackagesResponse"]["packageList"].first
51
+ current = package["scanEventList"].first
52
+
53
+ begin
54
+ time = Time.parse("#{current['date']} #{current['time']}#{current['+09:00']}")
55
+ rescue ArgumentError
56
+ raise NotMyKey.new('no time status in the package');
57
+ end
58
+
59
+ state = "#{current['status']}"
60
+ state = "#{state}(#{current['scanDetails']})" if current['scanDetails'].size > 0
61
+ state = "#{state} - #{current['scanLocation']}" if current['scanLocation'].size > 0
62
+
63
+ return time, state
64
+ rescue NotMyKey
65
+ raise
66
+ rescue
67
+ return (@time || Time.now), (@state || '')
68
+ end
69
+ end
70
+ end
71
+ end
@@ -1,3 +1,3 @@
1
1
  module TakuhaiStatus
2
- VERSION = "1.4.2"
2
+ VERSION = "1.5.0"
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.4.2
4
+ version: 1.5.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: 2016-02-08 00:00:00.000000000 Z
11
+ date: 2016-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -126,6 +126,7 @@ files:
126
126
  - bin/console
127
127
  - bin/setup
128
128
  - lib/takuhai_status.rb
129
+ - lib/takuhai_status/fedex.rb
129
130
  - lib/takuhai_status/japanpost.rb
130
131
  - lib/takuhai_status/kuronekoyamato.rb
131
132
  - lib/takuhai_status/sagawa.rb
@@ -153,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
154
  version: '0'
154
155
  requirements: []
155
156
  rubyforge_project:
156
- rubygems_version: 2.5.1
157
+ rubygems_version: 2.6.4
157
158
  signing_key:
158
159
  specification_version: 4
159
160
  summary: get delivery status of Takuhai-bin in Japan