quicktravel_client 3.6.1 → 4.0.0
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 +5 -5
- data/.ruby-version +1 -1
- data/.travis.yml +6 -3
- data/CHANGELOG.md +36 -3
- data/README.md +1 -1
- data/gemfiles/rails6.gemfile +8 -0
- data/lib/quick_travel.rb +4 -0
- data/lib/quick_travel/adapter.rb +19 -81
- data/lib/quick_travel/address.rb +4 -2
- data/lib/quick_travel/adjustment.rb +3 -2
- data/lib/quick_travel/background_check.rb +4 -2
- data/lib/quick_travel/bed_configuration.rb +3 -2
- data/lib/quick_travel/bed_requirement.rb +3 -2
- data/lib/quick_travel/booking.rb +11 -1
- data/lib/quick_travel/cache.rb +24 -5
- data/lib/quick_travel/checkout.rb +1 -1
- data/lib/quick_travel/client.rb +9 -0
- data/lib/quick_travel/contact.rb +4 -1
- data/lib/quick_travel/init_from_hash.rb +58 -1
- data/lib/quick_travel/package.rb +13 -0
- data/lib/quick_travel/passenger.rb +7 -2
- data/lib/quick_travel/passenger_price_break.rb +3 -2
- data/lib/quick_travel/passenger_split.rb +5 -0
- data/lib/quick_travel/passenger_type.rb +1 -1
- data/lib/quick_travel/product_configuration.rb +1 -1
- data/lib/quick_travel/products/base.rb +4 -4
- data/lib/quick_travel/property.rb +2 -1
- data/lib/quick_travel/property_facility.rb +3 -2
- data/lib/quick_travel/reservation.rb +5 -1
- data/lib/quick_travel/resource.rb +12 -3
- data/lib/quick_travel/resource_category.rb +5 -1
- data/lib/quick_travel/resource_group.rb +9 -0
- data/lib/quick_travel/room_facility.rb +3 -2
- data/lib/quick_travel/route.rb +1 -1
- data/lib/quick_travel/route_stop.rb +18 -2
- data/lib/quick_travel/service.rb +3 -2
- data/lib/quick_travel/version.rb +1 -1
- data/quicktravel_client.gemspec +6 -5
- data/spec/adapter_spec.rb +36 -5
- data/spec/booking_spec.rb +24 -6
- data/spec/clients_spec.rb +42 -0
- data/spec/discounts_spec.rb +21 -21
- data/spec/package_spec.rb +24 -0
- data/spec/passenger_type_spec.rb +1 -1
- data/spec/product_configuration_spec.rb +11 -0
- data/spec/product_spec.rb +5 -5
- data/spec/region_spec.rb +2 -2
- data/spec/reservation_spec.rb +22 -6
- data/spec/spec_helper.rb +6 -3
- data/spec/support/cassettes/accommodation_reserve.yml +119 -53
- data/spec/support/cassettes/basic_product_scheduled_trips.yml +22 -34
- data/spec/support/cassettes/basic_product_scheduled_trips_multi_sector.yml +22 -28
- data/spec/support/cassettes/basic_product_scheduled_trips_unbookable.yml +12 -12
- data/spec/support/cassettes/booking_activate.yml +31 -30
- data/spec/support/cassettes/booking_cancel.yml +31 -30
- data/spec/support/cassettes/booking_create.yml +17 -16
- data/spec/support/cassettes/booking_create_accommodation.yml +64 -0
- data/spec/support/cassettes/booking_documents.yml +12 -12
- data/spec/support/cassettes/booking_non_existant.yml +11 -11
- data/spec/support/cassettes/booking_price_changes.yml +22 -18
- data/spec/support/cassettes/booking_show.yml +16 -15
- data/spec/support/cassettes/booking_update.yml +31 -29
- data/spec/support/cassettes/booking_with_comments.yml +119 -0
- data/spec/support/cassettes/booking_with_documents.yml +41 -38
- data/spec/support/cassettes/booking_with_nested_attributes.yml +70 -64
- data/spec/support/cassettes/booking_with_price_changes.yml +30 -27
- data/spec/support/cassettes/checkout_client_token.yml +14 -14
- data/spec/support/cassettes/client_templates.yml +120 -0
- data/spec/support/cassettes/countries.yml +18 -94
- data/spec/support/cassettes/country_all.yml +18 -94
- data/spec/support/cassettes/create_reservation_fail.yml +11 -11
- data/spec/support/cassettes/create_reservation_with_booking.yml +18 -17
- data/spec/support/cassettes/locations.yml +15 -15
- data/spec/support/cassettes/opal_modern_pay_failed_booking.yml +64 -0
- data/spec/support/cassettes/opal_modern_pay_failed_create.yml +61 -0
- data/spec/support/cassettes/opal_modern_pay_failed_update.yml +59 -0
- data/spec/support/cassettes/opal_modern_pay_successful_booking.yml +64 -0
- data/spec/support/cassettes/opal_modern_pay_successful_response.yml +61 -0
- data/spec/support/cassettes/opal_modern_pay_successful_update_response.yml +61 -0
- data/spec/support/cassettes/opal_pay.yml +61 -0
- data/spec/support/cassettes/opal_pay_booking.yml +64 -0
- data/spec/support/cassettes/package_show.yml +83 -0
- data/spec/support/cassettes/package_show_product_type.yml +80 -0
- data/spec/support/cassettes/passenger_all.yml +14 -14
- data/spec/support/cassettes/payment_info.yml +12 -12
- data/spec/support/cassettes/price_quote.yml +23 -23
- data/spec/support/cassettes/product_date_range_bookability.yml +35 -49
- data/spec/support/cassettes/product_show.yml +16 -18
- data/spec/support/cassettes/product_show_as_agent.yml +17 -23
- data/spec/support/cassettes/product_type_all.yml +19 -15
- data/spec/support/cassettes/product_type_resource_categories.yml +12 -12
- data/spec/support/cassettes/product_type_resource_categories_tickets.yml +15 -15
- data/spec/support/cassettes/product_type_routes.yml +17 -17
- data/spec/support/cassettes/property.yml +19 -19
- data/spec/support/cassettes/property_types.yml +15 -15
- data/spec/support/cassettes/region_show.yml +14 -14
- data/spec/support/cassettes/reservation_resource.yml +64 -0
- data/spec/support/cassettes/reservation_with_extra_picks.yml +63 -63
- data/spec/support/cassettes/resource_category_all.yml +15 -15
- data/spec/support/cassettes/resource_category_all_for_product_type_8.yml +14 -14
- data/spec/support/cassettes/resource_fare_bases.yml +21 -24
- data/spec/support/cassettes/resource_show.yml +18 -18
- data/spec/support/cassettes/resource_with_price.yml +19 -19
- data/spec/support/cassettes/settings_basic.yml +12 -12
- data/spec/support/cassettes/tenant_switcher.yml +37 -29
- data/spec/support/cassettes/wrong_url.yml +28 -47
- data/spec/support/coverage_loader.rb +1 -1
- metadata +69 -27
- data/gemfiles/rails4.gemfile +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5007469a12b06055c4cd7b9ae331a99ffc041952348ccad994ab11de51069e79
|
4
|
+
data.tar.gz: e57da3eb9ef8ff2f49283a9de910d5ffbb4c424f965f96fb8175d6ea452795e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24d5ba5f79aedf800a3fbd40c793a13dab2bfb48f91059460293aa757e5aea062f850b290e2b3b72e83c2269de5a675e9d5dfee761ef7555ba47aa3bc24f8928
|
7
|
+
data.tar.gz: ecb835442572758fe0b02d953bf978f2af920396396e7d9a6937917d5636fd8663e3ce0672fbcf39fed76652acdbb7dd4582f0c0bd19b3827123cb861df77081
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.7.1
|
data/.travis.yml
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.
|
4
|
-
- 2.
|
3
|
+
- 2.5
|
4
|
+
- 2.6
|
5
|
+
- 2.7
|
6
|
+
before_install:
|
7
|
+
- gem install bundler
|
5
8
|
script: bundle && bundle exec rake spec
|
6
9
|
gemfile:
|
7
|
-
- gemfiles/rails4.gemfile
|
8
10
|
- gemfiles/rails5.gemfile
|
11
|
+
- gemfiles/rails6.gemfile
|
9
12
|
notifications:
|
10
13
|
email:
|
11
14
|
- support@travellink.com.au
|
data/CHANGELOG.md
CHANGED
@@ -3,12 +3,45 @@ 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
|
-
## [
|
6
|
+
## [4.0.0]
|
7
|
+
- [TT-7385] Update Money dependency, test against Ruby 2.7 / Rails 6
|
7
8
|
|
8
|
-
## [3.
|
9
|
-
###
|
9
|
+
## [3.9.0]
|
10
|
+
### Added
|
11
|
+
- [DC-3115] Add customer comments method in booking
|
12
|
+
- [DC-2942] Add package class to support quantity based package
|
13
|
+
|
14
|
+
## [3.8.1]
|
15
|
+
### Changed
|
16
|
+
- [DC-3033] Reverse changes in checkout class to fix polipay redirection in EcomEngine
|
17
|
+
|
18
|
+
## [3.8.0]
|
19
|
+
### Added
|
20
|
+
- [DC-1794] Update httparty to allow caching the whole response, also add namespace to cache key
|
21
|
+
- [DC-1418] Port NRMA portal availability cache back to EcomEngine
|
22
|
+
- [TT-4850] Added client templates
|
23
|
+
- [DC-1692] Fix error that can be thrown when checking if a product configuration can be priced
|
24
|
+
- [TT-6246] Remove Booking.delete_reservations method
|
25
|
+
|
26
|
+
### Changed
|
27
|
+
- [DC-2997] Remove API key from body, and move it to header
|
28
|
+
- [DC-1767] include long/lat changes to Stop
|
29
|
+
|
30
|
+
## [3.7.0]
|
31
|
+
### Added
|
32
|
+
- [DC-1437] Add relationship accesssor methods
|
33
|
+
- [TT-3337] Add booking.delete_reservations method
|
34
|
+
- [TT-3780] Add tests for Opal payments
|
35
|
+
- [TT-3780] Add tests for Opal payment using create / update workflow
|
36
|
+
|
37
|
+
### Fixed
|
10
38
|
- [TT-3304] Handle no response in booking update API
|
11
39
|
|
40
|
+
### Changed
|
41
|
+
- [TT-3333] URL encode data sent to booking reference lookup
|
42
|
+
- [TT-3783] Remove deprecated FixNum
|
43
|
+
- [TT-3812] Update cassettes
|
44
|
+
|
12
45
|
## [3.6.0]
|
13
46
|
###
|
14
47
|
- [ROT-114] Add drop off details
|
data/README.md
CHANGED
@@ -27,4 +27,4 @@ bundle exec puma -Ilib -p7000
|
|
27
27
|
|
28
28
|
In QuickTravel Client:
|
29
29
|
rm spec/support/cassettes/ -rf
|
30
|
-
QT_KEYS=a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2,
|
30
|
+
QT_KEYS=a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2,1b0a9f8e7d6c5b4a3f2e1d0c9b8a7f6e5d4c3b2a1f0e9d8c7b6a5f4e3d2c1b0a bundle exec rspec
|
data/lib/quick_travel.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
#
|
3
3
|
module QuickTravel
|
4
4
|
require 'active_support' # for .try, etc.
|
5
|
+
require 'money_extensions'
|
5
6
|
|
6
7
|
require 'quick_travel/cache'
|
7
8
|
require 'quick_travel/config'
|
@@ -33,9 +34,11 @@ module QuickTravel
|
|
33
34
|
require 'quick_travel/drop_off_location'
|
34
35
|
require 'quick_travel/drop_off_option'
|
35
36
|
require 'quick_travel/location'
|
37
|
+
require 'quick_travel/package'
|
36
38
|
require 'quick_travel/party'
|
37
39
|
require 'quick_travel/passenger'
|
38
40
|
require 'quick_travel/passenger_type'
|
41
|
+
require 'quick_travel/passenger_split'
|
39
42
|
require 'quick_travel/payment'
|
40
43
|
require 'quick_travel/background_check'
|
41
44
|
require 'quick_travel/payment_type'
|
@@ -49,6 +52,7 @@ module QuickTravel
|
|
49
52
|
require 'quick_travel/reservation'
|
50
53
|
require 'quick_travel/resource'
|
51
54
|
require 'quick_travel/resource_category'
|
55
|
+
require 'quick_travel/resource_group'
|
52
56
|
require 'quick_travel/room_facility'
|
53
57
|
require 'quick_travel/route_stop'
|
54
58
|
require 'quick_travel/service'
|
data/lib/quick_travel/adapter.rb
CHANGED
@@ -25,27 +25,6 @@ module QuickTravel
|
|
25
25
|
# ]
|
26
26
|
class_attribute :object_key # Key of sub-objects (i.e. convert under a key)
|
27
27
|
|
28
|
-
def initialize(hash = {})
|
29
|
-
return nil if hash.blank?
|
30
|
-
define_readers(hash.keys)
|
31
|
-
super(Parser.new(hash).parsed_attributes)
|
32
|
-
end
|
33
|
-
|
34
|
-
def define_readers(keys)
|
35
|
-
keys.each do |key|
|
36
|
-
next if respond_to?(key)
|
37
|
-
define_singleton_method(key) { instance_variable_get("@#{key}") }
|
38
|
-
if key.to_s.ends_with? '_cents'
|
39
|
-
name = key.to_s.gsub(/_in_cents$/, '')
|
40
|
-
define_singleton_method(name) {
|
41
|
-
cents = instance_variable_get("@#{key}")
|
42
|
-
return nil unless cents
|
43
|
-
Money.new(cents)
|
44
|
-
}
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
28
|
def self.has_many(relation_name, options = {})
|
50
29
|
define_method relation_name do
|
51
30
|
instance_variable_get("@#{relation_name}") || instance_variable_set(
|
@@ -86,7 +65,7 @@ module QuickTravel
|
|
86
65
|
def self.all(opts = {})
|
87
66
|
if lookup
|
88
67
|
cache_name = ["#{name}.all-attrs", opts.to_param].reject(&:blank?).join('?')
|
89
|
-
find_all!("#{api_base}.json", opts.merge(
|
68
|
+
find_all!("#{api_base}.json", opts.merge(cache_key: cache_name, cache_options: { disable_namespacing: true }))
|
90
69
|
else
|
91
70
|
find_all!("#{api_base}.json", opts)
|
92
71
|
end
|
@@ -101,8 +80,12 @@ module QuickTravel
|
|
101
80
|
put_and_validate("#{api_base}/#{id}.json", options)
|
102
81
|
end
|
103
82
|
|
104
|
-
def
|
105
|
-
|
83
|
+
def to_s
|
84
|
+
if defined? @to_s
|
85
|
+
@to_s
|
86
|
+
else
|
87
|
+
super
|
88
|
+
end
|
106
89
|
end
|
107
90
|
|
108
91
|
protected
|
@@ -115,20 +98,14 @@ module QuickTravel
|
|
115
98
|
end
|
116
99
|
|
117
100
|
def self.find_all!(request_path, opts = {})
|
118
|
-
response =
|
119
|
-
|
120
|
-
|
121
|
-
}
|
122
|
-
else
|
123
|
-
get_and_validate(request_path, opts, return_response_object: true)
|
124
|
-
end
|
125
|
-
full_response = response.respond_to? :parsed_response
|
126
|
-
parsed_response = full_response ? response.parsed_response : response
|
101
|
+
response = QuickTravel::Cache.cache(opts[:cache_key], opts[:cache_options]) {
|
102
|
+
get_and_validate(request_path, opts.except(:cache_key, :cache_options), return_response_object: true)
|
103
|
+
}
|
127
104
|
|
128
|
-
deserializer = Deserializer.new(parsed_response)
|
105
|
+
deserializer = Deserializer.new(response.parsed_response)
|
129
106
|
objects = Array.wrap(deserializer.extract_under_root(self))
|
130
107
|
|
131
|
-
if
|
108
|
+
if response.headers['pagination'].present?
|
132
109
|
pagination_headers = ::JSON.parse(response.headers['pagination'])
|
133
110
|
WillPaginate::Collection.create(pagination_headers['current_page'], pagination_headers['per_page'], pagination_headers['total_entries']) do |pager|
|
134
111
|
pager.replace(objects)
|
@@ -215,7 +192,11 @@ module QuickTravel
|
|
215
192
|
end
|
216
193
|
|
217
194
|
def self.call_and_validate(http_method, path, query = {}, opts = {})
|
218
|
-
|
195
|
+
response = QuickTravel::Cache.cache(opts[:cache_key], opts[:cache_options]) {
|
196
|
+
response_object = Api.call_and_validate(http_method, path, query, opts.except(:cache_key, :cache_options))
|
197
|
+
response_object = response_object.parsed_response if !opts[:cache_key] and !opts[:return_response_object]
|
198
|
+
response_object
|
199
|
+
}
|
219
200
|
end
|
220
201
|
|
221
202
|
def self.base_uri(uri = nil)
|
@@ -223,54 +204,16 @@ module QuickTravel
|
|
223
204
|
end
|
224
205
|
end
|
225
206
|
|
226
|
-
class Parser
|
227
|
-
def initialize(attributes)
|
228
|
-
@attributes = attributes
|
229
|
-
end
|
230
|
-
|
231
|
-
def attributes
|
232
|
-
@attributes ||= {}
|
233
|
-
end
|
234
|
-
|
235
|
-
def parsed_attributes
|
236
|
-
@parsed_attributes ||= parse_attributes
|
237
|
-
end
|
238
|
-
|
239
|
-
private
|
240
|
-
|
241
|
-
def parse_attributes
|
242
|
-
attributes.map.with_object({}) do |(attribute, value), hash|
|
243
|
-
hash[attribute] = parse(attribute, value)
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
def parse(attribute, value)
|
248
|
-
return nil if value.nil?
|
249
|
-
return convert(value, :to_date) if attribute.to_s.ends_with?('_date')
|
250
|
-
return convert(value, :to_date) if attribute.to_s.ends_with?('_on')
|
251
|
-
# to_datetime as it converts to app time zone, to_time converts to system time zone
|
252
|
-
return convert(value, :to_datetime) if attribute.to_s.ends_with?('_time')
|
253
|
-
return convert(value, :to_datetime) if attribute.to_s.ends_with?('_at')
|
254
|
-
value
|
255
|
-
end
|
256
|
-
|
257
|
-
def convert(value, conversion_method)
|
258
|
-
convertable_value = value.is_a?(Hash) ? value['_value'] : value
|
259
|
-
convertable_value.send(conversion_method)
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
207
|
class Api
|
264
208
|
include HTTParty
|
265
209
|
|
266
210
|
def self.call_and_validate(http_method, path, query = {}, opts = {})
|
267
211
|
http_params = opts.clone
|
268
|
-
return_response_object = http_params.delete(:return_response_object)
|
269
|
-
|
270
212
|
# Set default token
|
271
213
|
http_params[:query] ||= FilterQuery.new(query).call
|
272
214
|
http_params[:headers] ||= {}
|
273
215
|
http_params[:headers]['Content-length'] = '0' if http_params[:body].blank?
|
216
|
+
http_params[:headers]['x-api-key'] = QuickTravel.config.access_key
|
274
217
|
expect = http_params.delete(:expect)
|
275
218
|
|
276
219
|
# Use :body instead of :query for put/post.
|
@@ -280,7 +223,6 @@ module QuickTravel
|
|
280
223
|
if [:put, :post].include?(http_method.to_sym)
|
281
224
|
http_params[:body].merge!(http_params.delete(:query))
|
282
225
|
end
|
283
|
-
http_params[:body][:access_key] = QuickTravel.config.access_key
|
284
226
|
http_params[:follow_redirects] = false
|
285
227
|
|
286
228
|
begin
|
@@ -306,11 +248,7 @@ module QuickTravel
|
|
306
248
|
|
307
249
|
validate!(response)
|
308
250
|
|
309
|
-
|
310
|
-
response
|
311
|
-
else
|
312
|
-
response.parsed_response
|
313
|
-
end
|
251
|
+
response
|
314
252
|
end
|
315
253
|
|
316
254
|
# Do standard validations on response
|
data/lib/quick_travel/address.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
require 'quick_travel/
|
1
|
+
require 'quick_travel/init_from_hash'
|
2
2
|
|
3
3
|
module QuickTravel
|
4
|
-
class BackgroundCheck
|
4
|
+
class BackgroundCheck
|
5
|
+
include QuickTravel::InitFromHash
|
6
|
+
|
5
7
|
def self.check(options = {})
|
6
8
|
get_and_validate('/background_check/check.json', options)
|
7
9
|
end
|
data/lib/quick_travel/booking.rb
CHANGED
@@ -4,6 +4,7 @@ require 'quick_travel/vehicle'
|
|
4
4
|
require 'quick_travel/payment'
|
5
5
|
require 'quick_travel/payment_type'
|
6
6
|
require 'quick_travel/price_changes'
|
7
|
+
require 'uri'
|
7
8
|
|
8
9
|
module QuickTravel
|
9
10
|
class Booking < Adapter
|
@@ -12,7 +13,7 @@ module QuickTravel
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def self.find_by_reference(reference)
|
15
|
-
find_all!("#{api_base}/reference/#{reference}.json").first
|
16
|
+
find_all!("#{api_base}/reference/#{URI.encode_www_form_component(reference)}.json").first
|
16
17
|
end
|
17
18
|
|
18
19
|
def documents(regenerate = false)
|
@@ -184,6 +185,10 @@ module QuickTravel
|
|
184
185
|
vehicles.detect { |v| v.id.to_i == vid.to_i }
|
185
186
|
end
|
186
187
|
|
188
|
+
def passengers
|
189
|
+
@passenger_objects ||= @passengers_attributes.map{ |p| Passenger.new(p) }
|
190
|
+
end
|
191
|
+
|
187
192
|
def passenger_types_counts
|
188
193
|
passengers.each_with_object(Hash.new(0)) do |passenger, hash|
|
189
194
|
hash[passenger.passenger_type_id] += 1
|
@@ -291,6 +296,11 @@ module QuickTravel
|
|
291
296
|
Encrypt.access_key(@id.to_s)
|
292
297
|
end
|
293
298
|
|
299
|
+
def customer_comments
|
300
|
+
comment = comments.detect{ |comment| comment['comment_type'] == 'customer' }
|
301
|
+
comment.presence.try(:[], 'text') || ''
|
302
|
+
end
|
303
|
+
|
294
304
|
protected
|
295
305
|
|
296
306
|
def reserve(url, options)
|
data/lib/quick_travel/cache.rb
CHANGED
@@ -6,16 +6,27 @@ module QuickTravel
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.cache(key, cache_options =
|
9
|
+
def self.cache(key, cache_options = nil)
|
10
|
+
return yield unless key.present?
|
11
|
+
cache_options ||= {}
|
12
|
+
key = "#{@@namespace}_#{key}" unless cache_options[:disable_namespacing]
|
10
13
|
cached_value = cache_store.read(key)
|
11
|
-
return cached_value unless cached_value
|
14
|
+
return cached_value unless cache_empty?(cached_value)
|
12
15
|
return nil unless block_given?
|
13
16
|
cache_options ||= {}
|
14
17
|
cache_options[:expires_in] = 1.day unless cache_options.key?(:expires_in)
|
15
18
|
yield.tap { |value| cache_store.write(key, value, cache_options) }
|
16
19
|
end
|
17
20
|
|
18
|
-
def self.
|
21
|
+
def self.cache_empty?(cached_value)
|
22
|
+
if cached_value.respond_to?(:body)
|
23
|
+
return cached_value.body.nil? || cached_value.body.empty?
|
24
|
+
end
|
25
|
+
cached_value.nil?
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.delete(key, namespace = true)
|
29
|
+
key = "#{@@namespace}_#{key}" if namespace
|
19
30
|
cache_store.delete(key)
|
20
31
|
end
|
21
32
|
|
@@ -27,8 +38,16 @@ module QuickTravel
|
|
27
38
|
@@cache_store
|
28
39
|
end
|
29
40
|
|
30
|
-
def self.cache_store=(
|
31
|
-
@@cache_store =
|
41
|
+
def self.cache_store=(session)
|
42
|
+
@@cache_store = session
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.namespace
|
46
|
+
@@namespace
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.namespace=(namespace)
|
50
|
+
@@namespace = namespace
|
32
51
|
end
|
33
52
|
end
|
34
53
|
end
|
@@ -46,7 +46,7 @@ module QuickTravel
|
|
46
46
|
# TODO Move to an external builder?
|
47
47
|
def self.attributes_for
|
48
48
|
attrs = yield
|
49
|
-
attrs[:completed] =
|
49
|
+
attrs[:completed] = attrs['progress'] == 'completed'
|
50
50
|
attrs[:successful] = attrs[:completed]
|
51
51
|
attrs
|
52
52
|
rescue AdapterError => e
|