quicktravel_client 2.9.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a76d145655f8fbc3fbfa075eecd441b01e90007
4
- data.tar.gz: e53d5216a6e40d44416c0752db5bfe060ed8f799
3
+ metadata.gz: d406224338a518959484d11dcef14412f50cf92a
4
+ data.tar.gz: c63d38aeadcc3504609d5f0177dafa291d74d789
5
5
  SHA512:
6
- metadata.gz: 44ba1235552de14a7384a47c45d5d25e980f838a05de1c1436dba7da7f6681e733c93b52e22c2bc8010b2ee5edf423c7bc112da498be552863d9621e50259112
7
- data.tar.gz: 464f0a91ca06c4da7549f1c3d0126d4977513cf6a0b52b67b07f250291d6b9ecfe300a69064a3a498ce7cc2ad5f3aa566ff14cb44e8000b18bd8a20fa9e0f660
6
+ metadata.gz: 54c408479abad2926f6573a5703b7d0154feebaf8d60a6bbf59d9189e8f6cbb266798145e1dd47f9f394c4636c826de0ab4bfdd2f1317ab954cfe43f61fd442c
7
+ data.tar.gz: 0b53e81800754f522628d39cbd2602ae486ef8a08e597e3517ba9a5d5a524f8a354252115d998f259747fe553e0c80b3f960b83527a055e8fe69bdc6355c54f5
data/CHANGELOG.md CHANGED
@@ -3,6 +3,20 @@ All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
  This changelog adheres to [Keep a CHANGELOG](http://keepachangelog.com/).
5
5
 
6
+
7
+ ## [3.0.0]
8
+ ### Fixed
9
+ - Allow zero pricing for extra pick items
10
+
11
+ ### Changed
12
+ - Use new reset password url
13
+
14
+ ### Added
15
+ - Setting API
16
+
17
+ ### Removed
18
+ - Removed geocode function on address
19
+
6
20
  ## [2.9.0]
7
21
  ### Changed
8
22
  - Use new API login
@@ -1,5 +1,4 @@
1
1
  require 'quick_travel/adapter'
2
- require 'geokit'
3
2
 
4
3
  module QuickTravel
5
4
  class Address < Adapter
@@ -7,17 +6,6 @@ module QuickTravel
7
6
  QuickTravel::Country.find(@country_id).name
8
7
  end
9
8
 
10
- # TODO: Remove this method
11
- # Geokit is a dependency and ONLY used here
12
- # This function should be done outside this gem
13
- def geocode
14
- @_geocode ||= QuickTravel::Cache.cache("geocode_#{self}") {
15
- Geokit::Geocoders::MultiGeocoder.geocode(to_s)
16
- }
17
- rescue Geokit::Geocoders::TooManyQueriesError
18
- nil # do not cache, do not error
19
- end
20
-
21
9
  def to_s
22
10
  "#{address_line1} #{address_line2}, #{city}, #{post_code}, #{state}, #{country_name}"
23
11
  end
@@ -32,11 +32,11 @@ module QuickTravel
32
32
 
33
33
  def self.request_password(login, url)
34
34
  options = { login: login, url: url }
35
- post_and_validate('/sessions/request_password_reset', options)
35
+ post_and_validate('/api/sessions/request_password_reset', options)
36
36
  end
37
37
 
38
38
  def self.set_password_via_token(token, password)
39
- post_and_validate('/sessions/set_password_via_token', token: token, password: password)
39
+ post_and_validate('/api/sessions/set_password_via_token', token: token, password: password)
40
40
  rescue QuickTravel::AdapterError => e
41
41
  { error: e.message }
42
42
  end
@@ -102,20 +102,28 @@ module QuickTravel
102
102
  end
103
103
  end
104
104
 
105
+ def selected_extra_picks_with_price
106
+ selected_extra_pick_configurations.select(&:priced?)
107
+ end
108
+
105
109
  def selected_extra_picks_price
106
- selected_extra_pick_configurations.map(&:price).total_money
110
+ total_money(selected_extra_picks_with_price.map(&:price))
107
111
  end
108
112
 
109
113
  def selected_extra_picks_price_without_rules
110
- selected_extra_pick_configurations.map(&:price_without_rules).total_money
114
+ total_money(selected_extra_picks_with_price.map(&:price_without_rules))
111
115
  end
112
116
 
113
117
  def selected_extra_picks_price_for_rack_rate
114
- selected_extra_pick_configurations.map(&:price_for_rack_rate).total_money
118
+ total_money(selected_extra_picks_with_price.map(&:price_for_rack_rate))
115
119
  end
116
120
 
117
121
  def selected_extra_picks_applied_rules
118
- selected_extra_pick_configurations.flat_map(&:applied_rules)
122
+ selected_extra_picks_with_price.flat_map(&:applied_rules)
123
+ end
124
+
125
+ def total_money(array)
126
+ array.reduce(Money.new(0), :+)
119
127
  end
120
128
 
121
129
  def pricing_details
@@ -0,0 +1,9 @@
1
+ require 'quick_travel/adapter'
2
+
3
+ module QuickTravel
4
+ class Setting < Adapter
5
+ def self.basic
6
+ find_all!("/api/settings/basic.json").first
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module QuickTravel
2
- VERSION = '2.9.0'
2
+ VERSION = '3.0.0'
3
3
  end
@@ -18,8 +18,6 @@ Gem::Specification.new do |spec|
18
18
 
19
19
  spec.add_dependency 'httparty', '~> 0.14'
20
20
  spec.add_dependency 'json'
21
- # Geokit dependency should be removed (see address.rb for details)
22
- spec.add_dependency 'geokit', '~> 1.8.3' # used in address model
23
21
  spec.add_dependency 'activesupport', '>= 2.0.0'
24
22
  spec.add_dependency 'facets'
25
23
  spec.add_dependency 'money', '>= 3.0', '< 6.0' # 6.0 starts to deprecate/split
@@ -0,0 +1,265 @@
1
+ require 'spec_helper'
2
+ require 'money'
3
+ require 'quick_travel/product_configuration'
4
+
5
+ describe QuickTravel::ProductConfiguration do
6
+ ADULT_PASSENGER_TYPE_ID = 0
7
+ CHILD_PASSENGER_TYPE_ID = 1
8
+
9
+ let(:extra_pick_available) { false }
10
+ let(:extra_pick_minimum_price) { Money.new(2) }
11
+
12
+ let(:applied_rules) { [] }
13
+ let(:extra_pick_applied_rules) { [] }
14
+
15
+ let(:extra_pick_pricing_details) do
16
+ double(
17
+ applied_rules: extra_pick_applied_rules,
18
+ price_per_pax_type: [],
19
+ minimum_price_with_adjustments: extra_pick_minimum_price
20
+ )
21
+ end
22
+
23
+ let(:extra_pick_product) do
24
+ double(
25
+ extras: [],
26
+ pricing_details: extra_pick_pricing_details,
27
+ available?: extra_pick_available
28
+ )
29
+ end
30
+
31
+ let(:unpriced_extra_pick_product) { double(extras: [], available?: true) }
32
+
33
+ let(:extras) { [extra_pick_product] }
34
+
35
+ let(:available) { false }
36
+ let(:minimum_price) { Money.new(10) }
37
+ let(:minimum_without_rules_price) { Money.new(100) }
38
+ let(:minimum_rack_price) { Money.new(50) }
39
+
40
+ let(:pricing_details) do
41
+ double(
42
+ applied_rules: applied_rules,
43
+ price_per_pax_type: [2, 1],
44
+ minimum_price_with_adjustments: minimum_price
45
+ )
46
+ end
47
+
48
+ let(:pricing_details_for_rack_rate) do
49
+ double(
50
+ applied_rules: [],
51
+ price_per_pax_type: [],
52
+ minimum_price_with_adjustments: minimum_rack_price
53
+ )
54
+ end
55
+
56
+ let(:pricing_details_without_rules) do
57
+ double(
58
+ applied_rules: [],
59
+ price_per_pax_type: [],
60
+ minimum_price_with_adjustments: minimum_without_rules_price
61
+ )
62
+ end
63
+
64
+ let(:product) do
65
+ double(
66
+ extras: extras,
67
+ available?: available,
68
+ pricing_details: pricing_details,
69
+ pricing_details_without_rules: pricing_details_without_rules,
70
+ pricing_details_for_rack_rate: pricing_details_for_rack_rate
71
+ )
72
+ end
73
+
74
+ subject(:config) { QuickTravel::ProductConfiguration.new(product) }
75
+
76
+ context '#initialize' do
77
+ it 'should create the extra pick configurations' do
78
+ expect(subject.extra_pick_configurations.size).to be 1
79
+ end
80
+ end
81
+
82
+ context 'selections' do
83
+ it { is_expected.not_to be_selected }
84
+
85
+ context '#select!' do
86
+ before { subject.select! }
87
+ it { is_expected.to be_selected }
88
+
89
+ context '#deselect!' do
90
+ before { subject.deselect! }
91
+ it { is_expected.not_to be_selected }
92
+ end
93
+ end
94
+ end
95
+
96
+ context '#available?' do
97
+ context 'the product is available' do
98
+ let(:available) { true }
99
+ it { is_expected.to be_available }
100
+
101
+ context 'extra pick unavailable' do
102
+ let(:extra_pick_available) { false }
103
+
104
+ context 'non selected extra picks' do
105
+ it { is_expected.to be_available }
106
+ end
107
+
108
+ context 'selected extra pick' do
109
+ before { subject.select_extra_pick(extra_pick_product) }
110
+ it { is_expected.not_to be_available }
111
+ end
112
+ end
113
+ end
114
+
115
+ context 'the product is unavailable' do
116
+ let(:available) { false }
117
+ it { is_expected.not_to be_available }
118
+ end
119
+ end
120
+
121
+ context '#priced?' do
122
+ context 'when the pricing details are present' do
123
+ it { is_expected.to be_priced }
124
+ end
125
+
126
+ context 'when no pricing details are present' do
127
+ let(:pricing_details) { nil }
128
+ it { is_expected.not_to be_priced }
129
+ end
130
+ end
131
+
132
+ context '#price' do
133
+ subject { config.price }
134
+ it { is_expected.to eq minimum_price }
135
+ end
136
+
137
+ context '#price_without_rules' do
138
+ subject { config.price_without_rules }
139
+
140
+ context 'when the rules are not defined' do
141
+ let(:pricing_details_without_rules) { nil }
142
+ it { is_expected.to eq config.price }
143
+ end
144
+
145
+ context 'when the rules are defined' do
146
+ it { is_expected.to eq minimum_without_rules_price }
147
+ end
148
+ end
149
+
150
+ context '#price_for_rack_rate' do
151
+ subject { config.price_for_rack_rate }
152
+
153
+ context 'when the rules are not defined' do
154
+ let(:pricing_details_for_rack_rate) { nil }
155
+ it { is_expected.to eq config.price }
156
+ end
157
+
158
+ context 'when the rules are defined' do
159
+ it { is_expected.to eq minimum_rack_price }
160
+ end
161
+ end
162
+
163
+ context '#total_price' do
164
+ subject { config.total_price }
165
+
166
+ context 'when there are no selected extra picks' do
167
+ it { is_expected.to eq config.price }
168
+ end
169
+
170
+ context 'when there are selected extra picks' do
171
+ before { config.select_extra_pick(extra_pick_product) }
172
+ it { is_expected.to eq extra_pick_minimum_price + minimum_price }
173
+
174
+ context 'without a price' do
175
+ let(:extra_pick_pricing_details) { nil }
176
+ it { is_expected.to eq config.price }
177
+ end
178
+ end
179
+ end
180
+
181
+ context '#total_price_without_rules' do
182
+ subject { config.total_price_without_rules }
183
+ context 'when there are no selected extra picks' do
184
+ it { is_expected.to eq config.price_without_rules }
185
+ end
186
+ end
187
+
188
+ context '#total_price_for_rack_rate' do
189
+ subject { config.total_price_for_rack_rate }
190
+ context 'when there are no selected extra picks' do
191
+ it { is_expected.to eq config.price_for_rack_rate }
192
+ end
193
+ end
194
+
195
+ context '#applied_rules' do
196
+ let(:applied_rules) { [1, 1, 2, 2] }
197
+ subject { config.applied_rules }
198
+ it { is_expected.to eq [1, 2] }
199
+ end
200
+
201
+ context '#total_applied_rules' do
202
+ let(:applied_rules) { [1, 1, 2, 2] }
203
+ let(:extra_pick_applied_rules) { [1, 3] }
204
+ before do
205
+ subject.select_extra_pick(extra_pick_product)
206
+ end
207
+ it 'should return unique rules from product and selected extra picks' do
208
+ expect(subject.total_applied_rules).to eq [1, 2, 3]
209
+ end
210
+ end
211
+
212
+ context '#price_per_passenger_type' do
213
+ it 'should return a price for adult' do
214
+ expect(subject.price_per_passenger_type(ADULT_PASSENGER_TYPE_ID)).to be 2
215
+ end
216
+
217
+ it 'should return a price for child' do
218
+ expect(subject.price_per_passenger_type(CHILD_PASSENGER_TYPE_ID)).to be 1
219
+ end
220
+ end
221
+
222
+ context '#selected_extra_pick_configurations' do
223
+ it 'should have no selected extra picks by default' do
224
+ expect(subject.selected_extra_pick_configurations).to be_empty
225
+ end
226
+ end
227
+
228
+ context '#available_extra_pick_configurations' do
229
+ context 'when there are available extra picks' do
230
+ let(:extra_pick_available) { true }
231
+ it 'should return the available extra picks' do
232
+ expect(subject.available_extra_pick_configurations.size).to be 1
233
+ end
234
+ end
235
+
236
+ context 'when there are no available extra picks' do
237
+ let(:extra_pick_available) { false }
238
+ it 'should return the available extra picks' do
239
+ expect(subject.available_extra_pick_configurations).to be_empty
240
+ end
241
+ end
242
+ end
243
+
244
+ context '#select_extra_picks' do
245
+ let(:extras) { [extra_pick_product, unpriced_extra_pick_product] }
246
+ before do
247
+ subject.select_extra_picks(extras)
248
+ end
249
+
250
+ it 'should select all the extra pick configurations' do
251
+ expect(subject.extra_pick_configurations.all?(&:selected?)).to be true
252
+ end
253
+ end
254
+
255
+ context '#select_extra_pick' do
256
+ context 'when the extra pick does not exist' do
257
+ it 'should raise an exception' do
258
+ expect { subject.select_extra_pick(product) }.to raise_error(
259
+ ArgumentError,
260
+ 'That extra pick does not belong to the product'
261
+ )
262
+ end
263
+ end
264
+ end
265
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+ require 'quick_travel/setting'
3
+
4
+ describe QuickTravel::Checkout do
5
+ subject {
6
+ VCR.use_cassette 'settings_basic' do
7
+ QuickTravel::Setting.basic
8
+ end
9
+ }
10
+
11
+ specify do
12
+ expect(subject.vehicle_optional_fields).to eq %w(weight registration)
13
+ expect(subject.default_passenger_type_id).to eq 1
14
+ expect(subject.time_zone).to eq 'Australia/Adelaide'
15
+ expect(subject.ob_num_pax_requiring_details).to eq 'none'
16
+ expect(subject.person_titles).to eq %w(Mr Mrs Ms Miss)
17
+ end
18
+ end
@@ -0,0 +1,61 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://test.qt.sealink.com.au:8080/api/settings/basic.json
6
+ body:
7
+ encoding: UTF-8
8
+ string: access_key=<QT_KEY>
9
+ headers:
10
+ Content-Length:
11
+ - '0'
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: 'OK '
16
+ headers:
17
+ P3p:
18
+ - CP="IDC DSP CAO COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
19
+ Content-Type:
20
+ - application/json; charset=utf-8
21
+ X-Ua-Compatible:
22
+ - IE=Edge,chrome=1
23
+ Etag:
24
+ - '"168ce77e85be5b01489cbdeb4579ae80"'
25
+ Cache-Control:
26
+ - max-age=0, private, must-revalidate
27
+ X-Request-Id:
28
+ - 9bc0325ad1d87df4cfeabe842fd54665
29
+ X-Runtime:
30
+ - '0.162131'
31
+ Vary:
32
+ - Origin
33
+ Date:
34
+ - Fri, 01 Jan 2016 02:35:07 GMT
35
+ X-Rack-Cache:
36
+ - miss
37
+ X-Content-Type-Options:
38
+ - nosniff
39
+ X-Download-Options:
40
+ - noopen
41
+ X-Frame-Options:
42
+ - sameorigin
43
+ X-Permitted-Cross-Domain-Policies:
44
+ - none
45
+ X-Xss-Protection:
46
+ - 1; mode=block
47
+ Server:
48
+ - WEBrick/1.3.1 (Ruby/2.2.5/2016-04-26)
49
+ Content-Length:
50
+ - '195'
51
+ Connection:
52
+ - Keep-Alive
53
+ Set-Cookie:
54
+ - _session_id=BAh7B0kiD3Nlc3Npb25faWQGOgZFVEkiJTA1MTMxYmM3MzVkODRmNDc3ZTJkYzdjMTQ5YzM3M2Q3BjsAVEkiCXVzZXIGOwBGaQY%3D--a046d093f16ee7b3088c89116f6cfe2d12594657;
55
+ path=/; HttpOnly
56
+ body:
57
+ encoding: UTF-8
58
+ string: '{"vehicle_optional_fields":["weight","registration"],"default_passenger_type_id":1,"time_zone":"Australia/Adelaide","ob_num_pax_requiring_details":"none","person_titles":["Mr","Mrs","Ms","Miss"]}'
59
+ http_version:
60
+ recorded_at: Tue, 23 May 2017 04:09:58 GMT
61
+ recorded_with: VCR 3.0.3
@@ -1,4 +1,4 @@
1
1
  require 'simplecov-rcov'
2
2
  require 'coveralls'
3
3
  require 'coverage/kit'
4
- Coverage::Kit.setup(minimum_coverage: 78.76)
4
+ Coverage::Kit.setup(minimum_coverage: 82.10)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quicktravel_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Noack
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-02-16 00:00:00.000000000 Z
13
+ date: 2017-06-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
@@ -40,20 +40,6 @@ dependencies:
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0'
43
- - !ruby/object:Gem::Dependency
44
- name: geokit
45
- requirement: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: 1.8.3
50
- type: :runtime
51
- prerelease: false
52
- version_requirements: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - "~>"
55
- - !ruby/object:Gem::Version
56
- version: 1.8.3
57
43
  - !ruby/object:Gem::Dependency
58
44
  name: activesupport
59
45
  requirement: !ruby/object:Gem::Requirement
@@ -347,6 +333,7 @@ files:
347
333
  - lib/quick_travel/route_stop.rb
348
334
  - lib/quick_travel/search.rb
349
335
  - lib/quick_travel/service.rb
336
+ - lib/quick_travel/setting.rb
350
337
  - lib/quick_travel/status.rb
351
338
  - lib/quick_travel/trip.rb
352
339
  - lib/quick_travel/vehicle.rb
@@ -363,6 +350,7 @@ files:
363
350
  - spec/passenger_type_spec.rb
364
351
  - spec/payment_type_spec.rb
365
352
  - spec/price_quote_spec.rb
353
+ - spec/product_configuration_spec.rb
366
354
  - spec/product_spec.rb
367
355
  - spec/product_type_spec.rb
368
356
  - spec/products/scheduled_trip_spec.rb
@@ -372,6 +360,7 @@ files:
372
360
  - spec/resource_category_spec.rb
373
361
  - spec/resource_spec.rb
374
362
  - spec/route_spec.rb
363
+ - spec/setting_spec.rb
375
364
  - spec/spec_helper.rb
376
365
  - spec/status_spec.rb
377
366
  - spec/support/cassettes/accommodation_reserve.yml
@@ -409,6 +398,7 @@ files:
409
398
  - spec/support/cassettes/resource_fare_bases.yml
410
399
  - spec/support/cassettes/resource_show.yml
411
400
  - spec/support/cassettes/resource_with_price.yml
401
+ - spec/support/cassettes/settings_basic.yml
412
402
  - spec/support/cassettes/tenant_switcher.yml
413
403
  - spec/support/cassettes/wrong_url.yml
414
404
  - spec/support/coverage_loader.rb
@@ -433,7 +423,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
433
423
  version: '0'
434
424
  requirements: []
435
425
  rubyforge_project:
436
- rubygems_version: 2.4.8
426
+ rubygems_version: 2.5.2
437
427
  signing_key:
438
428
  specification_version: 4
439
429
  summary: Booking process using QuickTravel API
@@ -447,6 +437,7 @@ test_files:
447
437
  - spec/passenger_type_spec.rb
448
438
  - spec/payment_type_spec.rb
449
439
  - spec/price_quote_spec.rb
440
+ - spec/product_configuration_spec.rb
450
441
  - spec/product_spec.rb
451
442
  - spec/product_type_spec.rb
452
443
  - spec/products/scheduled_trip_spec.rb
@@ -456,6 +447,7 @@ test_files:
456
447
  - spec/resource_category_spec.rb
457
448
  - spec/resource_spec.rb
458
449
  - spec/route_spec.rb
450
+ - spec/setting_spec.rb
459
451
  - spec/spec_helper.rb
460
452
  - spec/status_spec.rb
461
453
  - spec/support/cassettes/accommodation_reserve.yml
@@ -493,6 +485,7 @@ test_files:
493
485
  - spec/support/cassettes/resource_fare_bases.yml
494
486
  - spec/support/cassettes/resource_show.yml
495
487
  - spec/support/cassettes/resource_with_price.yml
488
+ - spec/support/cassettes/settings_basic.yml
496
489
  - spec/support/cassettes/tenant_switcher.yml
497
490
  - spec/support/cassettes/wrong_url.yml
498
491
  - spec/support/coverage_loader.rb