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.
Files changed (108) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +14 -2
  5. data/CHANGELOG.md +34 -3
  6. data/Gemfile +0 -3
  7. data/Rakefile +0 -6
  8. data/examples/login_example.rb +1 -1
  9. data/gemfiles/rails4.gemfile +9 -0
  10. data/lib/quick_travel.rb +2 -1
  11. data/lib/quick_travel/accommodation.rb +1 -15
  12. data/lib/quick_travel/adapter.rb +98 -67
  13. data/lib/quick_travel/{adapter_exception.rb → adapter_error.rb} +1 -1
  14. data/lib/quick_travel/address.rb +2 -7
  15. data/lib/quick_travel/adjustment.rb +0 -2
  16. data/lib/quick_travel/bed_configuration.rb +0 -1
  17. data/lib/quick_travel/bed_requirement.rb +0 -1
  18. data/lib/quick_travel/booking.rb +22 -46
  19. data/lib/quick_travel/cache.rb +8 -14
  20. data/lib/quick_travel/checkout.rb +1 -1
  21. data/lib/quick_travel/client.rb +2 -4
  22. data/lib/quick_travel/client_type.rb +2 -1
  23. data/lib/quick_travel/connection_error.rb +1 -1
  24. data/lib/quick_travel/constants.rb +0 -1
  25. data/lib/quick_travel/contact.rb +0 -1
  26. data/lib/quick_travel/country.rb +0 -3
  27. data/lib/quick_travel/document.rb +0 -2
  28. data/lib/quick_travel/document_group.rb +0 -2
  29. data/lib/quick_travel/location.rb +0 -2
  30. data/lib/quick_travel/party.rb +7 -12
  31. data/lib/quick_travel/passenger.rb +0 -1
  32. data/lib/quick_travel/passenger_price_break.rb +0 -2
  33. data/lib/quick_travel/passenger_type.rb +0 -2
  34. data/lib/quick_travel/payment.rb +0 -3
  35. data/lib/quick_travel/payment_type.rb +4 -13
  36. data/lib/quick_travel/price_changes.rb +3 -0
  37. data/lib/quick_travel/price_changes/booking_price_change.rb +30 -0
  38. data/lib/quick_travel/price_changes/price_change.rb +23 -0
  39. data/lib/quick_travel/{discounts/discount_tree.rb → price_changes/price_change_tree.rb} +12 -8
  40. data/lib/quick_travel/product.rb +15 -28
  41. data/lib/quick_travel/product_type.rb +4 -16
  42. data/lib/quick_travel/property.rb +4 -20
  43. data/lib/quick_travel/property_facility.rb +0 -1
  44. data/lib/quick_travel/property_type.rb +2 -14
  45. data/lib/quick_travel/region.rb +0 -9
  46. data/lib/quick_travel/reservation.rb +0 -21
  47. data/lib/quick_travel/resource.rb +7 -28
  48. data/lib/quick_travel/room_facility.rb +0 -1
  49. data/lib/quick_travel/route.rb +9 -25
  50. data/lib/quick_travel/route_stop.rb +0 -1
  51. data/lib/quick_travel/service.rb +2 -1
  52. data/lib/quick_travel/status.rb +23 -0
  53. data/lib/quick_travel/trip.rb +0 -1
  54. data/lib/quick_travel/vehicle.rb +2 -4
  55. data/lib/quick_travel/vehicle_type.rb +0 -3
  56. data/lib/quick_travel/version.rb +1 -1
  57. data/quicktravel_client.gemspec +4 -4
  58. data/spec/booking_spec.rb +24 -0
  59. data/spec/discounts_spec.rb +69 -69
  60. data/spec/passenger_type_spec.rb +30 -0
  61. data/spec/payment_type_spec.rb +10 -0
  62. data/spec/product_spec.rb +52 -21
  63. data/spec/product_type_spec.rb +19 -0
  64. data/spec/property_spec.rb +83 -0
  65. data/spec/region_spec.rb +1 -1
  66. data/spec/reservation_spec.rb +3 -2
  67. data/spec/resource_spec.rb +31 -7
  68. data/spec/route_spec.rb +118 -0
  69. data/spec/spec_helper.rb +18 -25
  70. data/spec/status_spec.rb +9 -0
  71. data/spec/support/cassettes/booking_create.yml +39 -33
  72. data/spec/support/cassettes/booking_documents.yml +36 -30
  73. data/spec/support/cassettes/booking_price_changes.yml +66 -0
  74. data/spec/support/cassettes/booking_show.yml +38 -32
  75. data/spec/support/cassettes/booking_update.yml +74 -62
  76. data/spec/support/cassettes/booking_with_documents.yml +88 -76
  77. data/spec/support/cassettes/booking_with_nested_attributes.yml +128 -110
  78. data/spec/support/cassettes/booking_with_price_changes.yml +86 -0
  79. data/spec/support/cassettes/countries.yml +140 -0
  80. data/spec/support/cassettes/country_all.yml +36 -30
  81. data/spec/support/cassettes/create_reservation_fail.yml +32 -27
  82. data/spec/support/cassettes/create_reservation_with_booking.yml +40 -34
  83. data/spec/support/cassettes/passenger_all.yml +36 -30
  84. data/spec/support/cassettes/payment_info.yml +61 -0
  85. data/spec/support/cassettes/product_date_range_bookability.yml +61 -59
  86. data/spec/support/cassettes/product_show.yml +42 -32
  87. data/spec/support/cassettes/product_show_as_agent.yml +63 -0
  88. data/spec/support/cassettes/product_type_all.yml +53 -0
  89. data/spec/support/cassettes/property.yml +66 -0
  90. data/spec/support/cassettes/region_show.yml +36 -30
  91. data/spec/support/cassettes/reservation_with_extra_picks.yml +137 -110
  92. data/spec/support/cassettes/resource_fare_bases.yml +47 -78
  93. data/spec/support/cassettes/resource_product_type.yml +63 -0
  94. data/spec/support/cassettes/resource_show.yml +37 -31
  95. data/spec/support/cassettes/resource_with_price.yml +63 -0
  96. data/spec/support/cassettes/route_all.yml +65 -0
  97. data/spec/support/cassettes/tenant_switcher.yml +109 -0
  98. data/spec/support/coverage_loader.rb +26 -0
  99. data/spec/tenant_spec.rb +28 -0
  100. metadata +106 -115
  101. data/bootstrap/boot.rb +0 -4
  102. data/lib/quick_travel/discounts.rb +0 -3
  103. data/lib/quick_travel/discounts/booking_discount.rb +0 -18
  104. data/lib/quick_travel/discounts/discount.rb +0 -21
  105. data/spec/support/cassettes/booking_create_legacy.yml +0 -50
  106. data/spec/support/cassettes/booking_discounts.yml +0 -53
  107. data/spec/support/cassettes/booking_with_discounts.yml +0 -72
  108. data/spec/support/cassettes/region_index.yml +0 -48
@@ -2,7 +2,5 @@ require 'quick_travel/adapter'
2
2
 
3
3
  module QuickTravel
4
4
  class Adjustment < Adapter
5
- attr_accessor :id, :description, :gross_in_cents
6
- money :gross
7
5
  end
8
6
  end
@@ -2,6 +2,5 @@ require 'quick_travel/adapter'
2
2
 
3
3
  module QuickTravel
4
4
  class BedConfiguration < Adapter
5
- attr_accessor :created_at, :creator_id, :id, :name, :overriding_fare_basis_pointer_id, :resource_id, :updated_at, :updator_id
6
5
  end
7
6
  end
@@ -2,6 +2,5 @@ require 'quick_travel/adapter'
2
2
 
3
3
  module QuickTravel
4
4
  class BedRequirement < Adapter
5
- attr_accessor :id, :name, :single_bed_count, :double_bed_count
6
5
  end
7
6
  end
@@ -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/discounts'
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 AdapterException.new(response) unless response['id']
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 AdapterException.new(response) unless response['id'] || response['success']
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 AdapterException.new(response) unless response['id']
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 AdapterException.new('No checkout date specified')
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 AdapterException.new('Reservation cannot be deleted unless the booking is new')
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 AdapterException, 'Reservations have not been set from API' if @reservations_attributes.nil?
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 discount
318
- @discount ||= fetch_discount
299
+ def price_change
300
+ @price_change ||= fetch_price_change
319
301
  end
320
302
 
321
- def discount_on(reservation)
322
- discount.discount_on(reservation.id)
303
+ def price_change_on(reservation)
304
+ price_change.price_change_on(reservation.id)
323
305
  end
324
306
 
325
- def total_discount_on(reservation)
326
- discount.total_discount_on(reservation.id)
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(segments = {})
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 parse_date(hash)
361
- return if hash.blank? || hash['_value'].blank?
362
- hash['_value'].to_date
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
@@ -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.cache_store
17
- @@cache_store
16
+ def self.delete(key)
17
+ cache_store.delete(key)
18
18
  end
19
19
 
20
- def self.cache_store=(store)
21
- @@cache_store = store
20
+ def self.clear
21
+ cache_store.clear
22
22
  end
23
- end
24
23
 
25
- class DefaultCacheStore
26
- def initialize
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 read(key)
35
- @store[key]
28
+ def self.cache_store=(store)
29
+ @@cache_store = store
36
30
  end
37
31
  end
38
32
  end
@@ -45,7 +45,7 @@ module QuickTravel
45
45
  attrs[:completed] = (attrs['progress'] == 'completed')
46
46
  attrs[:successful] = attrs[:completed]
47
47
  attrs
48
- rescue AdapterException => e
48
+ rescue AdapterError => e
49
49
  {
50
50
  completed: true,
51
51
  successful: false,
@@ -1,8 +1,6 @@
1
+ require 'quick_travel/adapter'
2
+
1
3
  module QuickTravel
2
4
  class Client < Adapter
3
- attr_accessor :id, :party_id, :surchargeless, :client_type,
4
- :contact_phone, :contact_mobile, :contact_email,
5
- :name,
6
- :first_name, :last_name
7
5
  end
8
6
  end
@@ -1,6 +1,7 @@
1
+ require 'quick_travel/adapter'
2
+
1
3
  module QuickTravel
2
4
  class ClientType < Adapter
3
- attr_accessor :id, :name, :agent, :position, :right_id
4
5
  self.api_base = '/client_types'
5
6
  end
6
7
  end
@@ -1,5 +1,5 @@
1
1
  module QuickTravel
2
- class ConnectionError < Exception
2
+ class ConnectionError < StandardError
3
3
  attr_reader :original
4
4
  def initialize(msg, original = $ERROR_INFO)
5
5
  super(msg)
@@ -9,7 +9,6 @@ module QuickTravel
9
9
 
10
10
  # System wide
11
11
  PROPERTY_CACHE_TIMEOUT = 1440 # minutes
12
- AUSTRALIA_COUNTRY_ID = 14
13
12
  QT_DATE_FORMAT = '%d-%m-%Y'
14
13
 
15
14
  DEFAULT_REFERRAL_CODE_ID = 33
@@ -1,5 +1,4 @@
1
1
  module QuickTravel
2
2
  class Contact < Adapter
3
- attr_accessor :phone, :email, :id
4
3
  end
5
4
  end
@@ -1,10 +1,7 @@
1
1
  require 'quick_travel/adapter'
2
- require 'quick_travel/cache'
3
2
 
4
3
  module QuickTravel
5
4
  class Country < Adapter
6
- attr_accessor :id, :iso_3166_code, :name, :latitude, :longitude
7
-
8
5
  self.api_base = '/api/countries'
9
6
  self.lookup = true
10
7
  end
@@ -2,8 +2,6 @@ require 'quick_travel/adapter'
2
2
 
3
3
  module QuickTravel
4
4
  class Document < Adapter
5
- attr_accessor :id, :booking_id, :name
6
-
7
5
  self.api_base = "/front_office/bookings/#{@booking_id}/documents"
8
6
 
9
7
  # We used to direct the browser to QT directly
@@ -3,8 +3,6 @@ require 'quick_travel/encrypt'
3
3
 
4
4
  module QuickTravel
5
5
  class DocumentGroup < Adapter
6
- attr_accessor :id, :booking_id
7
-
8
6
  self.api_base = "/front_office/bookings/#{@booking_id}/document_groups"
9
7
 
10
8
  def pdf_url
@@ -2,8 +2,6 @@ require 'quick_travel/adapter'
2
2
 
3
3
  module QuickTravel
4
4
  class Location < Adapter
5
- attr_accessor :id, :name, :region_ids
6
-
7
5
  self.api_base = '/locations'
8
6
  self.lookup = true
9
7
 
@@ -2,20 +2,13 @@ module QuickTravel
2
2
  class Party < Adapter
3
3
  LOGIN_URL = '/login.json'
4
4
 
5
- attr_accessor :id, :type, :name, :login, :title, :first_name, :last_name, :gender, :active, :internal_staff, :display_name
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
- self.type = 'Person'
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
- fail 'You must specify :login and :password' unless options[:login] && options[:password]
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::AdapterException => e
40
+ rescue QuickTravel::AdapterError => e
46
41
  { error: e.message }
47
42
  end
48
43
  end
@@ -2,6 +2,5 @@ require 'quick_travel/adapter'
2
2
 
3
3
  module QuickTravel
4
4
  class Passenger < Adapter
5
- attr_accessor :id, :passenger_type_id, :age, :gender, :title, :first_name, :last_name, :details, :passenger_type_name
6
5
  end
7
6
  end
@@ -2,7 +2,5 @@ require 'quick_travel/adapter'
2
2
 
3
3
  module QuickTravel
4
4
  class PassengerPriceBreak < Adapter
5
- attr_accessor :amount_in_cents
6
- money :amount
7
5
  end
8
6
  end
@@ -2,8 +2,6 @@ require 'quick_travel/adapter'
2
2
 
3
3
  module QuickTravel
4
4
  class PassengerType < Adapter
5
- attr_accessor :age_range_required, :default_age, :id, :maximum_age, :minimum_age, :name, :position, :code
6
-
7
5
  self.api_base = '/passenger_types'
8
6
  self.lookup = true
9
7
 
@@ -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,3 @@
1
+ require 'quick_travel/price_changes/price_change'
2
+ require 'quick_travel/price_changes/price_change_tree'
3
+ require 'quick_travel/price_changes/booking_price_change'
@@ -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