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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a3861e56e139d377bed716a3b77f53bff4338057
4
- data.tar.gz: 07f22ff16e9259f70e93f00bfdd77f5313766409
3
+ metadata.gz: 8a409d14c5dd3c09ef990646299fed5c41a98344
4
+ data.tar.gz: 2c5b2351cbb499e2eb716e5e3c1823e764157a6e
5
5
  SHA512:
6
- metadata.gz: 5b12b9b562939297d2906e4888372c008cd25596d56cef80b7a55c0596db622d2e93ea18f29cdbdd95c7d10185df5fbc0fb1f9290d83ef19e0b0cbe551c59176
7
- data.tar.gz: ccca31830e4808aba44842b59a5880f0a8879f6268bb792ca7db01e976cf96b9b32d0226b1f60581485fdc23c7f07fc64cde5224214b1808e9ad6ce190013d52
6
+ metadata.gz: 18a5a258056c935e7754ffcc76cee2780d14358d5f9bf5b790b5015f807b9a16af140223d2861b7fbdea50fdfb08b31fc6adc63d4592456221f02214b0fadda0
7
+ data.tar.gz: fc07fc0bd2eeddad07179105ae2ead30c7c0dee057ec7f71d49100218f9cb9b0a1c926d796bbe6190216f2ac8b09643e908f5cadd5e07cd63901744829861b75
@@ -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
@@ -1,3 +1,3 @@
1
1
  module JpPost
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jp_post
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Szturo