dhl_express 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: 1f134e7ecaec8026474a2ab5ead332f2269cf085
4
- data.tar.gz: 14bb10ad9e5d50291c4501dccb89bfad68414727
3
+ metadata.gz: 51cc9df7fdda53be9dbdd840a346cb328a27de2f
4
+ data.tar.gz: 33f3c84bece5a0cc01d3126fd625d08666486bfe
5
5
  SHA512:
6
- metadata.gz: 55fdd24757fea39f60c415222f17a8be2b2a8776073acdcb464b4d780529e9f9b7e06ceb8b67a044b0355b01f2ba2f4f9ca43941668bb39f59b984d811d8184e
7
- data.tar.gz: efdcb18b5a172e701dda773b62ea794c679cb5cd1dfda2a03bc013e122c737ea4bd000c545eb730d5b035390c5f596962a6d554747dedc7da38135e80751a3c6
6
+ metadata.gz: 97aa304388d0cc9843b71c6dee0972140beb300c9904f57300a28be58a66cf540e0ec00f6b5e7f0d85b0f6c3a3b98d7c4683e6ad80795c3f7762d483a40a328e
7
+ data.tar.gz: 3d3c4ca97aba5ef0d9c4b44eee94612cb52e8fa3d00b1ee84f8d95a618d5c5f6bc2796780f7c3901533d0b06884c03bdde7468264a5a693891cc173a4d56be97
@@ -16,14 +16,14 @@ module DhlExpress
16
16
  tracking_url = "https://www.mydhl.dhl.com/shipmentTracking?AWB=#{@tracking_number}"
17
17
 
18
18
  @tracking_json = JSON.parse(Typhoeus.get(tracking_url).body)
19
-
20
- raise RuntimeError, "No Tracking found." if @tracking_json["results"].nil?
21
19
  end
22
20
 
23
21
  # Origin of the package
24
22
  #
25
23
  # Returns origin as String.
26
24
  def origin
25
+ return nil if tracking_is_empty
26
+
27
27
  origin = @tracking_json["results"][0]["origin"]["value"].strip
28
28
  return origin
29
29
  end
@@ -32,6 +32,8 @@ module DhlExpress
32
32
  #
33
33
  # Returns destination as String.
34
34
  def destination
35
+ return nil if tracking_is_empty
36
+
35
37
  destination = @tracking_json["results"][0]["destination"]["value"].strip
36
38
  return destination
37
39
  end
@@ -40,6 +42,8 @@ module DhlExpress
40
42
  #
41
43
  # Returns status as String.
42
44
  def status
45
+ return nil if tracking_is_empty
46
+
43
47
  status = @tracking_json["results"][0]["description"].strip
44
48
  return status
45
49
  end
@@ -48,6 +52,8 @@ module DhlExpress
48
52
  #
49
53
  # Returns tracking history as Array.
50
54
  def history
55
+ return nil if tracking_is_empty
56
+
51
57
  checkpoints = @tracking_json["results"][0]["checkpoints"]
52
58
 
53
59
  history = []
@@ -77,5 +83,13 @@ module DhlExpress
77
83
  return date
78
84
  end
79
85
 
86
+ def tracking_is_empty
87
+ if @tracking_json["results"].nil?
88
+ return true
89
+ else
90
+ return false
91
+ end
92
+ end
93
+
80
94
  end
81
95
  end
@@ -1,3 +1,3 @@
1
1
  module DhlExpress
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -6,12 +6,6 @@ describe DhlExpress::Tracking do
6
6
  expect { DhlExpress::Tracking.new() }.to raise_error(ArgumentError)
7
7
  end
8
8
 
9
- it "should not initialize with empty tracking" do
10
- VCR.use_cassette 'empty_tracking' do
11
- expect { DhlExpress::Tracking.new("1234567") }.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 = DhlExpress::Tracking.new("6476119576")
@@ -27,6 +21,13 @@ describe DhlExpress::Tracking do
27
21
  expect(package.origin).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 = DhlExpress::Tracking.new("1234567")
28
+ expect(package.origin).to be_nil
29
+ end
30
+ end
30
31
  end
31
32
 
32
33
  describe "#destination" do
@@ -36,6 +37,13 @@ describe DhlExpress::Tracking do
36
37
  expect(package.destination).to be_kind_of(String)
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 = DhlExpress::Tracking.new("1234567")
44
+ expect(package.destination).to be_nil
45
+ end
46
+ end
39
47
  end
40
48
 
41
49
  describe "#status" do
@@ -45,6 +53,13 @@ describe DhlExpress::Tracking do
45
53
  expect(package.status).to be_kind_of(String)
46
54
  end
47
55
  end
56
+
57
+ it "should return nil with empty tracking number" do
58
+ VCR.use_cassette 'empty_tracking' do
59
+ package = DhlExpress::Tracking.new("1234567")
60
+ expect(package.status).to be_nil
61
+ end
62
+ end
48
63
  end
49
64
 
50
65
  describe "#history" do
@@ -54,6 +69,13 @@ describe DhlExpress::Tracking do
54
69
  expect(package.history).to be_kind_of(Array)
55
70
  end
56
71
  end
72
+
73
+ it "should return nil with empty tracking number" do
74
+ VCR.use_cassette 'empty_tracking' do
75
+ package = DhlExpress::Tracking.new("1234567")
76
+ expect(package.history).to be_nil
77
+ end
78
+ end
57
79
  end
58
80
 
59
81
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dhl_express
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