jp_post 0.0.1
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 +7 -0
- data/.gitignore +18 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +68 -0
- data/LICENSE.txt +22 -0
- data/README.md +46 -0
- data/jp_post.gemspec +26 -0
- data/lib/jp_post/tracking.rb +74 -0
- data/lib/jp_post/version.rb +3 -0
- data/lib/jp_post.rb +5 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ed8fae8b77e629216a0372bd02f42a0f8314d5a7
|
4
|
+
data.tar.gz: 225992dbba78ad33c9827b4ac2517ef58b4586a8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 56448f562c0000fa69c2aed2cee8d29210dd1299f42f903e9b520a2475b23e1554e8479be7762cdcfafc0485448aebf897abdcc161a689ad02682e09bc2be814
|
7
|
+
data.tar.gz: 496b9cc7902097eab34f34c088db42ee399552726ccded657ce8118b34da050c743d5fe06cf6fdf48cb2386e21a0d62a3edeec44e2bcb6399a3423dc399c0ac3
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
jp_post (0.0.1)
|
5
|
+
chronic
|
6
|
+
nokogiri
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
celluloid (0.16.0)
|
12
|
+
timers (~> 4.0.0)
|
13
|
+
chronic (0.10.2)
|
14
|
+
coderay (1.1.0)
|
15
|
+
diff-lcs (1.2.5)
|
16
|
+
ffi (1.9.6)
|
17
|
+
formatador (0.2.5)
|
18
|
+
guard (2.8.0)
|
19
|
+
formatador (>= 0.2.4)
|
20
|
+
listen (~> 2.7)
|
21
|
+
lumberjack (~> 1.0)
|
22
|
+
pry (>= 0.9.12)
|
23
|
+
thor (>= 0.18.1)
|
24
|
+
guard-rspec (4.3.1)
|
25
|
+
guard (~> 2.1)
|
26
|
+
rspec (>= 2.14, < 4.0)
|
27
|
+
hitimes (1.2.2)
|
28
|
+
listen (2.7.11)
|
29
|
+
celluloid (>= 0.15.2)
|
30
|
+
rb-fsevent (>= 0.9.3)
|
31
|
+
rb-inotify (>= 0.9)
|
32
|
+
lumberjack (1.0.9)
|
33
|
+
method_source (0.8.2)
|
34
|
+
mini_portile (0.6.0)
|
35
|
+
nokogiri (1.6.3.1)
|
36
|
+
mini_portile (= 0.6.0)
|
37
|
+
pry (0.10.1)
|
38
|
+
coderay (~> 1.1.0)
|
39
|
+
method_source (~> 0.8.1)
|
40
|
+
slop (~> 3.4)
|
41
|
+
rb-fsevent (0.9.4)
|
42
|
+
rb-inotify (0.9.5)
|
43
|
+
ffi (>= 0.5.0)
|
44
|
+
rspec (3.1.0)
|
45
|
+
rspec-core (~> 3.1.0)
|
46
|
+
rspec-expectations (~> 3.1.0)
|
47
|
+
rspec-mocks (~> 3.1.0)
|
48
|
+
rspec-core (3.1.7)
|
49
|
+
rspec-support (~> 3.1.0)
|
50
|
+
rspec-expectations (3.1.2)
|
51
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
+
rspec-support (~> 3.1.0)
|
53
|
+
rspec-mocks (3.1.3)
|
54
|
+
rspec-support (~> 3.1.0)
|
55
|
+
rspec-support (3.1.2)
|
56
|
+
slop (3.6.0)
|
57
|
+
thor (0.19.1)
|
58
|
+
timers (4.0.1)
|
59
|
+
hitimes
|
60
|
+
|
61
|
+
PLATFORMS
|
62
|
+
ruby
|
63
|
+
|
64
|
+
DEPENDENCIES
|
65
|
+
bundler
|
66
|
+
guard-rspec
|
67
|
+
jp_post!
|
68
|
+
rspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Sebastian Szturo
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
## JP Post :postbox:
|
2
|
+
|
3
|
+
A gem to access JP Post Services.
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
- Ruby 1.9
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this to your gemfile
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'jp_post'
|
14
|
+
```
|
15
|
+
|
16
|
+
and
|
17
|
+
|
18
|
+
```
|
19
|
+
bundle
|
20
|
+
```
|
21
|
+
|
22
|
+
## Tracking
|
23
|
+
|
24
|
+
Track a package with it's item number.
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
package = JpPost::Tracking.new("RR123455678")
|
28
|
+
```
|
29
|
+
|
30
|
+
Access information from the tracking website.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
package = JpPost::Tracking.new("CI123455678")
|
34
|
+
|
35
|
+
package.classification # e.g. Parcel
|
36
|
+
package.additional_services # Additional Services
|
37
|
+
package.history # Array of package movement history
|
38
|
+
```
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create new Pull Request
|
data/jp_post.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jp_post/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jp_post"
|
8
|
+
spec.version = JpPost::VERSION
|
9
|
+
spec.authors = ["Sebastian Szturo"]
|
10
|
+
spec.email = ["s.szturo@me.com"]
|
11
|
+
spec.description = "Gem to access JP Posts Services."
|
12
|
+
spec.summary = "Gem to access JP Posts Services."
|
13
|
+
spec.homepage = "http://github.com/SebastianSzturo/jp_post"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "nokogiri"
|
22
|
+
spec.add_dependency "chronic"
|
23
|
+
spec.add_development_dependency "bundler"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "guard-rspec"
|
26
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "open-uri"
|
2
|
+
require "nokogiri"
|
3
|
+
require "chronic"
|
4
|
+
|
5
|
+
module JpPost
|
6
|
+
class Tracking
|
7
|
+
# Create a new Tracking object.
|
8
|
+
#
|
9
|
+
# tracking_number - tracking number of the package to lookup.
|
10
|
+
#
|
11
|
+
# Returns an instance of JpPost::Tracking.
|
12
|
+
def initialize(tracking_number)
|
13
|
+
raise ArgumentError unless tracking_number
|
14
|
+
|
15
|
+
@tracking_number = tracking_number
|
16
|
+
tracking_url = "https://trackings.post.japanpost.jp/services/srv/search/direct?reqCodeNo1=#{@tracking_number}&locale=en"
|
17
|
+
|
18
|
+
@tracking_page = Nokogiri::HTML(open(tracking_url))
|
19
|
+
|
20
|
+
raise RuntimeError, "No Tracking found." if @tracking_page.css(".indent table[summary='履歴情報']").empty?
|
21
|
+
end
|
22
|
+
|
23
|
+
# "Class of Goods" string from tracking site
|
24
|
+
#
|
25
|
+
# Returns classification String.
|
26
|
+
def classification
|
27
|
+
@delivery_status_details_box ||= @tracking_page.css(".indent table[summary='配達状況詳細']")
|
28
|
+
classification = @delivery_status_details_box.css("tr:last .w_380").text.strip
|
29
|
+
return classification
|
30
|
+
end
|
31
|
+
|
32
|
+
# "Additional Services" string from tracking site
|
33
|
+
#
|
34
|
+
# Returns additional_services String.
|
35
|
+
def additional_services
|
36
|
+
@delivery_status_details_box ||= @tracking_page.css(".indent table[summary='配達状況詳細']")
|
37
|
+
additional_services = @delivery_status_details_box.css(".w_100").last.text.strip
|
38
|
+
return additional_services
|
39
|
+
end
|
40
|
+
|
41
|
+
# "History Information" table from tracking site
|
42
|
+
#
|
43
|
+
# Returns tracking history as Array.
|
44
|
+
def history
|
45
|
+
@history_information_box ||= @tracking_page.css(".indent table[summary='履歴情報']")
|
46
|
+
history_columns = @history_information_box.css("tr")
|
47
|
+
history_columns = history_columns[2..history_columns.size] # remove header
|
48
|
+
|
49
|
+
history = []
|
50
|
+
|
51
|
+
history_columns.each_with_index do |tr, index|
|
52
|
+
next if index.odd? # skip zip code row
|
53
|
+
date = Chronic.parse(tr.css("td").first.text) rescue nil
|
54
|
+
|
55
|
+
action = tr.css("td")[1].text.strip
|
56
|
+
action = nil if action.empty?
|
57
|
+
|
58
|
+
details = tr.css("td")[2].text.strip
|
59
|
+
details = nil if action.empty?
|
60
|
+
|
61
|
+
office = tr.css("td")[3].text.strip
|
62
|
+
office = nil if action.empty?
|
63
|
+
|
64
|
+
location = tr.css("td")[4].text.strip
|
65
|
+
location = nil if action.empty?
|
66
|
+
|
67
|
+
history << { date: date, action: action, details: details, office: office, location: location }
|
68
|
+
end
|
69
|
+
|
70
|
+
return history
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
data/lib/jp_post.rb
ADDED
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jp_post
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sebastian Szturo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: chronic
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Gem to access JP Posts Services.
|
84
|
+
email:
|
85
|
+
- s.szturo@me.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- Gemfile.lock
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- jp_post.gemspec
|
96
|
+
- lib/jp_post.rb
|
97
|
+
- lib/jp_post/tracking.rb
|
98
|
+
- lib/jp_post/version.rb
|
99
|
+
homepage: http://github.com/SebastianSzturo/jp_post
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.2.2
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: Gem to access JP Posts Services.
|
123
|
+
test_files: []
|