Skip to content

Commit

Permalink
Merge pull request #42 from sealink/TT-608-update-qt-client-to-pass-t…
Browse files Browse the repository at this point in the history
…he-date

Tt 608 update qt client to pass the date
  • Loading branch information
Michael Noack authored Aug 9, 2016
2 parents 952491b + a7aaaf7 commit 43fc965
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 6 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This changelog adheres to [Keep a CHANGELOG](http://keepachangelog.com/).

## [2.3.0]

### Changed
- Change cache expiries
- Adds support for passing dates to Resource#all_with_price

### Fixed
- Fixes issue with HTTParty ~> 0.14
- Updates HTTParty dependency to ~> 0.14

## [2.2.2]
### Changed
Expand Down
3 changes: 3 additions & 0 deletions gemfiles/rails2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ source 'https://rubygems.org'
gemspec :path => '../'

group :development, :test do
gem 'json', '~> 1.8'
gem 'tins', '~> 1.6.0'
gem 'activesupport', '~> 2.3'
gem 'activerecord', '~> 2.3'
gem 'actionpack', '~> 2.3'
gem 'rubocop', '~> 0.41.2'
end
2 changes: 1 addition & 1 deletion lib/quick_travel/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def self.call_and_validate(http_method, path, query = {}, opts = {})
raise ConnectionError.new('Timeout error')
end

if expect && expect == :json && !response.is_a?(Hash)
if expect && expect == :json && !response.parsed_response.is_a?(Hash)
fail AdapterError, <<-FAIL
Request expected to be json but failed. Debug information below:
http_method: #{http_method.inspect}
Expand Down
23 changes: 21 additions & 2 deletions lib/quick_travel/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def sub_resources
end

def self.all_with_price(opts)
find_all!("/api/resources/index_with_price.json",
opts.merge(cache: "#{name}.all_with_price-attrs?#{opts.to_param}&date=#{Date.current}"))
cache_key = GenerateCacheKey.new(name, opts).call
find_all!("/api/resources/index_with_price.json", opts.merge(cache: cache_key))
end

def product_type
Expand All @@ -25,5 +25,24 @@ def bed_requirements
BedRequirement.new(bed_requirement)
end
end

private

class GenerateCacheKey
def initialize(resource_name, opts)
@resource_name = resource_name
@opts = opts
end

def call
"#{@resource_name}.all_with_price-attrs?#{cache_params.to_param}"
end

private

def cache_params
{ date: Date.current }.merge(@opts.symbolize_keys)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/quick_travel/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module QuickTravel
VERSION = '2.2.2'
VERSION = '2.3.0'
end
3 changes: 2 additions & 1 deletion quicktravel_client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_dependency 'httparty'
spec.add_dependency 'httparty', '~> 0.14'
spec.add_dependency 'json'
# Geokit dependency should be removed (see address.rb for details)
spec.add_dependency 'geokit', '~> 1.8.3' # used in address model
spec.add_dependency 'activesupport', '>= 2.0.0'
Expand Down

0 comments on commit 43fc965

Please sign in to comment.