quicktravel_client 1.1.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.ruby-version +1 -1
- data/.travis.yml +14 -2
- data/CHANGELOG.md +34 -3
- data/Gemfile +0 -3
- data/Rakefile +0 -6
- data/examples/login_example.rb +1 -1
- data/gemfiles/rails4.gemfile +9 -0
- data/lib/quick_travel.rb +2 -1
- data/lib/quick_travel/accommodation.rb +1 -15
- data/lib/quick_travel/adapter.rb +98 -67
- data/lib/quick_travel/{adapter_exception.rb → adapter_error.rb} +1 -1
- data/lib/quick_travel/address.rb +2 -7
- data/lib/quick_travel/adjustment.rb +0 -2
- data/lib/quick_travel/bed_configuration.rb +0 -1
- data/lib/quick_travel/bed_requirement.rb +0 -1
- data/lib/quick_travel/booking.rb +22 -46
- data/lib/quick_travel/cache.rb +8 -14
- data/lib/quick_travel/checkout.rb +1 -1
- data/lib/quick_travel/client.rb +2 -4
- data/lib/quick_travel/client_type.rb +2 -1
- data/lib/quick_travel/connection_error.rb +1 -1
- data/lib/quick_travel/constants.rb +0 -1
- data/lib/quick_travel/contact.rb +0 -1
- data/lib/quick_travel/country.rb +0 -3
- data/lib/quick_travel/document.rb +0 -2
- data/lib/quick_travel/document_group.rb +0 -2
- data/lib/quick_travel/location.rb +0 -2
- data/lib/quick_travel/party.rb +7 -12
- data/lib/quick_travel/passenger.rb +0 -1
- data/lib/quick_travel/passenger_price_break.rb +0 -2
- data/lib/quick_travel/passenger_type.rb +0 -2
- data/lib/quick_travel/payment.rb +0 -3
- data/lib/quick_travel/payment_type.rb +4 -13
- data/lib/quick_travel/price_changes.rb +3 -0
- data/lib/quick_travel/price_changes/booking_price_change.rb +30 -0
- data/lib/quick_travel/price_changes/price_change.rb +23 -0
- data/lib/quick_travel/{discounts/discount_tree.rb → price_changes/price_change_tree.rb} +12 -8
- data/lib/quick_travel/product.rb +15 -28
- data/lib/quick_travel/product_type.rb +4 -16
- data/lib/quick_travel/property.rb +4 -20
- data/lib/quick_travel/property_facility.rb +0 -1
- data/lib/quick_travel/property_type.rb +2 -14
- data/lib/quick_travel/region.rb +0 -9
- data/lib/quick_travel/reservation.rb +0 -21
- data/lib/quick_travel/resource.rb +7 -28
- data/lib/quick_travel/room_facility.rb +0 -1
- data/lib/quick_travel/route.rb +9 -25
- data/lib/quick_travel/route_stop.rb +0 -1
- data/lib/quick_travel/service.rb +2 -1
- data/lib/quick_travel/status.rb +23 -0
- data/lib/quick_travel/trip.rb +0 -1
- data/lib/quick_travel/vehicle.rb +2 -4
- data/lib/quick_travel/vehicle_type.rb +0 -3
- data/lib/quick_travel/version.rb +1 -1
- data/quicktravel_client.gemspec +4 -4
- data/spec/booking_spec.rb +24 -0
- data/spec/discounts_spec.rb +69 -69
- data/spec/passenger_type_spec.rb +30 -0
- data/spec/payment_type_spec.rb +10 -0
- data/spec/product_spec.rb +52 -21
- data/spec/product_type_spec.rb +19 -0
- data/spec/property_spec.rb +83 -0
- data/spec/region_spec.rb +1 -1
- data/spec/reservation_spec.rb +3 -2
- data/spec/resource_spec.rb +31 -7
- data/spec/route_spec.rb +118 -0
- data/spec/spec_helper.rb +18 -25
- data/spec/status_spec.rb +9 -0
- data/spec/support/cassettes/booking_create.yml +39 -33
- data/spec/support/cassettes/booking_documents.yml +36 -30
- data/spec/support/cassettes/booking_price_changes.yml +66 -0
- data/spec/support/cassettes/booking_show.yml +38 -32
- data/spec/support/cassettes/booking_update.yml +74 -62
- data/spec/support/cassettes/booking_with_documents.yml +88 -76
- data/spec/support/cassettes/booking_with_nested_attributes.yml +128 -110
- data/spec/support/cassettes/booking_with_price_changes.yml +86 -0
- data/spec/support/cassettes/countries.yml +140 -0
- data/spec/support/cassettes/country_all.yml +36 -30
- data/spec/support/cassettes/create_reservation_fail.yml +32 -27
- data/spec/support/cassettes/create_reservation_with_booking.yml +40 -34
- data/spec/support/cassettes/passenger_all.yml +36 -30
- data/spec/support/cassettes/payment_info.yml +61 -0
- data/spec/support/cassettes/product_date_range_bookability.yml +61 -59
- data/spec/support/cassettes/product_show.yml +42 -32
- data/spec/support/cassettes/product_show_as_agent.yml +63 -0
- data/spec/support/cassettes/product_type_all.yml +53 -0
- data/spec/support/cassettes/property.yml +66 -0
- data/spec/support/cassettes/region_show.yml +36 -30
- data/spec/support/cassettes/reservation_with_extra_picks.yml +137 -110
- data/spec/support/cassettes/resource_fare_bases.yml +47 -78
- data/spec/support/cassettes/resource_product_type.yml +63 -0
- data/spec/support/cassettes/resource_show.yml +37 -31
- data/spec/support/cassettes/resource_with_price.yml +63 -0
- data/spec/support/cassettes/route_all.yml +65 -0
- data/spec/support/cassettes/tenant_switcher.yml +109 -0
- data/spec/support/coverage_loader.rb +26 -0
- data/spec/tenant_spec.rb +28 -0
- metadata +106 -115
- data/bootstrap/boot.rb +0 -4
- data/lib/quick_travel/discounts.rb +0 -3
- data/lib/quick_travel/discounts/booking_discount.rb +0 -18
- data/lib/quick_travel/discounts/discount.rb +0 -21
- data/spec/support/cassettes/booking_create_legacy.yml +0 -50
- data/spec/support/cassettes/booking_discounts.yml +0 -53
- data/spec/support/cassettes/booking_with_discounts.yml +0 -72
- data/spec/support/cassettes/region_index.yml +0 -48
data/lib/quick_travel/booking.rb
CHANGED
@@ -3,24 +3,10 @@ require 'quick_travel/passenger'
|
|
3
3
|
require 'quick_travel/vehicle'
|
4
4
|
require 'quick_travel/payment'
|
5
5
|
require 'quick_travel/payment_type'
|
6
|
-
require 'quick_travel/
|
6
|
+
require 'quick_travel/price_changes'
|
7
7
|
|
8
8
|
module QuickTravel
|
9
9
|
class Booking < Adapter
|
10
|
-
attr_accessor :reference, :state, :client_id, :first_travel_date, :created_at, :access_token
|
11
|
-
attr_accessor :gross_in_cents, :commission_in_cents, :cost_in_cents, :balance_in_cents, :paid_in_cents, :surcharge_in_cents
|
12
|
-
attr_accessor :deposit_in_cents, :deposit_due_on, :deposit_relevant
|
13
|
-
|
14
|
-
attr_accessor :id # booking_id. I am initializing this data member when we create booking.
|
15
|
-
attr_accessor :client_address, :client_party, :client_contact,
|
16
|
-
:customer_contact_name, :customer_contact_phone, :customer_contact_mobile, :customer_contact_email,
|
17
|
-
:post_code, :country_id, :referral_code_id,
|
18
|
-
:discardable_in, :inactivatable_in,
|
19
|
-
:promo_code, :web_site_name,
|
20
|
-
:insurance_offered, :public_comments
|
21
|
-
|
22
|
-
money :gross, :balance, :commission, :paid, :surcharge, :deposit
|
23
|
-
|
24
10
|
def self.api_base
|
25
11
|
'/api/bookings'
|
26
12
|
end
|
@@ -55,15 +41,7 @@ module QuickTravel
|
|
55
41
|
end
|
56
42
|
|
57
43
|
def country
|
58
|
-
Country.find(@country_id)
|
59
|
-
end
|
60
|
-
|
61
|
-
def deposit_due_on
|
62
|
-
@deposit_due_on_parsed ||= parse_date(@deposit_due_on)
|
63
|
-
end
|
64
|
-
|
65
|
-
def balance_due_on
|
66
|
-
@balance_due_on_parsed ||= parse_date(@balance_due_on)
|
44
|
+
Country.find(@country_id) if @country_id
|
67
45
|
end
|
68
46
|
|
69
47
|
# Create an empty booking
|
@@ -83,7 +61,7 @@ module QuickTravel
|
|
83
61
|
options = { booking: default_options.merge(options) }
|
84
62
|
|
85
63
|
response = post_and_validate("#{api_base}.json", options)
|
86
|
-
fail
|
64
|
+
fail AdapterError.new(response) unless response['id']
|
87
65
|
|
88
66
|
return nil unless response['id']
|
89
67
|
Booking.new(response)
|
@@ -93,7 +71,7 @@ module QuickTravel
|
|
93
71
|
def update(options = {})
|
94
72
|
response = put_and_validate("#{api_base}/#{@id}.json", booking: options)
|
95
73
|
# id is returned if other attributes change otherwise success: true
|
96
|
-
fail
|
74
|
+
fail AdapterError.new(response) unless response['id'] || response['success']
|
97
75
|
|
98
76
|
Booking.find(@id)
|
99
77
|
end
|
@@ -108,7 +86,7 @@ module QuickTravel
|
|
108
86
|
def update_with_nested_attributes!(booking_args = {})
|
109
87
|
response = put_and_validate("#{api_base}/#{@id}/update_with_nested_attributes.json",
|
110
88
|
booking: booking_args)
|
111
|
-
fail
|
89
|
+
fail AdapterError.new(response) unless response['id']
|
112
90
|
Booking.find(response['id'])
|
113
91
|
end
|
114
92
|
|
@@ -142,7 +120,7 @@ module QuickTravel
|
|
142
120
|
# }
|
143
121
|
def accommodation_reserve(reservations_options = {})
|
144
122
|
if reservations_options[:last_travel_date].nil?
|
145
|
-
fail
|
123
|
+
fail AdapterError.new('No checkout date specified')
|
146
124
|
end
|
147
125
|
|
148
126
|
last_travel_date = Date.strptime(reservations_options[:last_travel_date], '%d/%m/%Y')
|
@@ -203,7 +181,7 @@ module QuickTravel
|
|
203
181
|
|
204
182
|
def delete_reservation_by_id(reservation_id)
|
205
183
|
if state != 'new'
|
206
|
-
fail
|
184
|
+
fail AdapterError.new('Reservation cannot be deleted unless the booking is new')
|
207
185
|
end
|
208
186
|
|
209
187
|
delete_and_validate("#{api_base}/#{@id}/reservations/#{reservation_id}.json")
|
@@ -247,7 +225,7 @@ module QuickTravel
|
|
247
225
|
# It returns booking items for a booking.
|
248
226
|
# Array of BookingItem
|
249
227
|
def reservations
|
250
|
-
fail
|
228
|
+
fail AdapterError, 'Reservations have not been set from API' if @reservations_attributes.nil?
|
251
229
|
@_reservations_object_array ||= @reservations_attributes.map { |item| Reservation.new(item) }
|
252
230
|
end
|
253
231
|
|
@@ -256,18 +234,22 @@ module QuickTravel
|
|
256
234
|
end
|
257
235
|
|
258
236
|
def client_address
|
237
|
+
return nil unless @client_address
|
259
238
|
@client_address_object ||= Address.new(@client_address)
|
260
239
|
end
|
261
240
|
|
262
241
|
def client_party
|
242
|
+
return nil unless @client_party
|
263
243
|
@client_party_object ||= Party.new(@client_party)
|
264
244
|
end
|
265
245
|
|
266
246
|
def client_contact
|
247
|
+
return nil unless @client_contact
|
267
248
|
@client_contact_object ||= Contact.new(@client_contact)
|
268
249
|
end
|
269
250
|
|
270
251
|
def client
|
252
|
+
return nil unless @client
|
271
253
|
@client_object ||= Client.new(@client)
|
272
254
|
end
|
273
255
|
|
@@ -314,20 +296,19 @@ module QuickTravel
|
|
314
296
|
(balance_in_cents == 0 && state != 'new' && !reservations.empty?) || state == 'quote'
|
315
297
|
end
|
316
298
|
|
317
|
-
def
|
318
|
-
@
|
299
|
+
def price_change
|
300
|
+
@price_change ||= fetch_price_change
|
319
301
|
end
|
320
302
|
|
321
|
-
def
|
322
|
-
|
303
|
+
def price_change_on(reservation)
|
304
|
+
price_change.price_change_on(reservation.id)
|
323
305
|
end
|
324
306
|
|
325
|
-
def
|
326
|
-
|
307
|
+
def total_price_change_on(reservation)
|
308
|
+
price_change.total_price_change_on(reservation.id)
|
327
309
|
end
|
328
310
|
|
329
|
-
def calculate_price_quote(
|
330
|
-
params = segments.merge(segments: segments.keys)
|
311
|
+
def calculate_price_quote(params = {})
|
331
312
|
response = post_and_validate("#{api_base}/#{@id}/price_quotes/calculate", params)
|
332
313
|
Money.new(response['quoted_booking_gross_in_cents'])
|
333
314
|
end
|
@@ -357,14 +338,9 @@ module QuickTravel
|
|
357
338
|
|
358
339
|
private
|
359
340
|
|
360
|
-
def
|
361
|
-
|
362
|
-
|
363
|
-
end
|
364
|
-
|
365
|
-
def fetch_discount
|
366
|
-
attributes = get_and_validate("#{api_base}/#{@id}/discount.json")
|
367
|
-
QuickTravel::Discounts::BookingDiscount.new(attributes)
|
341
|
+
def fetch_price_change
|
342
|
+
attributes = get_and_validate("#{api_base}/#{@id}/price_change.json")
|
343
|
+
QuickTravel::PriceChanges::BookingPriceChange.new(attributes)
|
368
344
|
end
|
369
345
|
end
|
370
346
|
end
|
data/lib/quick_travel/cache.rb
CHANGED
@@ -13,26 +13,20 @@ module QuickTravel
|
|
13
13
|
yield.tap { |value| cache_store.write(key, value, cache_options) }
|
14
14
|
end
|
15
15
|
|
16
|
-
def self.
|
17
|
-
|
16
|
+
def self.delete(key)
|
17
|
+
cache_store.delete(key)
|
18
18
|
end
|
19
19
|
|
20
|
-
def self.
|
21
|
-
|
20
|
+
def self.clear
|
21
|
+
cache_store.clear
|
22
22
|
end
|
23
|
-
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
@store = {}
|
28
|
-
end
|
29
|
-
|
30
|
-
def write(key, value)
|
31
|
-
@store[key] = value
|
24
|
+
def self.cache_store
|
25
|
+
@@cache_store
|
32
26
|
end
|
33
27
|
|
34
|
-
def
|
35
|
-
|
28
|
+
def self.cache_store=(store)
|
29
|
+
@@cache_store = store
|
36
30
|
end
|
37
31
|
end
|
38
32
|
end
|
data/lib/quick_travel/client.rb
CHANGED
data/lib/quick_travel/contact.rb
CHANGED
data/lib/quick_travel/country.rb
CHANGED
data/lib/quick_travel/party.rb
CHANGED
@@ -2,20 +2,13 @@ module QuickTravel
|
|
2
2
|
class Party < Adapter
|
3
3
|
LOGIN_URL = '/login.json'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
attr_accessor :client_id, :vendor_id
|
8
|
-
attr_accessor :surchargeable
|
9
|
-
attr_accessor :client_type_id, :client_type_name, :client_type_is_agent
|
10
|
-
attr_accessor :default_web_user, :rights
|
11
|
-
|
12
|
-
attr_accessor :phone, :mobile, :email # if has a contact
|
13
|
-
attr_accessor :post_code, :country_id # if has an address
|
5
|
+
attr_reader :phone, :mobile, :email # if has a contact
|
6
|
+
attr_reader :post_code, :country_id # if has an address
|
14
7
|
|
15
8
|
def initialize(hash = {})
|
16
9
|
super
|
17
10
|
if type.blank?
|
18
|
-
|
11
|
+
@type = 'Person'
|
19
12
|
end
|
20
13
|
end
|
21
14
|
|
@@ -30,7 +23,9 @@ module QuickTravel
|
|
30
23
|
# @returns: Party: Valid Credentials
|
31
24
|
# Nil: Invalid Credentialss
|
32
25
|
def self.login(options = { login: nil, password: nil })
|
33
|
-
|
26
|
+
unless options[:login] && options[:password]
|
27
|
+
fail ArgumentError, 'You must specify :login and :password'
|
28
|
+
end
|
34
29
|
response = post_and_validate(LOGIN_URL, options)
|
35
30
|
Party.new(response) unless response[:error]
|
36
31
|
end
|
@@ -42,7 +37,7 @@ module QuickTravel
|
|
42
37
|
|
43
38
|
def self.set_password_via_token(token, password)
|
44
39
|
post_and_validate('/sessions/set_password_via_token', token: token, password: password)
|
45
|
-
rescue QuickTravel::
|
40
|
+
rescue QuickTravel::AdapterError => e
|
46
41
|
{ error: e.message }
|
47
42
|
end
|
48
43
|
end
|
data/lib/quick_travel/payment.rb
CHANGED
@@ -3,9 +3,6 @@ require 'quick_travel/credit_card'
|
|
3
3
|
|
4
4
|
module QuickTravel
|
5
5
|
class Payment < Adapter
|
6
|
-
attr_accessor :id, :payment_type_id, :amount_in_cents, :authorization, :success, :created_at
|
7
|
-
money :amount
|
8
|
-
|
9
6
|
def payment_type
|
10
7
|
QuickTravel::PaymentType.find(@payment_type_id)
|
11
8
|
end
|
@@ -3,19 +3,6 @@ require 'quick_travel/cache'
|
|
3
3
|
|
4
4
|
module QuickTravel
|
5
5
|
class PaymentType < Adapter
|
6
|
-
attr_accessor :id,
|
7
|
-
:name,
|
8
|
-
:description,
|
9
|
-
:position,
|
10
|
-
:active,
|
11
|
-
:payment_method,
|
12
|
-
:for_frequent_traveller_redemption,
|
13
|
-
:notes,
|
14
|
-
:surchargeable,
|
15
|
-
:transaction_fee,
|
16
|
-
:redirect,
|
17
|
-
:credit_card_brand
|
18
|
-
|
19
6
|
self.api_base = '/payment_types'
|
20
7
|
self.lookup = true
|
21
8
|
|
@@ -34,5 +21,9 @@ module QuickTravel
|
|
34
21
|
def as_json(options = nil)
|
35
22
|
super.merge(code: code)
|
36
23
|
end
|
24
|
+
|
25
|
+
def self.information
|
26
|
+
get_and_validate('/api/payment_types/information.json')
|
27
|
+
end
|
37
28
|
end
|
38
29
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module QuickTravel
|
2
|
+
module PriceChanges
|
3
|
+
class BookingPriceChange < PriceChangeTree
|
4
|
+
def initialize(attrs = {})
|
5
|
+
super(
|
6
|
+
attrs.merge(
|
7
|
+
'root' => attrs,
|
8
|
+
'children' => attrs['reservation_price_changes']
|
9
|
+
)
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
def reservation_price_changes
|
14
|
+
@children
|
15
|
+
end
|
16
|
+
|
17
|
+
def discounts
|
18
|
+
price_changes.select(&:negative?)
|
19
|
+
end
|
20
|
+
|
21
|
+
def surcharges
|
22
|
+
price_changes.select(&:positive?)
|
23
|
+
end
|
24
|
+
|
25
|
+
def price_changes
|
26
|
+
@children.flat_map(&:roots)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|