bring 0.0.1 → 0.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: 97d5eec883fe2e9e432dfe019281bde0a2d1994f
4
- data.tar.gz: 1849980a27923652ee5eaec13c21abd5a7c4f828
3
+ metadata.gz: 23a8f32332ed5d7b2ce6ac9721462793191ff4e2
4
+ data.tar.gz: acb517dad6c7302cee55eb68893a8fac6dba1e3f
5
5
  SHA512:
6
- metadata.gz: a32c9f8183a00f32d1d63449751e1f0445ae6d2828ca5bee4b8b0c98bf4941f1f617d7342d007255da94963feb4510e7f1e4a30b20a19647bfd7ded10922999f
7
- data.tar.gz: 50f6f069b0c1ebee7ae5adeb587538377a9a27d7255a4d8256d0e72f45a541e391b40b0a1192aed984faabbb0d6133963446047575d38592dc0753d357612ae4
6
+ metadata.gz: 307300495e88e1c9e97751fcd50adf57a524a21d43066fb6089af12d19d61c34fdf7e1462d39329f8a9115234b5ce44650830380af3e03333da0164eacfc30ec
7
+ data.tar.gz: 57fe9ef6963eff79bdc1f48eb6016014efb812034d13c2607c7c08b8f523a035d9c74f97b38e8ab27c39be41e904221224b5739c240b0ea3adf13ece0a095c69
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  A simple ruby library for communicating with the Bring's APIs (see:
6
6
  [developer.bring.com](http://developer.bring.com)).
7
7
 
8
- *For now only the Postal Code API is supported.*
8
+ *For now only the Postal Code and Tracking API is supported.*
9
9
 
10
10
  ## Installation
11
11
 
@@ -28,6 +28,19 @@ From the commandline:
28
28
  $ bring postal_code 0190 no
29
29
  OSLO
30
30
 
31
+ $ bring tracking TESTPACKAGE-EDI
32
+ Shipment Number: SHIPMENTNUMBER
33
+ Total Weight: 16.5 kg
34
+ Total Volume: 45.2 dm3
35
+ Number of Packages: 1
36
+
37
+ Package Number: TESTPACKAGEEDI
38
+ Measurements: 41x38x29 cm (LxWxH)
39
+
40
+ Status: PRE_NOTIFIED
41
+ Ingen sending er mottatt ennå, kun melding om dette
42
+ 2013-10-06 12:44
43
+
31
44
  Or in Ruby:
32
45
  ```ruby
33
46
  require 'bring/postal_code'
@@ -28,5 +28,8 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency "faraday", "~> 0.8.0"
29
29
  spec.add_dependency "faraday_middleware"
30
30
 
31
- spec.add_dependency "json" if RUBY_VERSION.start_with?('1.8')
31
+ if RUBY_VERSION.start_with?('1.8')
32
+ spec.add_dependency "json"
33
+ spec.add_dependency "system_timer"
34
+ end
32
35
  end
@@ -8,5 +8,64 @@ module Bring
8
8
  require 'bring/postal_code'
9
9
  puts PostalCode.new(pnr, :country => options[:country]).city
10
10
  end
11
+
12
+ desc 'tracking TRACKING_NUMBER', 'get tracking data from TRACKING_NUMBER'
13
+ option :full, :type => :boolean
14
+ option :color, :type => :boolean, :default => true
15
+ def tracking(tracking_number)
16
+ require 'bring/tracking'
17
+ begin
18
+ tracking = Tracking.new(tracking_number)
19
+
20
+ tracking.consignments.each do |consignment|
21
+ say "Shipment Number: #{consignment.consignment_id}", :white
22
+ say "Total Weight: #{consignment.total_weight_in_kgs} kg"
23
+ say "Total Volume: #{consignment.total_volume_in_dm3} dm3"
24
+ say "Number of Packages: #{consignment.packages.count}"
25
+
26
+ consignment.packages.each do |package|
27
+ say ""
28
+ say "Package Number: #{package.package_number}", :white
29
+
30
+ if package.sender_name
31
+ say "Sender: #{package.sender_name}"
32
+ end
33
+
34
+ if package.recipient_address
35
+ say "Recipient: #{package.recipient_address.to_s}"
36
+ end
37
+
38
+ sizes =
39
+ [package.length_in_cm, package.width_in_cm, package.height_in_cm]
40
+ say "Measurements: #{sizes.join('x')} cm (LxWxH)"
41
+
42
+ if package.date_of_return
43
+ say "Last day for retrieval: #{package.date_of_return}"
44
+ end
45
+
46
+ package.events.each_with_index do |event, index|
47
+ color = event.color if options[:color]
48
+ say ""
49
+ say "Status: #{event.status}", color
50
+ say event.description
51
+
52
+ say "#{event.date.strftime('%Y-%m-%d %H:%M')}", nil, false
53
+ if event.postal_code?
54
+ say ", #{event.postal_code} #{event.city}", nil, false
55
+ end
56
+ say ''
57
+
58
+ break unless options[:full] || index > 0
59
+ end
60
+ end
61
+ end
62
+ rescue Bring::Tracking::Error => exception
63
+ raise Thor::Error, exception.message
64
+ end
65
+ end
66
+
67
+ def self.exit_on_failure?
68
+ true
69
+ end
11
70
  end
12
71
  end
@@ -10,7 +10,8 @@ module Bring
10
10
  end
11
11
 
12
12
  def initialize(pnr, options = {})
13
- @postal_code, @country = pnr, options[:country]
13
+ @postal_code = pnr
14
+ @country = options[:country] || 'no'
14
15
  end
15
16
 
16
17
  def city
@@ -0,0 +1,166 @@
1
+ require 'date'
2
+ require 'bring/base_request'
3
+
4
+ module Bring
5
+ class Tracking < BaseRequest
6
+ attr_reader :tracking_number
7
+
8
+ def initialize(tracking_number)
9
+ @tracking_number = tracking_number
10
+ end
11
+
12
+ class Error < StandardError
13
+ end
14
+
15
+ class ApiClass
16
+ def initialize(data)
17
+ @data = data
18
+ raise(Error, error_message) if has_errors?
19
+ end
20
+
21
+ def has_errors?
22
+ !data['error'].nil?
23
+ end
24
+
25
+ def error_message
26
+ "#{data['error']['message']} (#{data['error']['code']})"
27
+ end
28
+
29
+
30
+ def self.attribute(name)
31
+ define_method name do
32
+ data[camelize(name)]
33
+ end
34
+ end
35
+
36
+ private
37
+ def data
38
+ @data
39
+ end
40
+
41
+ def camelize(string)
42
+ string.to_s.split('_').each_with_index { |word, index|
43
+ word.capitalize! unless index == 0
44
+ }.join
45
+ end
46
+ end
47
+
48
+ class Address < ApiClass
49
+ attribute :address_line_1
50
+ attribute :address_line_2
51
+ attribute :postal_code
52
+ attribute :city
53
+ attribute :country_code
54
+ attribute :country
55
+
56
+ def to_s
57
+ address =
58
+ [ address_line_1, address_line_2, "#{postal_code} #{city}", country ]
59
+ address.delete_if { |line| line.nil? || line == '' }
60
+ address.join(', ')
61
+ end
62
+ end
63
+
64
+ class Definition < ApiClass
65
+ attribute :term
66
+ attribute :explanation
67
+ end
68
+
69
+ class Event < ApiClass
70
+ attribute :description
71
+ attribute :status
72
+ attribute :unit_id
73
+ attribute :unit_information_url
74
+ attribute :unit_type
75
+ attribute :postal_code
76
+ attribute :city
77
+ attribute :country_code
78
+ attribute :country
79
+ attribute :date_iso
80
+ attribute :display_date
81
+ attribute :display_time
82
+ attribute :consignment_event
83
+
84
+ def postal_code?
85
+ !(postal_code.nil? or postal_code.empty?)
86
+ end
87
+
88
+ def date
89
+ @date ||= DateTime.strptime(date_iso)
90
+ end
91
+
92
+ def definitions
93
+ return [] if data['definitions'].nil?
94
+ data['definitions'].map { |attr| Definition.new attr }
95
+ end
96
+
97
+ def color
98
+ case status
99
+ when 'READY_FOR_PICKUP' then :yellow
100
+ when 'DELIVERED' then :green
101
+ end
102
+ end
103
+ end
104
+
105
+ class Package < ApiClass
106
+ attribute :status_description
107
+ attribute :descriptions
108
+ attribute :package_number
109
+ attribute :previous_package_number
110
+ attribute :product_name
111
+ attribute :product_code
112
+ attribute :brand
113
+ attribute :length_in_cm
114
+ attribute :width_in_cm
115
+ attribute :height_in_cm
116
+ attribute :volume_in_dm3
117
+ attribute :weight_in_kgs
118
+ attribute :pickup_code
119
+ attribute :sender_name
120
+
121
+ def date_of_return
122
+ return if data['dateOfReturn'].nil?
123
+ @date_of_return ||= Date.strptime(data['dateOfReturn'], '%d.%m.%Y')
124
+ end
125
+
126
+ def recipient_address
127
+ return unless data['recipientAddress'].is_a?(Hash)
128
+ @address ||= Address.new(data['recipientAddress'])
129
+ end
130
+
131
+ def events
132
+ @events ||= data['eventSet'].map { |attr| Event.new(attr) }
133
+ end
134
+ end
135
+
136
+ class Consignment < ApiClass
137
+ attribute :consignment_id
138
+ attribute :previous_consignment_id
139
+ attribute :total_weight_in_kgs
140
+ attribute :total_volume_in_dm3
141
+
142
+ def packages
143
+ return [] if data['packageSet'].nil?
144
+ @packages ||=
145
+ data['packageSet'].map { |attr| Package.new attr }
146
+ end
147
+ end
148
+
149
+ def consignments
150
+ return [] if data['consignmentSet'].nil?
151
+ @consignments ||=
152
+ data['consignmentSet'].map { |attr| Consignment.new attr }
153
+ end
154
+
155
+ private
156
+ def data
157
+ @data ||= connection.get do |req|
158
+ req.params['q'] = tracking_number
159
+ end.body
160
+ end
161
+
162
+ def api_url
163
+ 'http://sporing.bring.no/sporing.json'.freeze
164
+ end
165
+ end
166
+ end
@@ -1,3 +1,3 @@
1
1
  module Bring
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,19 +1,132 @@
1
+ # encoding: utf-8
1
2
  require 'spec_helper'
2
3
  require 'bring/cli'
3
4
 
4
- describe Bring::CLI, :vcr do
5
+ describe Bring::CLI do
5
6
  def invoke!(*args)
6
7
  capture(:stdout) { Bring::CLI.start(args) }
7
8
  end
8
9
 
9
- describe 'postal_code' do
10
+ describe 'postal_code', :vcr => { :cassette_name => 'postal_code' } do
10
11
  it 'displays city for pnr' do
11
12
  expect(invoke! 'postal_code', '0190').to eq "OSLO\n"
12
13
  end
13
14
 
14
- it 'takes a country' do
15
+ it 'takes a country', :vcr => { :cassette_name => 'postal_code_se' } do
15
16
  arguments = %w[postal_code 12000 --country se]
16
17
  expect(invoke!(*arguments)).to eq "Stockholm\n"
17
18
  end
18
19
  end
20
+
21
+ describe 'tracking' do
22
+ use_vcr_cassette 'tracking_ready_for_pickup'
23
+ let(:output) { invoke!('tracking', 'TESTPACKAGE-AT-PICKUPPOINT') }
24
+
25
+ it 'displays shipment number' do
26
+ expect(output).to include 'Shipment Number: SHIPMENTNUMBER'
27
+ end
28
+
29
+ it 'displays sender' do
30
+ expect(output).to include 'Sender: POSTEN NORGE AS'
31
+ end
32
+
33
+ it 'displays recipient' do
34
+ expect(output).to include 'Recipient: 1407 VINTERBRO'
35
+ end
36
+
37
+ it 'displays packing number' do
38
+ expect(output).to include 'Package Number: TESTPACKAGEATPICKUPPOINT'
39
+ end
40
+
41
+ it 'displays package size' do
42
+ expect(output).to include 'Measurements: 41x38x29 cm (LxWxH)'
43
+ end
44
+
45
+ it 'displays package weight' do
46
+ expect(output).to include 'Weight: 16.5 kg'
47
+ end
48
+
49
+ it 'displays number of packages' do
50
+ expect(output).to include 'Number of Packages: 1'
51
+ end
52
+
53
+ it 'only displays most recent status' do
54
+ expect(output).to include 'Status: READY_FOR_PICKUP'
55
+ expect(output).not_to include 'Status: IN_TRANSIT'
56
+ end
57
+
58
+ it 'displays date and location' do
59
+ expect(output).to include '2010-10-01 08:30, 2341 LØTEN'
60
+ end
61
+
62
+ it 'displays last day for retrieval' do
63
+ expect(output).to include 'Last day for retrieval: 2011-12-01'
64
+ end
65
+
66
+ context 'with --full' do
67
+ let(:output) { invoke!('tracking', 'TESTPACKAGE-AT-PICKUPPOINT', '--full') }
68
+
69
+ it 'displays all events' do
70
+ expect(output).to include 'Status: READY_FOR_PICKUP'
71
+ expect(output).to include 'Status: IN_TRANSIT'
72
+ end
73
+ end
74
+
75
+ context 'with status PRE_NOTIFIED' do
76
+ use_vcr_cassette 'tracking_pre_notified'
77
+ let(:output) { invoke!('tracking', 'TESTPACKAGE-EDI') }
78
+
79
+ it 'displays status' do
80
+ expect(output).to include %q{
81
+ Status: PRE_NOTIFIED
82
+ Ingen sending er mottatt ennå, kun melding om dette
83
+ 2013-10-06 12:44
84
+ }
85
+ end
86
+ end
87
+
88
+ context 'with status READY_FOR_PICKUP' do
89
+ let(:output) { invoke!('tracking', 'TESTPACKAGE-AT-PICKUPPOINT') }
90
+
91
+ it 'displays status' do
92
+ expect(output).to include %q{
93
+ Status: READY_FOR_PICKUP
94
+ Sendingen er ankommet postkontor
95
+ 2010-10-01 08:30, 2341 LØTEN}
96
+ end
97
+ end
98
+
99
+ context 'with status TRANSPORT_TO_RECIPIENT' do
100
+ use_vcr_cassette 'tracking_transport_to_recipient'
101
+ let(:output) { invoke!('tracking', 'TESTPACKAGE-LOADED-FOR-DELIVERY') }
102
+
103
+ it 'displays status' do
104
+ expect(output).to include %q{
105
+ Status: TRANSPORT_TO_RECIPIENT
106
+ Sendingen er lastet opp for utkjøring
107
+ 2010-09-30 16:48, 0001 OSLO}
108
+ end
109
+ end
110
+
111
+ context 'with status DELIVERED' do
112
+ use_vcr_cassette 'tracking_delivered'
113
+ let(:output) { invoke!('tracking', 'TESTPACKAGE-DELIVERED') }
114
+
115
+ it 'displays status' do
116
+ expect(output).to include %q{
117
+ Status: DELIVERED
118
+ Sendingen er utlevert
119
+ 2010-09-30 17:45}
120
+ end
121
+ end
122
+
123
+ context 'with invalid tracking number' do
124
+ use_vcr_cassette 'tracking_invalid'
125
+ let(:output) { invoke!('tracking', 'FOO') }
126
+
127
+ it 'exits with error' do
128
+ expect { output }.to raise_error SystemExit
129
+ end
130
+ end
131
+ end
19
132
  end
@@ -2,7 +2,8 @@ require 'spec_helper'
2
2
  require 'bring/postal_code'
3
3
 
4
4
  describe Bring::PostalCode do
5
- describe 'city', :vcr do
5
+ describe 'city' do
6
+ use_vcr_cassette 'postal_code'
6
7
  before do
7
8
  Bring::PostalCode.reset_cache!
8
9
  end
@@ -19,10 +20,14 @@ describe Bring::PostalCode do
19
20
  expect { Bring::PostalCode.new('0190').city }.not_to raise_error
20
21
  end
21
22
 
22
- it 'fetches result for different countries' do
23
- postal_code = Bring::PostalCode.new('12000', :country => 'se')
23
+ context 'when country is sweden' do
24
+ use_vcr_cassette 'postal_code_se'
24
25
 
25
- expect(postal_code.city).to eq 'Stockholm'
26
+ it "fetches result from Bring's API" do
27
+ postal_code = Bring::PostalCode.new('12000', :country => 'se')
28
+
29
+ expect(postal_code.city).to eq 'Stockholm'
30
+ end
26
31
  end
27
32
  end
28
33
  end
@@ -0,0 +1,345 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'bring/tracking'
4
+
5
+ describe Bring::Tracking do
6
+ use_vcr_cassette 'tracking_ready_for_pickup'
7
+ let(:tracking) { Bring::Tracking.new 'TESTPACKAGE-AT-PICKUPPOINT' }
8
+
9
+ describe 'consignments' do
10
+ it 'returns an array of consignments' do
11
+ expect(tracking.consignments).to be_a Array
12
+ expect(tracking.consignments.first).to be_a Bring::Tracking::Consignment
13
+ end
14
+ end
15
+
16
+ describe Bring::Tracking::Address do
17
+ let(:address) { tracking.consignments.first.packages.first.recipient_address}
18
+
19
+ describe 'address_line_1' do
20
+ it 'returns address line 1' do
21
+ expect(address.address_line_1).to eq ''
22
+ end
23
+ end
24
+
25
+ describe 'address_line_2' do
26
+ it 'returns address line 2' do
27
+ expect(address.address_line_2).to eq ''
28
+ end
29
+ end
30
+
31
+ describe 'postal_code' do
32
+ it 'returns postal code' do
33
+ expect(address.postal_code).to eq '1407'
34
+ end
35
+ end
36
+
37
+ describe 'city' do
38
+ it 'returns city' do
39
+ expect(address.city).to eq 'VINTERBRO'
40
+ end
41
+ end
42
+
43
+ describe 'country_code' do
44
+ it 'returns country code' do
45
+ expect(address.country_code).to eq ''
46
+ end
47
+ end
48
+
49
+ describe 'country' do
50
+ it 'returns country' do
51
+ expect(address.country).to eq ''
52
+ end
53
+ end
54
+
55
+ describe 'to_s' do
56
+ it 'formats address' do
57
+ expect(address.to_s).to eq '1407 VINTERBRO'
58
+ end
59
+ end
60
+ end
61
+
62
+ describe Bring::Tracking::Definition do
63
+ let(:event) { tracking.consignments.first.packages.first.events.last }
64
+ let(:definition) { event.definitions.last }
65
+
66
+ describe 'term' do
67
+ it 'returns term' do
68
+ expect(definition.term).to eq 'terminal'
69
+ end
70
+ end
71
+
72
+ describe 'explanation' do
73
+ it 'returns explanation' do
74
+
75
+ expect(definition.explanation).to eq 'Brev, pakke eller godsterminal som benyttes til sortering og omlasting av sendinger som er underveis til mottaker.'
76
+ end
77
+ end
78
+ end
79
+
80
+ describe Bring::Tracking::Event do
81
+ let(:events) { tracking.consignments.first.packages.first.events }
82
+ let(:event) { events.first }
83
+
84
+ describe 'description' do
85
+ it 'returns description' do
86
+ expect(event.description).to eq 'Sendingen er ankommet postkontor'
87
+ end
88
+ end
89
+
90
+ describe 'status' do
91
+ it 'returns status' do
92
+ expect(event.status).to eq 'READY_FOR_PICKUP'
93
+ end
94
+ end
95
+
96
+ describe 'unit_id' do
97
+ it 'returns unit id' do
98
+ expect(event.unit_id).to eq '122608'
99
+ end
100
+ end
101
+
102
+ describe 'color' do
103
+ let(:event) { Bring::Tracking::Event.new '' }
104
+
105
+ it 'returns yellow when status is READY_FOR_PICKUP' do
106
+ event.stub(:status).and_return('READY_FOR_PICKUP')
107
+
108
+ expect(event.color).to eq :yellow
109
+ end
110
+
111
+ it 'returns green when status is DELIVERED' do
112
+ event.stub(:status).and_return('DELIVERED')
113
+
114
+ expect(event.color).to eq :green
115
+ end
116
+ end
117
+
118
+ describe 'unit_information_url' do
119
+ it 'returns unit information url' do
120
+ expect(event.unit_information_url).
121
+ to eq 'http://fraktguide.bring.no/fraktguide/api/pickuppoint/id/122608'
122
+ end
123
+ end
124
+
125
+ describe 'unit_type' do
126
+ it 'returns unit type' do
127
+ expect(event.unit_type).to eq 'BRING'
128
+ end
129
+ end
130
+
131
+ describe 'postal_code' do
132
+ it 'returns postal code' do
133
+ expect(event.postal_code).to eq '2341'
134
+ end
135
+ end
136
+
137
+ describe 'city' do
138
+ it 'returns city' do
139
+ expect(event.city).to eq 'LØTEN'
140
+ end
141
+ end
142
+
143
+ describe 'country_code' do
144
+ it 'returns the country code' do
145
+ expect(event.country_code).to eq 'NO'
146
+ end
147
+ end
148
+
149
+ describe 'country' do
150
+ it 'returns the country' do
151
+ expect(event.country).to eq 'Norway'
152
+ end
153
+ end
154
+
155
+ describe 'date_iso' do
156
+ it 'returns iso-formatted date' do
157
+ expect(event.date_iso).to eq '2010-10-01T08:30:25+02:00'
158
+ end
159
+ end
160
+
161
+ describe 'display_date' do
162
+ it 'returns display date' do
163
+ expect(event.display_date).to eq "01.10.2010"
164
+ end
165
+ end
166
+
167
+ describe 'display_time' do
168
+ it 'returns display time' do
169
+ expect(event.display_time).to eq "08:30"
170
+ end
171
+ end
172
+
173
+ describe 'date' do
174
+ it 'returns datetime' do
175
+ expect(event.date).to be_a(DateTime)
176
+ end
177
+
178
+ it 'equals to date_iso' do
179
+ expect(event.date.to_s).to eq event.date_iso
180
+ end
181
+ end
182
+
183
+ describe 'consignment_event' do
184
+ it 'returns consignment event' do
185
+ expect(event.consignment_event).to eq false
186
+ end
187
+ end
188
+
189
+ describe 'definitions' do
190
+ it 'returns array of definitions' do
191
+ expect(event.definitions).to be_a Array
192
+ end
193
+ end
194
+ end
195
+
196
+ describe Bring::Tracking::Package do
197
+ let(:package) { tracking.consignments.first.packages.first }
198
+
199
+ describe 'status_description' do
200
+ it 'returns status description' do
201
+ expect(package.status_description).
202
+ to eq 'Sendingen kan hentes på postkontor.'
203
+ end
204
+ end
205
+
206
+ describe 'descriptions' do
207
+ it 'returns array of descriptions' do
208
+ expect(package.descriptions).to be_a Array
209
+ end
210
+ end
211
+
212
+ describe 'package_number' do
213
+ it 'returns package number' do
214
+ expect(package.package_number).to eq 'TESTPACKAGEATPICKUPPOINT'
215
+ end
216
+ end
217
+
218
+ describe 'previous_package_number' do
219
+ it 'returns previous package number' do
220
+ expect(package.previous_package_number).to eq ''
221
+ end
222
+ end
223
+
224
+ describe 'product_name' do
225
+ it 'returns product name' do
226
+ expect(package.product_name).to eq 'KLIMANØYTRAL SERVICEPAKKE'
227
+ end
228
+ end
229
+
230
+ describe 'product_code' do
231
+ it 'returns product code' do
232
+ expect(package.product_code).to eq '1202'
233
+ end
234
+ end
235
+
236
+ describe 'brand' do
237
+ it 'returns brand' do
238
+ expect(package.brand).to eq 'POSTEN'
239
+ end
240
+ end
241
+
242
+ describe 'length_in_cm' do
243
+ it 'returns length in cm' do
244
+ expect(package.length_in_cm).to eq 41
245
+ end
246
+ end
247
+
248
+ describe 'width_in_cm' do
249
+ it 'returns width in cm' do
250
+ expect(package.width_in_cm).to eq 38
251
+ end
252
+ end
253
+
254
+ describe 'height_in_cm' do
255
+ it 'returns height in cm' do
256
+ expect(package.height_in_cm).to eq 29
257
+ end
258
+ end
259
+
260
+ describe 'volume_in_dm3' do
261
+ it 'returns volume in dm3' do
262
+ expect(package.volume_in_dm3).to eq 45.2
263
+ end
264
+ end
265
+
266
+ describe 'weight_in_kgs' do
267
+ it 'returns weight in kg' do
268
+ expect(package.weight_in_kgs).to eq 16.5
269
+ end
270
+ end
271
+
272
+ describe 'pickup_code' do
273
+ it 'returns pickup code' do
274
+ expect(package.pickup_code).to eq 'AA11'
275
+ end
276
+ end
277
+
278
+ describe 'date_of_return' do
279
+ it 'is a DateTime' do
280
+ expect(package.date_of_return).to be_a Date
281
+ end
282
+
283
+ it 'returns date of return' do
284
+ expect(package.date_of_return.to_s).to eq '2011-12-01'
285
+ end
286
+ end
287
+
288
+ describe 'sender_name' do
289
+ it 'returns sender name' do
290
+ expect(package.sender_name).to eq 'POSTEN NORGE AS'
291
+ end
292
+ end
293
+
294
+ describe 'recipient_address' do
295
+ it 'returns a Address' do
296
+ expect(package.recipient_address).to be_a Bring::Tracking::Address
297
+ end
298
+ end
299
+
300
+ describe 'events' do
301
+ it 'returns an Array of events' do
302
+ expect(package.events).to be_a Array
303
+ expect(package.events.first).to be_a Bring::Tracking::Event
304
+ end
305
+ end
306
+ end
307
+
308
+ describe Bring::Tracking::Consignment do
309
+ let(:consignment) { tracking.consignments.first }
310
+
311
+ describe 'consignment_id' do
312
+ it 'returns consignment id' do
313
+ expect(consignment.consignment_id).to eq 'SHIPMENTNUMBER'
314
+ end
315
+ end
316
+
317
+ describe 'previous_consignment_id' do
318
+ it 'returns previous consignment id' do
319
+ expect(consignment.previous_consignment_id).to eq ''
320
+ end
321
+ end
322
+
323
+ describe 'total_weight_in_kgs' do
324
+ it 'returns weight in kg' do
325
+ expect(consignment.total_weight_in_kgs).to eq 16.5
326
+ end
327
+ end
328
+
329
+ describe 'total_volume_in_dm3' do
330
+ it 'returns volume in dm3' do
331
+ expect(consignment.total_volume_in_dm3).to eq 45.2
332
+ end
333
+ end
334
+
335
+ context 'when tracking number is invalid' do
336
+ use_vcr_cassette 'tracking_invalid'
337
+ let!(:tracking) { Bring::Tracking.new 'FOO' }
338
+
339
+ it 'raises error' do
340
+ expect { consignment }.to raise_error(Bring::Tracking::Error,
341
+ 'Invalid query (400)')
342
+ end
343
+ end
344
+ end
345
+ end
@@ -19,6 +19,8 @@ RSpec.configure do |config|
19
19
  # This will be default behaviour in RSpec 3
20
20
  config.treat_symbols_as_metadata_keys_with_true_values = true
21
21
 
22
+ config.extend VCR::RSpec::Macros
23
+
22
24
  def capture(stream)
23
25
  begin
24
26
  stream = stream.to_s
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bring
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erlend Finvåg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-06 00:00:00.000000000 Z
11
+ date: 2013-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -130,11 +130,13 @@ files:
130
130
  - lib/bring/cli.rb
131
131
  - lib/bring/configurator.rb
132
132
  - lib/bring/postal_code.rb
133
+ - lib/bring/tracking.rb
133
134
  - lib/bring/version.rb
134
135
  - spec/bring/base_request_spec.rb
135
136
  - spec/bring/cli_spec.rb
136
137
  - spec/bring/configurator_spec.rb
137
138
  - spec/bring/postal_code_spec.rb
139
+ - spec/bring/tracking_spec.rb
138
140
  - spec/spec_helper.rb
139
141
  homepage: https://github.com/wepack/bring
140
142
  licenses:
@@ -165,4 +167,6 @@ test_files:
165
167
  - spec/bring/cli_spec.rb
166
168
  - spec/bring/configurator_spec.rb
167
169
  - spec/bring/postal_code_spec.rb
170
+ - spec/bring/tracking_spec.rb
168
171
  - spec/spec_helper.rb
172
+ has_rdoc: