flexirest 1.10.11 → 1.10.12
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/docs/{debugging.md → logging.md} +23 -4
- data/lib/flexirest/caching.rb +2 -2
- data/lib/flexirest/configuration.rb +14 -0
- data/lib/flexirest/instrumentation.rb +1 -1
- data/lib/flexirest/request.rb +18 -10
- data/lib/flexirest/version.rb +1 -1
- data/spec/lib/configuration_spec.rb +20 -0
- data/spec/lib/instrumentation_spec.rb +1 -1
- data/spec/lib/json_api_spec.rb +4 -4
- data/spec/lib/request_spec.rb +22 -2
- data/spec/spec_helper.rb +2 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40ffddde69dc7fb5e5e16c7de3e881f4c913d573170c8ddefcdc799da6a2139e
|
4
|
+
data.tar.gz: 370540fa78e3d99f8a9ac798104e21a1f8d0f5bb8ff54e99d398b682f0a58be9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 253e46a23429c4f0ec77fe9bb223ec80ab758bf352232559e68ae63f1462710af268bee3d9662c5cf104b5f262ff3bea112f03991be8f08ec76777f5c45c021a
|
7
|
+
data.tar.gz: 65a2576d868804a56147227cddb604d3ade6c91960bcd5f59778e3aaad3489682bbc725942a4c1f6f93148333b9929d27238280eb9c8f76b1c9f98b770ea3bdd
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -100,7 +100,7 @@ I've written a TON of documentation on how to use Flexirest and a LITTLE bit on
|
|
100
100
|
- [HTTP/parse error handling](docs/httpparse-error-handling.md)
|
101
101
|
- [Validation](docs/validation.md)
|
102
102
|
- [Filtering result lists](docs/filtering-result-lists.md)
|
103
|
-
- [
|
103
|
+
- [Logging](docs/logging.md)
|
104
104
|
- [XML responses](docs/xml-responses.md)
|
105
105
|
|
106
106
|
|
@@ -1,14 +1,18 @@
|
|
1
|
-
# *Flexirest:*
|
1
|
+
# *Flexirest:* Logging
|
2
2
|
|
3
|
-
|
3
|
+
## Verbose
|
4
|
+
|
5
|
+
You can turn on verbose logging to see what is sent to the API server and what is returned in one of these two ways:
|
4
6
|
|
5
7
|
```ruby
|
6
8
|
class Article < Flexirest::Base
|
7
|
-
verbose
|
9
|
+
verbose!
|
8
10
|
end
|
9
11
|
|
12
|
+
# or if you prefer
|
13
|
+
|
10
14
|
class Person < Flexirest::Base
|
11
|
-
verbose
|
15
|
+
verbose true
|
12
16
|
end
|
13
17
|
```
|
14
18
|
|
@@ -26,6 +30,21 @@ class Article < Flexirest::Base
|
|
26
30
|
end
|
27
31
|
```
|
28
32
|
|
33
|
+
## Quiet
|
34
|
+
|
35
|
+
By the same token, if you want to silence all log output from Flexirest, you can use quiet:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
class Article < Flexirest::Base
|
39
|
+
quiet!
|
40
|
+
end
|
41
|
+
|
42
|
+
# or if you prefer
|
43
|
+
|
44
|
+
class Person < Flexirest::Base
|
45
|
+
quiet true
|
46
|
+
end
|
47
|
+
```
|
29
48
|
|
30
49
|
-----
|
31
50
|
|
data/lib/flexirest/caching.rb
CHANGED
@@ -48,10 +48,10 @@ module Flexirest
|
|
48
48
|
@@cache_store = nil
|
49
49
|
end
|
50
50
|
|
51
|
-
def read_cached_response(request)
|
51
|
+
def read_cached_response(request, quiet)
|
52
52
|
if cache_store && perform_caching && request.method[:method] == :get
|
53
53
|
key = "#{request.class_name}:#{request.original_url}"
|
54
|
-
Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{key} - Trying to read from cache"
|
54
|
+
Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{key} - Trying to read from cache" unless quiet
|
55
55
|
value = cache_store.read(key)
|
56
56
|
value = Marshal.load(value) rescue value
|
57
57
|
end
|
@@ -299,6 +299,20 @@ module Flexirest
|
|
299
299
|
value ? @verbose = value : @verbose
|
300
300
|
end
|
301
301
|
|
302
|
+
def quiet!(options = {})
|
303
|
+
@quiet = true
|
304
|
+
@verbose = false
|
305
|
+
end
|
306
|
+
|
307
|
+
def quiet(value = nil)
|
308
|
+
@quiet ||= false
|
309
|
+
if value == true || value == false
|
310
|
+
@quiet = value
|
311
|
+
@verbose = false if @quiet != false
|
312
|
+
end
|
313
|
+
@quiet
|
314
|
+
end
|
315
|
+
|
302
316
|
def translator(value = nil)
|
303
317
|
Flexirest::Logger.warn("DEPRECATION: The translator functionality of Flexirest has been replaced with proxy functionality, see https://github.com/andyjeffries/flexirest#proxying-apis for more information") unless value.nil?
|
304
318
|
@translator ||= nil
|
@@ -4,7 +4,7 @@ module Flexirest
|
|
4
4
|
self.class.time_spent += event.duration
|
5
5
|
self.class.calls_made += 1
|
6
6
|
name = '%s (%.1fms)' % [Flexirest.name, event.duration]
|
7
|
-
Flexirest::Logger.debug " \033[1;4;32m#{name}\033[0m #{event.payload[:name]}"
|
7
|
+
Flexirest::Logger.debug " \033[1;4;32m#{name}\033[0m #{event.payload[:name]}" unless event.payload[:quiet]
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.time_spent=(value)
|
data/lib/flexirest/request.rb
CHANGED
@@ -184,6 +184,14 @@ module Flexirest
|
|
184
184
|
end
|
185
185
|
end
|
186
186
|
|
187
|
+
def quiet?
|
188
|
+
if object_is_class?
|
189
|
+
@object.quiet
|
190
|
+
else
|
191
|
+
@object.class.quiet
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
187
195
|
def translator
|
188
196
|
if object_is_class?
|
189
197
|
@object.translator
|
@@ -226,7 +234,7 @@ module Flexirest
|
|
226
234
|
@instrumentation_name = "#{class_name}##{@method[:name]}"
|
227
235
|
result = nil
|
228
236
|
cached = nil
|
229
|
-
ActiveSupport::Notifications.instrument("request_call.flexirest", :name => @instrumentation_name) do
|
237
|
+
ActiveSupport::Notifications.instrument("request_call.flexirest", :name => @instrumentation_name, quiet: quiet?) do
|
230
238
|
@explicit_parameters = explicit_parameters
|
231
239
|
@body = nil
|
232
240
|
prepare_params
|
@@ -244,7 +252,7 @@ module Flexirest
|
|
244
252
|
elsif @object.class.new.respond_to?(fake)
|
245
253
|
fake = @object.class.new.send(fake)
|
246
254
|
end
|
247
|
-
Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Faked response found"
|
255
|
+
Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Faked response found" unless quiet?
|
248
256
|
content_type = @method[:options][:fake_content_type] || "application/json"
|
249
257
|
return handle_response(OpenStruct.new(status:200, body:fake, response_headers:{"X-ARC-Faked-Response" => "true", "Content-Type" => content_type}))
|
250
258
|
end
|
@@ -260,13 +268,13 @@ module Flexirest
|
|
260
268
|
append_get_parameters
|
261
269
|
prepare_request_body
|
262
270
|
self.original_url = self.url
|
263
|
-
cached = original_object_class.read_cached_response(self)
|
271
|
+
cached = original_object_class.read_cached_response(self, quiet?)
|
264
272
|
if cached && !cached.is_a?(String)
|
265
273
|
if cached.expires && cached.expires > Time.now
|
266
|
-
Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Absolutely cached copy found"
|
274
|
+
Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Absolutely cached copy found" unless quiet?
|
267
275
|
return handle_cached_response(cached)
|
268
276
|
elsif cached.etag.to_s != "" #present? isn't working for some reason
|
269
|
-
Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Etag cached copy found with etag #{cached.etag}"
|
277
|
+
Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Etag cached copy found with etag #{cached.etag}" unless quiet?
|
270
278
|
etag = cached.etag
|
271
279
|
end
|
272
280
|
end
|
@@ -564,9 +572,9 @@ module Flexirest
|
|
564
572
|
connection = Flexirest::ConnectionManager.get_connection(base_url)
|
565
573
|
end
|
566
574
|
if @method[:options][:direct]
|
567
|
-
Flexirest::Logger.info " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Requesting #{@url}"
|
575
|
+
Flexirest::Logger.info " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Requesting #{@url}" unless quiet?
|
568
576
|
else
|
569
|
-
Flexirest::Logger.info " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Requesting #{connection.base_url}#{@url}"
|
577
|
+
Flexirest::Logger.info " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Requesting #{connection.base_url}#{@url}" unless quiet?
|
570
578
|
end
|
571
579
|
|
572
580
|
if verbose?
|
@@ -634,7 +642,7 @@ module Flexirest
|
|
634
642
|
|
635
643
|
if cached && response.status == 304
|
636
644
|
Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name}" +
|
637
|
-
' - Etag copy is the same as the server'
|
645
|
+
' - Etag copy is the same as the server' unless quiet?
|
638
646
|
return handle_cached_response(cached)
|
639
647
|
end
|
640
648
|
|
@@ -647,9 +655,9 @@ module Flexirest
|
|
647
655
|
return @response = Flexirest::PlainResponse.from_response(@response)
|
648
656
|
elsif is_json_response? || is_xml_response?
|
649
657
|
if @response.respond_to?(:proxied) && @response.proxied
|
650
|
-
Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Response was proxied, unable to determine size"
|
658
|
+
Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Response was proxied, unable to determine size" unless quiet?
|
651
659
|
else
|
652
|
-
Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Response received #{@response.body.size} bytes"
|
660
|
+
Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Response received #{@response.body.size} bytes" unless quiet?
|
653
661
|
end
|
654
662
|
result = generate_new_object(ignore_root: ignore_root, ignore_xml_root: @method[:options][:ignore_xml_root])
|
655
663
|
# TODO: Cleanup when ignore_xml_root is removed
|
data/lib/flexirest/version.rb
CHANGED
@@ -229,6 +229,26 @@ describe Flexirest::Configuration do
|
|
229
229
|
expect(VerboseConfigurationExample3.verbose).to be_truthy
|
230
230
|
end
|
231
231
|
|
232
|
+
it "should default to non-quiet logging" do
|
233
|
+
class QuietConfigurationExample1
|
234
|
+
include Flexirest::Configuration
|
235
|
+
end
|
236
|
+
expect(QuietConfigurationExample1.quiet).to be_falsey
|
237
|
+
end
|
238
|
+
|
239
|
+
it "should be able to switch on quiet logging" do
|
240
|
+
class QuietConfigurationExample2
|
241
|
+
include Flexirest::Configuration
|
242
|
+
quiet!
|
243
|
+
end
|
244
|
+
class QuietConfigurationExample3
|
245
|
+
include Flexirest::Configuration
|
246
|
+
quiet true
|
247
|
+
end
|
248
|
+
expect(QuietConfigurationExample2.quiet).to be_truthy
|
249
|
+
expect(QuietConfigurationExample3.quiet).to be_truthy
|
250
|
+
end
|
251
|
+
|
232
252
|
it "should store a translator given" do
|
233
253
|
expect{ ConfigurationExample.send(:translator) }.to_not raise_error
|
234
254
|
ConfigurationExample.send(:translator, String.new)
|
@@ -14,7 +14,7 @@ describe Flexirest::Instrumentation do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should call ActiveSupport::Notifications.instrument when making any request" do
|
17
|
-
expect(ActiveSupport::Notifications).to receive(:instrument).with("request_call.flexirest", {:name=>"InstrumentationExampleClient#fake"})
|
17
|
+
expect(ActiveSupport::Notifications).to receive(:instrument).with("request_call.flexirest", {:name=>"InstrumentationExampleClient#fake", :quiet=>false})
|
18
18
|
InstrumentationExampleClient.fake
|
19
19
|
end
|
20
20
|
|
data/spec/lib/json_api_spec.rb
CHANGED
@@ -332,7 +332,7 @@ describe 'JSON API' do
|
|
332
332
|
end
|
333
333
|
|
334
334
|
it 'should raise the relevant Flexirest error' do
|
335
|
-
expect
|
335
|
+
expect { make_request }.to raise_error(Flexirest::HTTPNotFoundClientException) do |exception|
|
336
336
|
expect(exception.result.first.detail).to eq("The record identified by 123456 could not be found")
|
337
337
|
end
|
338
338
|
end
|
@@ -349,7 +349,7 @@ describe 'JSON API' do
|
|
349
349
|
end
|
350
350
|
|
351
351
|
it 'should ignore the "data" key and raise the relevant Flexirest error' do
|
352
|
-
expect
|
352
|
+
expect { make_request }.to raise_error(Flexirest::HTTPNotFoundClientException) do |exception|
|
353
353
|
expect(exception.result.first.detail).to eq("The record identified by 123456 could not be found")
|
354
354
|
end
|
355
355
|
end
|
@@ -464,7 +464,7 @@ describe 'JSON API' do
|
|
464
464
|
end
|
465
465
|
|
466
466
|
it 'should raise exception when an association in the response is not defined in base class' do
|
467
|
-
expect
|
467
|
+
expect { subject.includes(:tags).not_recognized_assoc(1) }.to raise_error(Exception)
|
468
468
|
end
|
469
469
|
end
|
470
470
|
|
@@ -528,7 +528,7 @@ describe 'JSON API' do
|
|
528
528
|
article = JsonAPIExample::Article.new
|
529
529
|
article.item = 'item one'
|
530
530
|
article.tags = [tag, author]
|
531
|
-
expect
|
531
|
+
expect { article.create }.to raise_error(Exception)
|
532
532
|
end
|
533
533
|
|
534
534
|
it 'should perform a patch request in proper json api format' do
|
data/spec/lib/request_spec.rb
CHANGED
@@ -188,6 +188,13 @@ describe Flexirest::Request do
|
|
188
188
|
post :create, "/create"
|
189
189
|
end
|
190
190
|
|
191
|
+
class QuietExampleClient < ExampleClient
|
192
|
+
base_url "http://www.example.com"
|
193
|
+
quiet!
|
194
|
+
get :all, "/all"
|
195
|
+
post :create, "/create"
|
196
|
+
end
|
197
|
+
|
191
198
|
class CallbackBodyExampleClient < ExampleClient
|
192
199
|
base_url "http://www.example.com"
|
193
200
|
before_request do |name, request|
|
@@ -385,11 +392,14 @@ describe Flexirest::Request do
|
|
385
392
|
|
386
393
|
it "should use the URL method for Basic auth when basic_auth_method is set to :url (and not include Authorization header)" do
|
387
394
|
mocked_response = ::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{}))
|
388
|
-
headers_not_including_auth = hash_excluding("Authorization")
|
389
395
|
|
390
396
|
connection = double(Flexirest::Connection).as_null_object
|
391
397
|
expect(Flexirest::ConnectionManager).to receive(:get_connection).with("http://john:smith@www.example.com").and_return(connection)
|
392
|
-
expect(connection).to receive(:get)
|
398
|
+
expect(connection).to receive(:get) do |path, options|
|
399
|
+
expect(path).to eq("/")
|
400
|
+
expect(options[:headers]).to eq({"Accept"=>"application/hal+json, application/json;q=0.5", "Content-Type"=>"application/x-www-form-urlencoded; charset=utf-8"})
|
401
|
+
end.and_return(mocked_response)
|
402
|
+
|
393
403
|
AuthenticatedBasicUrlExampleClient.all
|
394
404
|
end
|
395
405
|
|
@@ -1120,6 +1130,16 @@ describe Flexirest::Request do
|
|
1120
1130
|
VerboseExampleClient.all
|
1121
1131
|
end
|
1122
1132
|
|
1133
|
+
it "should not log if quiet" do
|
1134
|
+
connection = double(Flexirest::Connection).as_null_object
|
1135
|
+
expect(Flexirest::ConnectionManager).to receive(:get_connection).and_return(connection)
|
1136
|
+
expect(connection).to receive(:get).with("/all", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{"Content-Type" => "application/json", "Connection" => "close"})))
|
1137
|
+
expect(Flexirest::Logger).to_not receive(:debug)
|
1138
|
+
expect(Flexirest::Logger).to_not receive(:info)
|
1139
|
+
expect(Flexirest::Logger).to_not receive(:error)
|
1140
|
+
QuietExampleClient.all
|
1141
|
+
end
|
1142
|
+
|
1123
1143
|
it "should return the headers still for 202 responses" do
|
1124
1144
|
fake_location = "https://foo.example.com/123"
|
1125
1145
|
expect_any_instance_of(Flexirest::Connection).
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flexirest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.10.
|
4
|
+
version: 1.10.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Jeffries
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -280,7 +280,6 @@ files:
|
|
280
280
|
- docs/body-types.md
|
281
281
|
- docs/caching.md
|
282
282
|
- docs/combined-example.md
|
283
|
-
- docs/debugging.md
|
284
283
|
- docs/default-parameters.md
|
285
284
|
- docs/empty-body-handling.md
|
286
285
|
- docs/faking-calls.md
|
@@ -291,6 +290,7 @@ files:
|
|
291
290
|
- docs/issue_template.md
|
292
291
|
- docs/json-api.md
|
293
292
|
- docs/lazy-loading.md
|
293
|
+
- docs/logging.md
|
294
294
|
- docs/migrating-from-activerestclient.md
|
295
295
|
- docs/parallel-requests.md
|
296
296
|
- docs/per-request-parameter-encoding.md
|