quicktravel_client 4.4.0 → 4.5.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
  SHA256:
3
- metadata.gz: e129c681ca2ddcb9dd7e16bec7c20abf68d521e97772a014084eafff9012d59a
4
- data.tar.gz: 4b2616b1833da92d728e068855ef45d079dee130917d069dc0392fca3c4cf29a
3
+ metadata.gz: e0325799c230cd8fe94a4f7454f8ff7ccb5fddb27ab18a67b9f3096d72aada02
4
+ data.tar.gz: 427ad145f755aa347c5ceb6d1c558b9e47392d1e61f48daeac074b933d7ded30
5
5
  SHA512:
6
- metadata.gz: 7583c89610fb8f7b5807446638dd0eac84773fc7007be819f6ef410121eca3a00bf6dba6db78373ea067804ae73fe39afa3951c15a9d9456ff7865167735367c
7
- data.tar.gz: 5ca4f5155bf9130c355c9a11620af95914e84276d382eff6f80b97a28fa98000ec055afc18c0f35ebbee6d9bec5f0a9a8ea9d0148c8a708b15b7e59644f60a13
6
+ metadata.gz: 744fc85a1f7bf032a494eb394c1573f06c0a1094608da175f7fc20c053babf78a8950bf038ff0b6dff97a0926f70492b96db2481083aa9055590f9fd8bdd33ac
7
+ data.tar.gz: 42f9a4aefc2150631c807a96bfaad03b8a0b6ff9c1427980435bd5a35818dadb84929b715199c47c2f02093be211b5f1565ef9957087129f5feed7398768bbae
data/CHANGELOG.md CHANGED
@@ -3,6 +3,13 @@ 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
+ ## Unreleased
7
+
8
+
9
+ ## 4.5.0
10
+ - [TT-9346] Support injection of additional headers in requests to quicktravel
11
+ - [TT-9331] Cache resources to reduce unnecessary API requests
12
+
6
13
  ## 4.4.0
7
14
  - [TT-8615] Update to build with github actions / ruby 3.0 / rails 6.1
8
15
 
@@ -216,6 +216,7 @@ module QuickTravel
216
216
  http_params[:headers]['Content-length'] = '0' if http_params[:body].blank?
217
217
  http_params[:headers]['x-api-key'] = QuickTravel.config.access_key
218
218
  http_params[:headers]['user-agent'] = 'quicktravel_client/' + QuickTravel::VERSION;
219
+ http_params[:headers].merge!(extra_headers) if extra_headers
219
220
 
220
221
  expect = http_params.delete(:expect)
221
222
 
@@ -254,6 +255,10 @@ module QuickTravel
254
255
  response
255
256
  end
256
257
 
258
+ def self.extra_headers
259
+ QuickTravel.config.extra_headers
260
+ end
261
+
257
262
  # Do standard validations on response
258
263
  #
259
264
  # Firstly, check if a valid HTTP code was returned
@@ -2,7 +2,7 @@ require 'quick_travel/adapter'
2
2
 
3
3
  module QuickTravel
4
4
  class Configuration
5
- attr_accessor :url, :access_key, :version
5
+ attr_accessor :url, :access_key, :version, :extra_headers
6
6
 
7
7
  def url=(url)
8
8
  @url = url
@@ -11,6 +11,11 @@ module QuickTravel
11
11
  Resource.find_all!('/api/resources.json', parent_resource_id: @id)
12
12
  end
13
13
 
14
+ def self.find(id, opts = {})
15
+ opts = { cache_key: "resource:#{id}", cache_options: { expires_in: 1.hour } }.merge(opts)
16
+ super(id, opts)
17
+ end
18
+
14
19
  def self.all_with_price(opts)
15
20
  cache_key = GenerateCacheKey.new(name, opts).call
16
21
  find_all!("/api/resources/index_with_price.json", opts.merge(cache_key: cache_key))
@@ -1,3 +1,3 @@
1
1
  module QuickTravel
2
- VERSION = '4.4.0'
2
+ VERSION = '4.5.0'
3
3
  end
data/spec/adapter_spec.rb CHANGED
@@ -83,4 +83,28 @@ describe QuickTravel::Adapter do
83
83
  specify { expect(api).to have_received(:call_and_validate).twice }
84
84
  end
85
85
  end
86
+
87
+ context 'extra headers defined' do
88
+ let(:url) { 'http://test.quicktravel.com.au' }
89
+ let(:query) { {} }
90
+ let(:change_config) { }
91
+ let(:useragent) { 'rspec' }
92
+
93
+ before do
94
+ change_config
95
+ QuickTravel::Adapter.post_and_validate(url, query)
96
+ end
97
+
98
+ let(:expected_params) { a_hash_including(headers: a_hash_including('user-agent' => useragent)) }
99
+
100
+ specify { expect(QuickTravel::Api).to have_received(:post).with(url, expected_params) }
101
+
102
+ context 'and the config is changed' do
103
+ let(:useragent) { 'newspec' }
104
+ let(:change_config) {
105
+ QuickTravel.config.extra_headers = { 'user-agent' => 'newspec' }
106
+ }
107
+ specify { expect(QuickTravel::Api).to have_received(:post).with(url, expected_params) }
108
+ end
109
+ end
86
110
  end
data/spec/spec_helper.rb CHANGED
@@ -22,6 +22,7 @@ qt_keys = ENV['QT_KEYS'].split(',')
22
22
  QuickTravel.configure do |c|
23
23
  c.url = 'http://test.qt.sealink.com.au:8080'
24
24
  c.access_key = qt_keys[0]
25
+ c.extra_headers = { 'user-agent' => 'rspec' }
25
26
  end
26
27
 
27
28
  require 'quick_travel/connection_error'
@@ -1,4 +1,4 @@
1
1
  require 'simplecov-rcov'
2
2
  require 'coveralls'
3
3
  require 'coverage/kit'
4
- Coverage::Kit.setup(minimum_coverage: 83.2)
4
+ Coverage::Kit.setup(minimum_coverage: 83.7)
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: 4.4.0
4
+ version: 4.5.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: 2021-01-06 00:00:00.000000000 Z
13
+ date: 2021-05-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty