minato_ruby_api_client 0.2.1 → 0.2.3

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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -23
  3. data/Dockerfile +1 -1
  4. data/Gemfile +17 -17
  5. data/Gemfile.lock +402 -398
  6. data/README.md +54 -54
  7. data/Rakefile +10 -10
  8. data/compose.yml +11 -11
  9. data/lib/minato_ruby_api_client/api_client.rb +398 -389
  10. data/lib/minato_ruby_api_client/api_error.rb +16 -16
  11. data/lib/minato_ruby_api_client/configuration.rb +247 -247
  12. data/lib/minato_ruby_api_client/version.rb +3 -3
  13. data/lib/minato_ruby_api_client.rb +24 -24
  14. data/minato_ruby_api_client.gemspec +35 -35
  15. data/spec/api_client_spec.rb +42 -0
  16. data/spec/configuration_spec.rb +204 -204
  17. data/spec/minato_ruby_api_client_spec.rb +17 -17
  18. data/spec/spec_helper.rb +105 -105
  19. metadata +7 -40
  20. data/coverage/.last_run.json +0 -5
  21. data/coverage/.resultset.json +0 -1248
  22. data/coverage/.resultset.json.lock +0 -0
  23. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_asc.png +0 -0
  24. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_asc_disabled.png +0 -0
  25. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_both.png +0 -0
  26. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_desc.png +0 -0
  27. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_desc_disabled.png +0 -0
  28. data/coverage/assets/0.12.3/application.css +0 -1
  29. data/coverage/assets/0.12.3/application.js +0 -7
  30. data/coverage/assets/0.12.3/colorbox/border.png +0 -0
  31. data/coverage/assets/0.12.3/colorbox/controls.png +0 -0
  32. data/coverage/assets/0.12.3/colorbox/loading.gif +0 -0
  33. data/coverage/assets/0.12.3/colorbox/loading_background.png +0 -0
  34. data/coverage/assets/0.12.3/favicon_green.png +0 -0
  35. data/coverage/assets/0.12.3/favicon_red.png +0 -0
  36. data/coverage/assets/0.12.3/favicon_yellow.png +0 -0
  37. data/coverage/assets/0.12.3/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  38. data/coverage/assets/0.12.3/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  39. data/coverage/assets/0.12.3/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  40. data/coverage/assets/0.12.3/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  41. data/coverage/assets/0.12.3/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  42. data/coverage/assets/0.12.3/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  43. data/coverage/assets/0.12.3/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  44. data/coverage/assets/0.12.3/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  45. data/coverage/assets/0.12.3/images/ui-icons_222222_256x240.png +0 -0
  46. data/coverage/assets/0.12.3/images/ui-icons_2e83ff_256x240.png +0 -0
  47. data/coverage/assets/0.12.3/images/ui-icons_454545_256x240.png +0 -0
  48. data/coverage/assets/0.12.3/images/ui-icons_888888_256x240.png +0 -0
  49. data/coverage/assets/0.12.3/images/ui-icons_cd0a0a_256x240.png +0 -0
  50. data/coverage/assets/0.12.3/loading.gif +0 -0
  51. data/coverage/assets/0.12.3/magnify.png +0 -0
  52. data/coverage/index.html +0 -13728
@@ -306,4 +306,46 @@ describe MinatoRubyApiClient::ApiClient do
306
306
  end
307
307
  end
308
308
  end
309
+
310
+ describe '#log_response' do
311
+ let(:config) { MinatoRubyApiClient::Configuration.new }
312
+ let(:logger) { Logger.new(STDOUT) }
313
+ let(:api_client) { described_class.new(config) }
314
+
315
+ before do
316
+ allow(config).to receive(:logger).and_return(logger)
317
+ end
318
+
319
+ context 'when response has JSON content type' do
320
+ it 'logs response with full details' do
321
+ response = double('response',
322
+ env: double(url: 'https://api.example.com/test'),
323
+ headers: { 'Content-Type' => 'application/json' },
324
+ to_hash: { status: 200, body: '{"success": true}' }
325
+ )
326
+
327
+ expect(logger).to receive(:info).with({
328
+ 'message' => 'Receive response from https://api.example.com/test',
329
+ 'http_response' => { status: 200, body: '{"success": true}' }
330
+ })
331
+
332
+ api_client.send(:log_response, response)
333
+ end
334
+ end
335
+
336
+ context 'when response has binary content type' do
337
+ it 'logs only message without response details' do
338
+ response = double('response',
339
+ env: double(url: 'https://api.example.com/download'),
340
+ headers: { 'Content-Type' => 'application/pdf' }
341
+ )
342
+
343
+ expect(logger).to receive(:info).with({
344
+ 'message' => 'Receive response from https://api.example.com/download'
345
+ })
346
+
347
+ api_client.send(:log_response, response)
348
+ end
349
+ end
350
+ end
309
351
  end
@@ -1,204 +1,204 @@
1
- require 'spec_helper'
2
-
3
- describe MinatoRubyApiClient::Configuration do
4
- let(:url) { 'https://example.com/v1' }
5
-
6
- before :each do
7
- require 'uri'
8
- uri = URI.parse(url)
9
- MinatoRubyApiClient.configure do |c|
10
- c.host = uri.host
11
- c.base_path = uri.path
12
- c.api_key['api_key'] = 'test_key'
13
- end
14
-
15
- @config = described_class.default
16
- end
17
-
18
- describe '#scheme' do
19
- it 'should have the default value https' do
20
- expect(@config.scheme).to eq('https')
21
- end
22
-
23
- it 'should remove :// from scheme' do
24
- @config.scheme = 'https://'
25
- expect(@config.scheme).to eq('https')
26
- end
27
- end
28
-
29
- describe '#host' do
30
- it 'should do not have the scheme value' do
31
- expect(@config.host).not_to match(/https/)
32
- end
33
- end
34
-
35
- describe '#base_path' do
36
- it 'should add leading slashes if missing' do
37
- @config.base_path = 'v1'
38
- expect(@config.base_path).to eq('/v1')
39
- end
40
-
41
- it 'should be empty if is /' do
42
- @config.base_path = '/'
43
- expect(@config.base_path).to eq('')
44
- end
45
- end
46
-
47
- describe '#user_agent' do
48
- it 'should have user agent' do
49
- @config.user_agent = 'Minato'
50
- expect(@config.user_agent).to eq('Minato')
51
- end
52
- end
53
-
54
- describe '#base_url' do
55
- it 'should have the default value' do
56
- expect(@config.base_url).to eq(url)
57
- end
58
-
59
- it 'should remove trailing slashes' do
60
- [nil, '', '/', '//'].each do |base_path|
61
- @config.base_path = base_path
62
- expect(@config.base_url).to eq("https://example.com")
63
- end
64
- end
65
- end
66
-
67
- describe '#timeout' do
68
- it 'should have the default value' do
69
- expect(@config.timeout).to eq(60)
70
- end
71
- end
72
-
73
- describe '#debugging' do
74
- it 'should have the default value falsy' do
75
- expect(@config.debugging).to be_falsy
76
- end
77
-
78
- context 'when MINATO_RUBY_API_CLIENT_DEBUG is true' do
79
- it 'should be truthy' do
80
- allow(ENV).to receive(:[]).with('MINATO_RUBY_API_CLIENT_DEBUG').and_return('true')
81
- expect(@config.debugging).to be_truthy
82
- end
83
- end
84
-
85
- context 'when debug is active' do
86
- it 'should be truthy' do
87
- config = described_class.new
88
- config.debugging = true
89
- expect(config.debugging).to be_truthy
90
- end
91
- end
92
- end
93
-
94
- describe '#auth_settings' do
95
- it 'should have default auth types' do
96
- expect(@config.auth_settings.keys).to eq(%w[bearer_auth basic_auth apikey])
97
- end
98
- end
99
-
100
- describe '#basic_auth_token' do
101
- let(:username) { 'test' }
102
- let(:password) { 'test' }
103
- let(:token) { ["#{username}:#{password}"].pack('m').delete("\r\n") }
104
- it 'should return basic auth string' do
105
- @config.username = username
106
- @config.password = password
107
- expect(@config.basic_auth_token).to eq("Basic #{token}")
108
- end
109
- end
110
-
111
- describe '#logger' do
112
- let(:logger) { Logger.new(STDOUT) }
113
-
114
- context 'when Rails is defined' do
115
- it 'should return Rails.logger' do
116
- allow(Object).to receive(:const_defined?).with(:Rails).and_return(true)
117
- allow(Rails).to receive(:logger).and_return(logger)
118
- config = described_class.new
119
- expect(config.logger).to eq(Rails.logger)
120
- end
121
- end
122
-
123
- context 'when Rails is not defined' do
124
- it 'should return Logger instance' do
125
- allow(Object).to receive(:const_defined?).with(:Rails).and_return(nil)
126
- config = described_class.new
127
- expect(config.logger).to be_instance_of(Logger)
128
- end
129
- end
130
- end
131
-
132
- describe '#api_key_with_prefix' do
133
- context 'when api_key_prefix is not defined' do
134
- it 'return the key without prefix' do
135
- expect(@config.api_key_with_prefix('api_key')).to eq('test_key')
136
- end
137
- end
138
-
139
- context 'when api_key_prefix is defined' do
140
- it 'return the key with prefix' do
141
- @config.api_key_prefix['api_key'] = 'Prefix'
142
- expect(@config.api_key_with_prefix('api_key')).to eq('Prefix test_key')
143
- end
144
- end
145
- end
146
-
147
- describe '#configure' do
148
- context 'when block is given' do
149
- it 'should yield the configuration object' do
150
- expect { |b| @config.configure(&b) }.to yield_with_args
151
- end
152
- end
153
-
154
- context 'when block is not given' do
155
- it 'should return nil' do
156
- expect(@config.configure).to be_nil
157
- end
158
- end
159
- end
160
-
161
- describe '#use' do
162
- it 'add middleware to the middlewares list' do
163
- @config.use(:test)
164
- expect(@config.instance_variable_get('@middlewares')).to include([:test])
165
- end
166
- end
167
-
168
- describe '#request' do
169
- it 'add middleware to the request middlewares list' do
170
- @config.request(:test)
171
- expect(@config.instance_variable_get('@request_middlewares')).to include([:test])
172
- end
173
- end
174
-
175
- describe '#response' do
176
- it 'add middleware to the response middlewares list' do
177
- @config.response(:test)
178
- expect(@config.instance_variable_get('@response_middlewares')).to include([:test])
179
- end
180
- end
181
-
182
- describe '#configure_middleware' do
183
- let(:conn) { double('conn') }
184
- let(:config) { described_class.new }
185
-
186
- before do
187
- config.use(:use)
188
- config.request(:request)
189
- config.response(:response)
190
-
191
- allow(conn).to receive(:use)
192
- allow(conn).to receive(:request)
193
- allow(conn).to receive(:response)
194
-
195
- config.configure_middleware(conn)
196
- end
197
-
198
- it 'add middlewares to connection middleware stack' do
199
- expect(conn).to have_received(:use).once.with(:use)
200
- expect(conn).to have_received(:request).once.with(:request)
201
- expect(conn).to have_received(:response).once.with(:response)
202
- end
203
- end
204
- end
1
+ require 'spec_helper'
2
+
3
+ describe MinatoRubyApiClient::Configuration do
4
+ let(:url) { 'https://example.com/v1' }
5
+
6
+ before :each do
7
+ require 'uri'
8
+ uri = URI.parse(url)
9
+ MinatoRubyApiClient.configure do |c|
10
+ c.host = uri.host
11
+ c.base_path = uri.path
12
+ c.api_key['api_key'] = 'test_key'
13
+ end
14
+
15
+ @config = described_class.default
16
+ end
17
+
18
+ describe '#scheme' do
19
+ it 'should have the default value https' do
20
+ expect(@config.scheme).to eq('https')
21
+ end
22
+
23
+ it 'should remove :// from scheme' do
24
+ @config.scheme = 'https://'
25
+ expect(@config.scheme).to eq('https')
26
+ end
27
+ end
28
+
29
+ describe '#host' do
30
+ it 'should do not have the scheme value' do
31
+ expect(@config.host).not_to match(/https/)
32
+ end
33
+ end
34
+
35
+ describe '#base_path' do
36
+ it 'should add leading slashes if missing' do
37
+ @config.base_path = 'v1'
38
+ expect(@config.base_path).to eq('/v1')
39
+ end
40
+
41
+ it 'should be empty if is /' do
42
+ @config.base_path = '/'
43
+ expect(@config.base_path).to eq('')
44
+ end
45
+ end
46
+
47
+ describe '#user_agent' do
48
+ it 'should have user agent' do
49
+ @config.user_agent = 'Minato'
50
+ expect(@config.user_agent).to eq('Minato')
51
+ end
52
+ end
53
+
54
+ describe '#base_url' do
55
+ it 'should have the default value' do
56
+ expect(@config.base_url).to eq(url)
57
+ end
58
+
59
+ it 'should remove trailing slashes' do
60
+ [nil, '', '/', '//'].each do |base_path|
61
+ @config.base_path = base_path
62
+ expect(@config.base_url).to eq("https://example.com")
63
+ end
64
+ end
65
+ end
66
+
67
+ describe '#timeout' do
68
+ it 'should have the default value' do
69
+ expect(@config.timeout).to eq(60)
70
+ end
71
+ end
72
+
73
+ describe '#debugging' do
74
+ it 'should have the default value falsy' do
75
+ expect(@config.debugging).to be_falsy
76
+ end
77
+
78
+ context 'when MINATO_RUBY_API_CLIENT_DEBUG is true' do
79
+ it 'should be truthy' do
80
+ allow(ENV).to receive(:[]).with('MINATO_RUBY_API_CLIENT_DEBUG').and_return('true')
81
+ expect(@config.debugging).to be_truthy
82
+ end
83
+ end
84
+
85
+ context 'when debug is active' do
86
+ it 'should be truthy' do
87
+ config = described_class.new
88
+ config.debugging = true
89
+ expect(config.debugging).to be_truthy
90
+ end
91
+ end
92
+ end
93
+
94
+ describe '#auth_settings' do
95
+ it 'should have default auth types' do
96
+ expect(@config.auth_settings.keys).to eq(%w[bearer_auth basic_auth apikey])
97
+ end
98
+ end
99
+
100
+ describe '#basic_auth_token' do
101
+ let(:username) { 'test' }
102
+ let(:password) { 'test' }
103
+ let(:token) { ["#{username}:#{password}"].pack('m').delete("\r\n") }
104
+ it 'should return basic auth string' do
105
+ @config.username = username
106
+ @config.password = password
107
+ expect(@config.basic_auth_token).to eq("Basic #{token}")
108
+ end
109
+ end
110
+
111
+ describe '#logger' do
112
+ let(:logger) { Logger.new(STDOUT) }
113
+
114
+ context 'when Rails is defined' do
115
+ it 'should return Rails.logger' do
116
+ allow(Object).to receive(:const_defined?).with(:Rails).and_return(true)
117
+ allow(Rails).to receive(:logger).and_return(logger)
118
+ config = described_class.new
119
+ expect(config.logger).to eq(Rails.logger)
120
+ end
121
+ end
122
+
123
+ context 'when Rails is not defined' do
124
+ it 'should return Logger instance' do
125
+ allow(Object).to receive(:const_defined?).with(:Rails).and_return(nil)
126
+ config = described_class.new
127
+ expect(config.logger).to be_instance_of(Logger)
128
+ end
129
+ end
130
+ end
131
+
132
+ describe '#api_key_with_prefix' do
133
+ context 'when api_key_prefix is not defined' do
134
+ it 'return the key without prefix' do
135
+ expect(@config.api_key_with_prefix('api_key')).to eq('test_key')
136
+ end
137
+ end
138
+
139
+ context 'when api_key_prefix is defined' do
140
+ it 'return the key with prefix' do
141
+ @config.api_key_prefix['api_key'] = 'Prefix'
142
+ expect(@config.api_key_with_prefix('api_key')).to eq('Prefix test_key')
143
+ end
144
+ end
145
+ end
146
+
147
+ describe '#configure' do
148
+ context 'when block is given' do
149
+ it 'should yield the configuration object' do
150
+ expect { |b| @config.configure(&b) }.to yield_with_args
151
+ end
152
+ end
153
+
154
+ context 'when block is not given' do
155
+ it 'should return nil' do
156
+ expect(@config.configure).to be_nil
157
+ end
158
+ end
159
+ end
160
+
161
+ describe '#use' do
162
+ it 'add middleware to the middlewares list' do
163
+ @config.use(:test)
164
+ expect(@config.instance_variable_get('@middlewares')).to include([:test])
165
+ end
166
+ end
167
+
168
+ describe '#request' do
169
+ it 'add middleware to the request middlewares list' do
170
+ @config.request(:test)
171
+ expect(@config.instance_variable_get('@request_middlewares')).to include([:test])
172
+ end
173
+ end
174
+
175
+ describe '#response' do
176
+ it 'add middleware to the response middlewares list' do
177
+ @config.response(:test)
178
+ expect(@config.instance_variable_get('@response_middlewares')).to include([:test])
179
+ end
180
+ end
181
+
182
+ describe '#configure_middleware' do
183
+ let(:conn) { double('conn') }
184
+ let(:config) { described_class.new }
185
+
186
+ before do
187
+ config.use(:use)
188
+ config.request(:request)
189
+ config.response(:response)
190
+
191
+ allow(conn).to receive(:use)
192
+ allow(conn).to receive(:request)
193
+ allow(conn).to receive(:response)
194
+
195
+ config.configure_middleware(conn)
196
+ end
197
+
198
+ it 'add middlewares to connection middleware stack' do
199
+ expect(conn).to have_received(:use).once.with(:use)
200
+ expect(conn).to have_received(:request).once.with(:request)
201
+ expect(conn).to have_received(:response).once.with(:response)
202
+ end
203
+ end
204
+ end
@@ -1,17 +1,17 @@
1
- require 'spec_helper'
2
-
3
- describe MinatoRubyApiClient do
4
- describe '.configure' do
5
- context 'when no block is given' do
6
- it 'returns the default configuration' do
7
- expect(MinatoRubyApiClient.configure).to eq MinatoRubyApiClient::Configuration.default
8
- end
9
- end
10
-
11
- context 'when a block is given' do
12
- it 'yields the configuration' do
13
- expect { |b| MinatoRubyApiClient.configure(&b) }.to yield_control
14
- end
15
- end
16
- end
17
- end
1
+ require 'spec_helper'
2
+
3
+ describe MinatoRubyApiClient do
4
+ describe '.configure' do
5
+ context 'when no block is given' do
6
+ it 'returns the default configuration' do
7
+ expect(MinatoRubyApiClient.configure).to eq MinatoRubyApiClient::Configuration.default
8
+ end
9
+ end
10
+
11
+ context 'when a block is given' do
12
+ it 'yields the configuration' do
13
+ expect { |b| MinatoRubyApiClient.configure(&b) }.to yield_control
14
+ end
15
+ end
16
+ end
17
+ end