garage_client 2.4.0 → 2.4.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 67db70f420fa5fc41a2a070c99dbbd37eb70f909
4
- data.tar.gz: a1caece74b9d92acfc6df7a7e5429e330969401f
2
+ SHA256:
3
+ metadata.gz: b719783d93f2fe8a23421f6a05946aa376623d953c99ba1a3cf5435a5d248ac0
4
+ data.tar.gz: 40287bfa976d8608d43a67cd3b50135e1618a28232346508f6ad319d50cf1262
5
5
  SHA512:
6
- metadata.gz: 323b4e8bab3eca3cafcdffa6c83c5960b745b1ad7827298d79fd59ad7f44df3e29186a0a295766ae5d2864c29c7e593c671302fbc9b06c96a4a1e59ffd0882f7
7
- data.tar.gz: e7bf77480f8e5f46f511f7d66ecba31fdc5da866570a16c3fd683eb6d72e7046be0d65bcbc2b521960169e621193e45046891d11556f343dc175b34d3492848a
6
+ metadata.gz: bebf81e6430a3765d0f4f970aeca63c6ee059050c2d5f1a9a58b611d17b80f0a6bc91f756f85dee2a2c3d5e7a091ef75a3b5fd87b282288e238494dac213b6cc
7
+ data.tar.gz: 20a0ae03b1803f66a2b3f1ad47329990326f96004c667091600d474c63c7a2e0d65ea037aa026af6880677137e11432b6b284cbd8ba078e8593443aa5f6d7c8e
data/.travis.yml CHANGED
@@ -2,8 +2,10 @@ language: ruby
2
2
 
3
3
  rvm:
4
4
  - ruby-head
5
- - 2.3.1
6
- - 2.2.5
5
+ - 3.0.0
6
+ - 2.7.2
7
+ - 2.6.6
8
+ - 2.5.8
7
9
  matrix:
8
10
  allow_failures:
9
11
  - rvm: "ruby-head"
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## 2.4.5
2
+ - Drop support for Ruby 2.5
3
+ - Remove implicit dependency on Active Support
4
+
5
+ ## 2.4.4
6
+ - Remove activesupport dependency
7
+ - Fix request ID not being propagated
8
+
9
+ ## 2.4.3
10
+ - Support query methods on GarageClient::Resource
11
+ - Use Module#module_parent_name for Rails 6.0
12
+
13
+ ## 2.4.2
14
+ - Fixes for latest aws-xray gem. Require `aws/xray/faraday`.
15
+
16
+ ## 2.4.1
17
+ - Record http request/response even if API returns errors.
18
+
1
19
  ## 2.4.0
2
20
  - Support distributed tracing.
3
21
 
data/README.md CHANGED
@@ -209,7 +209,7 @@ Choose one of supported tracers from below. If you want to add new tracer, pleas
209
209
  Bundle [aws-xray](https://github.com/taiki45/aws-xray) gem in your `Gemfile`, then configure `GarageClient::Client` instance with `tracing.service` option:
210
210
 
211
211
  ```ruby
212
- require 'aws/xray'
212
+ require 'aws/xray/faraday'
213
213
  GarageClient::Client.new(..., tracing: { tracer: 'aws-xray', service: 'user' })
214
214
  ```
215
215
 
@@ -16,14 +16,11 @@ Gem::Specification.new do |s|
16
16
  s.authors = ['Cookpad Inc.']
17
17
  s.email = ['kaihatsu@cookpad.com']
18
18
 
19
- s.add_dependency 'activesupport', '> 3.2.0'
20
19
  s.add_dependency 'faraday', '>= 0.8.0'
21
20
  s.add_dependency 'faraday_middleware'
22
21
  s.add_dependency 'hashie', '>= 1.2.0'
23
22
  s.add_dependency 'link_header'
24
23
 
25
- s.add_dependency 'system_timer' if RUBY_VERSION < '1.9'
26
-
27
24
  s.add_development_dependency "rails"
28
25
  s.add_development_dependency "rake", ">= 0.9.2"
29
26
  s.add_development_dependency "rspec"
@@ -32,5 +29,5 @@ Gem::Specification.new do |s|
32
29
  s.add_development_dependency "pry"
33
30
  # Until bug fixed: https://github.com/colszowka/simplecov/issues/281
34
31
  s.add_development_dependency "simplecov", "~> 0.7.1"
35
- s.add_development_dependency "aws-xray"
32
+ s.add_development_dependency "aws-xray", ">= 0.30.0"
36
33
  end
data/lib/garage_client.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'active_support/all'
2
1
  require 'faraday'
3
2
  require 'faraday_middleware'
4
3
 
@@ -24,11 +23,15 @@ end
24
23
 
25
24
  module GarageClient
26
25
  class << self
27
- GarageClient::Configuration.keys.each do |key|
28
- delegate key, "#{key}=", to: :configuration
29
- end
26
+ [*GarageClient::Configuration.keys, :default_headers].each do |key|
27
+ define_method(key) do
28
+ configuration.public_send(key)
29
+ end
30
30
 
31
- delegate 'default_headers', 'default_headers=', to: :configuration
31
+ define_method("#{key}=") do |value|
32
+ configuration.public_send("#{key}=", value)
33
+ end
34
+ end
32
35
 
33
36
  def configuration
34
37
  @configuration ||= GarageClient::Configuration.new
@@ -27,7 +27,7 @@ module GarageClient
27
27
  end
28
28
 
29
29
  def headers
30
- @headers ||= GarageClient.configuration.headers.merge(given_headers.stringify_keys)
30
+ @headers ||= GarageClient.configuration.headers.merge(given_headers.transform_keys(&:to_s))
31
31
  end
32
32
  alias :default_headers :headers
33
33
 
@@ -58,17 +58,6 @@ module GarageClient
58
58
 
59
59
  def connection
60
60
  Faraday.new(headers: headers, url: endpoint) do |builder|
61
- if options[:tracing]
62
- case options[:tracing][:tracer]
63
- when 'aws-xray'
64
- service = options[:tracing][:service]
65
- raise 'Configure target service name with `tracing.service`' unless service
66
- builder.use Aws::Xray::Faraday, service
67
- else
68
- raise "`tracing` option specified but GarageClient does not support the tracer: #{options[:tracing][:tracer]}"
69
- end
70
- end
71
-
72
61
  # Response Middlewares
73
62
  builder.use Faraday::Response::Logger if verbose
74
63
  builder.use FaradayMiddleware::Mashify
@@ -81,6 +70,19 @@ module GarageClient
81
70
  builder.use GarageClient::Request::JsonEncoded
82
71
  builder.use GarageClient::Request::PropagateRequestId
83
72
 
73
+ # Tracing Middlewares
74
+ if options[:tracing]
75
+ case options[:tracing][:tracer]
76
+ when 'aws-xray'
77
+ service = options[:tracing][:service]
78
+ raise 'Configure target service name with `tracing.service`' unless service
79
+ require 'aws/xray/faraday'
80
+ builder.use Aws::Xray::Faraday, service
81
+ else
82
+ raise "`tracing` option specified but GarageClient does not support the tracer: #{options[:tracing][:tracer]}"
83
+ end
84
+ end
85
+
84
86
  # Low-level Middlewares
85
87
  apply_auth_middleware builder
86
88
  builder.adapter(*adapter)
@@ -9,7 +9,13 @@ module GarageClient
9
9
  def self.set_default_name
10
10
  unless GarageClient.configuration.options[:name]
11
11
  GarageClient.configure do |c|
12
- c.name = ::Rails.application.class.parent_name.underscore
12
+ klass = ::Rails.application.class
13
+ parent_name = if klass.respond_to?(:module_parent_name)
14
+ klass.module_parent_name
15
+ else
16
+ klass.parent_name
17
+ end
18
+ c.name = parent_name.underscore
13
19
  end
14
20
  end
15
21
  end
@@ -2,8 +2,8 @@ module GarageClient
2
2
  module Request
3
3
  class PropagateRequestId < Faraday::Middleware
4
4
  def call(env)
5
- if Thread.current[:request_id] && !env[:request_headers]["HTTP_X_REQUEST_ID"]
6
- env[:request_headers]["HTTP_X_REQUEST_ID"] = Thread.current[:request_id]
5
+ if Thread.current[:request_id] && !env[:request_headers]["X-Request-Id"]
6
+ env[:request_headers]["X-Request-Id"] = Thread.current[:request_id]
7
7
  end
8
8
  @app.call(env)
9
9
  end
@@ -41,6 +41,8 @@ module GarageClient
41
41
  else
42
42
  value
43
43
  end
44
+ elsif query_method?(name)
45
+ data.__send__(name)
44
46
  elsif links.include?(name)
45
47
  path = data._links[name].href
46
48
  client.get(path, *args)
@@ -53,11 +55,20 @@ module GarageClient
53
55
  end
54
56
 
55
57
  def respond_to_missing?(name, include_private)
56
- !!(properties.include?(name) || links.include?(name) || nested_resource_creation_method?(name))
58
+ !!(properties.include?(name) || query_method?(name) || links.include?(name) || nested_resource_creation_method?(name))
57
59
  end
58
60
 
59
61
  def nested_resource_creation_method?(name)
60
62
  !!(name =~ /\Acreate_(.+)\z/ && links.include?($1.to_sym))
61
63
  end
64
+
65
+ private
66
+
67
+ def query_method?(name)
68
+ if name.to_s.end_with?('?')
69
+ key = name.to_s[0..-2]
70
+ properties.include?(key.to_sym)
71
+ end
72
+ end
62
73
  end
63
74
  end
@@ -1,3 +1,3 @@
1
1
  module GarageClient
2
- VERSION = '2.4.0'
2
+ VERSION = '2.4.5'
3
3
  end
@@ -5,6 +5,7 @@ RSpec.describe 'Tracing support' do
5
5
  context 'when `tracing` option is specified' do
6
6
  around do |ex|
7
7
  Aws::Xray.config.client_options = { sock: io }
8
+ Aws::Xray.config.sampling_rate = 1
8
9
  Aws::Xray.trace(name: 'test-app') { ex.run }
9
10
  end
10
11
 
@@ -21,13 +22,13 @@ RSpec.describe 'Tracing support' do
21
22
  end
22
23
  let(:stubs) do
23
24
  Faraday::Adapter::Test::Stubs.new do |stub|
24
- stub.get('/campain') { |env| [200, {'Content-Type' => 'application/json'}, '{"campain": false}'] }
25
+ stub.get('/campaign') { |env| [200, {'Content-Type' => 'application/json'}, '{"campaign": false}'] }
25
26
  end
26
27
  end
27
28
 
28
29
  specify 'client enables tracing and sends trace data to a local agent' do
29
- res = client.get('/campain')
30
- expect(res.body.campain).to eq(false)
30
+ res = client.get('/campaign')
31
+ expect(res.body.campaign).to eq(false)
31
32
 
32
33
  io.rewind
33
34
  sent_jsons = io.read.split("\n")
@@ -35,5 +36,48 @@ RSpec.describe 'Tracing support' do
35
36
  body = JSON.parse(sent_jsons[1])
36
37
  expect(body['name']).to eq('target-app')
37
38
  end
39
+
40
+ context 'API returns client errors' do
41
+ let(:stubs) do
42
+ Faraday::Adapter::Test::Stubs.new do |stub|
43
+ stub.get('/campaign') { |env| [404, {'Content-Type' => 'application/json'}, '{"error": "not_found"}'] }
44
+ end
45
+ end
46
+
47
+ specify 'client traces HTTP request and response and records errors' do
48
+ expect { client.get('/campaign') }.to raise_error(GarageClient::NotFound)
49
+
50
+ io.rewind
51
+ sent_jsons = io.read.split("\n")
52
+ expect(sent_jsons.size).to eq(2)
53
+ body = JSON.parse(sent_jsons[1])
54
+ expect(body['name']).to eq('target-app')
55
+ expect(body['error']).to eq(true)
56
+ expect(body['http']['request']['method']).to eq('GET')
57
+ expect(body['http']['response']['status']).to eq(404)
58
+ end
59
+ end
60
+
61
+ context 'API returns server errors' do
62
+ let(:stubs) do
63
+ Faraday::Adapter::Test::Stubs.new do |stub|
64
+ stub.get('/campaign') { |env| [500, {'Content-Type' => 'application/json'}, '{"error": "internal_server_error"}'] }
65
+ end
66
+ end
67
+
68
+ specify 'client traces HTTP request and response and marks as fault' do
69
+ expect { client.get('/campaign') }.to raise_error(GarageClient::InternalServerError)
70
+
71
+ io.rewind
72
+ sent_jsons = io.read.split("\n")
73
+ expect(sent_jsons.size).to eq(2)
74
+ body = JSON.parse(sent_jsons[1])
75
+ expect(body['name']).to eq('target-app')
76
+ expect(body['error']).to eq(false)
77
+ expect(body['fault']).to eq(true)
78
+ expect(body['http']['request']['method']).to eq('GET')
79
+ expect(body['http']['response']['status']).to eq(500)
80
+ end
81
+ end
38
82
  end
39
83
  end
@@ -64,10 +64,6 @@ describe GarageClient::Cachers::Base do
64
64
 
65
65
  # Check dump data. Because cache data not broken on the version up of faraday.
66
66
  describe "check Faraday::Response marshal" do
67
- specify do
68
- expect(Faraday::VERSION).to be < "1.0.0", "This spec is no longer needed. Delete this 'describe' section!"
69
- end
70
-
71
67
  context "v0.9.1's marshal data" do
72
68
  let(:res) do
73
69
  Marshal.load(File.read(File.expand_path('../fixtures/faraday_0.9.1_response.dump', __dir__)))
@@ -75,7 +71,7 @@ describe GarageClient::Cachers::Base do
75
71
 
76
72
  it "load data" do
77
73
  expect(res).to be_instance_of Faraday::Response
78
- expect(res.env[:body]).to eq fixture("example.yaml")[:body]
74
+ expect(res.env[:body]).to eq fixture("example.yaml")["body"]
79
75
  end
80
76
  end
81
77
 
@@ -86,7 +82,7 @@ describe GarageClient::Cachers::Base do
86
82
 
87
83
  it "load data" do
88
84
  expect(res).to be_instance_of Faraday::Response
89
- expect(res.env[:body]).to eq fixture("example.yaml")[:body]
85
+ expect(res.env[:body]).to eq fixture("example.yaml")["body"]
90
86
  end
91
87
  end
92
88
  end
@@ -13,7 +13,7 @@ describe GarageClient::Request::PropagateRequestId do
13
13
  end
14
14
 
15
15
  it 'sends request_id via header' do
16
- stub_get("/examples").with(headers: { 'HTTP_X_REQUEST_ID' => 'request_id' })
16
+ stub_get("/examples").with(headers: { 'X-Request-Id' => 'request_id' })
17
17
  expect { client.get("/examples") }.not_to raise_error
18
18
  end
19
19
 
@@ -24,7 +24,7 @@ describe GarageClient::Request::PropagateRequestId do
24
24
 
25
25
  it 'does not send request_id via header' do
26
26
  stub_get("/examples").with do |request|
27
- !request.headers.include?('HTTP_X_REQUEST_ID')
27
+ !request.headers.include?('X-Request-Id')
28
28
  end
29
29
  expect { client.get("/examples") }.not_to raise_error
30
30
  end
@@ -32,11 +32,11 @@ describe GarageClient::Request::PropagateRequestId do
32
32
 
33
33
  context 'if already has request_id' do
34
34
  let(:client) do
35
- GarageClient::Client.new(headers: { 'HTTP_X_REQUEST_ID' => 'another_id' })
35
+ GarageClient::Client.new(headers: { 'X-Request-Id' => 'another_id' })
36
36
  end
37
37
 
38
38
  it 'does not overwrite request_id' do
39
- stub_get("/examples").with(headers: { 'HTTP_X_REQUEST_ID' => 'another_id' })
39
+ stub_get("/examples").with(headers: { 'X-Request-Id' => 'another_id' })
40
40
  expect { client.get("/examples") }.not_to raise_error
41
41
  end
42
42
  end
@@ -84,6 +84,12 @@ describe GarageClient::Resource do
84
84
  resource.user.should be_kind_of(GarageClient::Resource)
85
85
  end
86
86
  end
87
+
88
+ context 'with property query' do
89
+ it 'returns presence' do
90
+ resource.name?.should == true
91
+ end
92
+ end
87
93
  end
88
94
 
89
95
  describe 'link' do
data/spec/spec_helper.rb CHANGED
@@ -47,7 +47,7 @@ end
47
47
  def fixture(file)
48
48
  prefix = File.expand_path('../fixtures', __FILE__)
49
49
  path = File.join(prefix, file)
50
- HashWithIndifferentAccess.new(YAML.load_file(path))
50
+ YAML.load_file(path)
51
51
  end
52
52
 
53
53
  RSpec.configure do |config|
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: garage_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cookpad Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-29 00:00:00.000000000 Z
11
+ date: 2021-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: activesupport
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">"
18
- - !ruby/object:Gem::Version
19
- version: 3.2.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">"
25
- - !ruby/object:Gem::Version
26
- version: 3.2.0
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: faraday
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -184,14 +170,14 @@ dependencies:
184
170
  requirements:
185
171
  - - ">="
186
172
  - !ruby/object:Gem::Version
187
- version: '0'
173
+ version: 0.30.0
188
174
  type: :development
189
175
  prerelease: false
190
176
  version_requirements: !ruby/object:Gem::Requirement
191
177
  requirements:
192
178
  - - ">="
193
179
  - !ruby/object:Gem::Version
194
- version: '0'
180
+ version: 0.30.0
195
181
  description: Ruby client library for the Garage API
196
182
  email:
197
183
  - kaihatsu@cookpad.com
@@ -260,8 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
260
246
  - !ruby/object:Gem::Version
261
247
  version: '0'
262
248
  requirements: []
263
- rubyforge_project:
264
- rubygems_version: 2.6.11
249
+ rubygems_version: 3.1.4
265
250
  signing_key:
266
251
  specification_version: 4
267
252
  summary: Ruby client library for the Garage API