jp_post 1.0.1 → 1.0.2
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/lib/jp_post/tracking.rb +16 -2
- data/lib/jp_post/version.rb +1 -1
- data/spec/jp_post/tracking_spec.rb +15 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a409d14c5dd3c09ef990646299fed5c41a98344
|
4
|
+
data.tar.gz: 2c5b2351cbb499e2eb716e5e3c1823e764157a6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18a5a258056c935e7754ffcc76cee2780d14358d5f9bf5b790b5015f807b9a16af140223d2861b7fbdea50fdfb08b31fc6adc63d4592456221f02214b0fadda0
|
7
|
+
data.tar.gz: fc07fc0bd2eeddad07179105ae2ead30c7c0dee057ec7f71d49100218f9cb9b0a1c926d796bbe6190216f2ac8b09643e908f5cadd5e07cd63901744829861b75
|
data/lib/jp_post/tracking.rb
CHANGED
@@ -16,14 +16,14 @@ module JpPost
|
|
16
16
|
tracking_url = "https://trackings.post.japanpost.jp/services/srv/search/direct?reqCodeNo1=#{@tracking_number}&locale=en"
|
17
17
|
|
18
18
|
@tracking_page = Nokogiri::HTML(Typhoeus.get(tracking_url).body)
|
19
|
-
|
20
|
-
raise RuntimeError, "No Tracking found." if @tracking_page.css(".indent table[summary='履歴情報']").empty?
|
21
19
|
end
|
22
20
|
|
23
21
|
# "Class of Goods" string from tracking site
|
24
22
|
#
|
25
23
|
# Returns classification String.
|
26
24
|
def classification
|
25
|
+
return nil if tracking_is_empty
|
26
|
+
|
27
27
|
@delivery_status_details_box ||= @tracking_page.css(".indent table[summary='配達状況詳細']")
|
28
28
|
classification = @delivery_status_details_box.css("tr:last .w_380").text.strip
|
29
29
|
return classification
|
@@ -33,6 +33,8 @@ module JpPost
|
|
33
33
|
#
|
34
34
|
# Returns additional_services String.
|
35
35
|
def additional_services
|
36
|
+
return nil if tracking_is_empty
|
37
|
+
|
36
38
|
@delivery_status_details_box ||= @tracking_page.css(".indent table[summary='配達状況詳細']")
|
37
39
|
additional_services = @delivery_status_details_box.css(".w_100").last.text.strip
|
38
40
|
return additional_services
|
@@ -42,6 +44,8 @@ module JpPost
|
|
42
44
|
#
|
43
45
|
# Returns tracking history as Array.
|
44
46
|
def history
|
47
|
+
return nil if tracking_is_empty
|
48
|
+
|
45
49
|
@history_information_box ||= @tracking_page.css(".indent table[summary='履歴情報']")
|
46
50
|
history_columns = @history_information_box.css("tr")
|
47
51
|
history_columns = history_columns[2..history_columns.size] # remove header
|
@@ -70,5 +74,15 @@ module JpPost
|
|
70
74
|
return history
|
71
75
|
end
|
72
76
|
|
77
|
+
private
|
78
|
+
|
79
|
+
def tracking_is_empty
|
80
|
+
if @tracking_page.css(".indent table[summary='履歴情報']").empty?
|
81
|
+
return true
|
82
|
+
else
|
83
|
+
return false
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
73
87
|
end
|
74
88
|
end
|
data/lib/jp_post/version.rb
CHANGED
@@ -6,12 +6,6 @@ describe JpPost::Tracking do
|
|
6
6
|
expect { JpPost::Tracking.new() }.to raise_error(ArgumentError)
|
7
7
|
end
|
8
8
|
|
9
|
-
it "should not initialize with empty tracking number" do
|
10
|
-
VCR.use_cassette 'empty_tracking' do
|
11
|
-
expect { JpPost::Tracking.new("EL015307999123JP") }.to raise_error(RuntimeError)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
9
|
it "should initialize a tracking object" do
|
16
10
|
VCR.use_cassette 'working_tracking' do
|
17
11
|
package = JpPost::Tracking.new("EL015307999JP")
|
@@ -27,6 +21,13 @@ describe JpPost::Tracking do
|
|
27
21
|
expect(package.classification).to be_kind_of(String)
|
28
22
|
end
|
29
23
|
end
|
24
|
+
|
25
|
+
it "should return nil with empty tracking number" do
|
26
|
+
VCR.use_cassette 'empty_tracking' do
|
27
|
+
package = JpPost::Tracking.new("EL015307999123JP")
|
28
|
+
expect(package.classification).to be_nil
|
29
|
+
end
|
30
|
+
end
|
30
31
|
end
|
31
32
|
|
32
33
|
describe "#history" do
|
@@ -36,6 +37,13 @@ describe JpPost::Tracking do
|
|
36
37
|
expect(package.history).to be_kind_of(Array)
|
37
38
|
end
|
38
39
|
end
|
40
|
+
|
41
|
+
it "should return nil with empty tracking number" do
|
42
|
+
VCR.use_cassette 'empty_tracking' do
|
43
|
+
package = JpPost::Tracking.new("EL015307999123JP")
|
44
|
+
expect(package.history).to be_nil
|
45
|
+
end
|
46
|
+
end
|
39
47
|
end
|
40
|
-
|
48
|
+
|
41
49
|
end
|