lhc 11.0.0 → 11.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lhc/concerns/lhc/basic_methods_concern.rb +1 -1
- data/lib/lhc/concerns/lhc/formats_concern.rb +4 -0
- data/lib/lhc/error.rb +4 -0
- data/lib/lhc/formats.rb +1 -0
- data/lib/lhc/formats/form.rb +45 -0
- data/lib/lhc/interceptors/auth.rb +1 -1
- data/lib/lhc/interceptors/prometheus.rb +9 -3
- data/lib/lhc/request.rb +1 -1
- data/lib/lhc/version.rb +1 -1
- data/spec/formats/form_spec.rb +27 -0
- data/spec/formats/multipart_spec.rb +1 -1
- data/spec/interceptors/auth/reauthentication_spec.rb +10 -0
- data/spec/request/ignore_errors_spec.rb +8 -0
- data/spec/request/parallel_requests_spec.rb +19 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19e2069105d325acde5b2d89abcb267604658239dfc8808acc58637aac94a97a
|
4
|
+
data.tar.gz: f1795b3999b8307cca582bfd55318a663a823b87057535e9652b1c611d952292
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b0da63bf8c0ff0a66c37e7c3ca3b28f14e4940c2c16d432734b56ff957c4b305ca408660b5448c5f81e87cf19faf76578ddf52b0fbe826a2f63d1ad8c59468d
|
7
|
+
data.tar.gz: bd50aacfc4667b1d30cf9e1c1b2961d31b46e5603868a6d14ebcc2690deb4e9e3691e5ef65881f5b1744994d342eaf11be47b48cbd60bb33c1a9065033b32e5c
|
data/lib/lhc/error.rb
CHANGED
data/lib/lhc/formats.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LHC::Formats
|
4
|
+
class Form < LHC::Format
|
5
|
+
include LHC::BasicMethodsConcern
|
6
|
+
|
7
|
+
def self.request(options)
|
8
|
+
options[:format] = new
|
9
|
+
super(options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def format_options(options)
|
13
|
+
options[:headers] ||= {}
|
14
|
+
no_content_type_header!(options)
|
15
|
+
options[:headers]['Content-Type'] = 'application/x-www-form-urlencoded'
|
16
|
+
options
|
17
|
+
end
|
18
|
+
|
19
|
+
def as_json(input)
|
20
|
+
parse(input)
|
21
|
+
end
|
22
|
+
|
23
|
+
def as_open_struct(input)
|
24
|
+
parse(input)
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_body(input)
|
28
|
+
input
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s
|
32
|
+
'form'
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_sym
|
36
|
+
to_s.to_sym
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def parse(input)
|
42
|
+
input
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -66,7 +66,7 @@ class LHC::Auth < LHC::Interceptor
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def bearer_header_present?
|
69
|
-
@has_bearer_header ||= request.headers['Authorization'] =~ /^Bearer
|
69
|
+
@has_bearer_header ||= request.headers['Authorization'] =~ /^Bearer .+$/i
|
70
70
|
end
|
71
71
|
|
72
72
|
def refresh_client_token_option
|
@@ -15,9 +15,15 @@ class LHC::Prometheus < LHC::Interceptor
|
|
15
15
|
def initialize(request)
|
16
16
|
super(request)
|
17
17
|
return if LHC::Prometheus.registered || LHC::Prometheus.client.blank?
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
|
19
|
+
begin
|
20
|
+
LHC::Prometheus.client.registry.counter(LHC::Prometheus::REQUEST_COUNTER_KEY, 'Counter of all LHC requests.')
|
21
|
+
LHC::Prometheus.client.registry.histogram(LHC::Prometheus::REQUEST_HISTOGRAM_KEY, 'Request timings for all LHC requests in seconds.')
|
22
|
+
rescue Prometheus::Client::Registry::AlreadyRegisteredError => e
|
23
|
+
Rails.logger.error(e) if defined?(Rails)
|
24
|
+
ensure
|
25
|
+
LHC::Prometheus.registered = true
|
26
|
+
end
|
21
27
|
end
|
22
28
|
|
23
29
|
def after_response
|
data/lib/lhc/request.rb
CHANGED
@@ -15,7 +15,7 @@ class LHC::Request
|
|
15
15
|
attr_accessor :response, :options, :raw, :format, :error_handler, :errors_ignored, :source
|
16
16
|
|
17
17
|
def initialize(options, self_executing = true)
|
18
|
-
self.errors_ignored = (options.fetch(:ignored_errors, []) || []).compact
|
18
|
+
self.errors_ignored = (options.fetch(:ignored_errors, []) || []).to_a.compact
|
19
19
|
self.source = options&.dig(:source)
|
20
20
|
self.options = format!(options.deep_dup || {})
|
21
21
|
self.error_handler = options.delete :error_handler
|
data/lib/lhc/version.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
describe LHC do
|
6
|
+
include ActionDispatch::TestProcess
|
7
|
+
|
8
|
+
context 'form' do
|
9
|
+
it 'formats requests to be application/x-www-form-urlencoded' do
|
10
|
+
stub = stub_request(:post, 'http://local.ch/')
|
11
|
+
.with(body: 'client_id=1234&client_secret=4567&grant_type=client_credentials')
|
12
|
+
.with(headers: { 'Content-Type': 'application/x-www-form-urlencoded' })
|
13
|
+
.to_return(status: 200)
|
14
|
+
|
15
|
+
LHC.form.post(
|
16
|
+
'http://local.ch',
|
17
|
+
body: {
|
18
|
+
client_id: '1234',
|
19
|
+
client_secret: '4567',
|
20
|
+
grant_type: 'client_credentials'
|
21
|
+
}
|
22
|
+
)
|
23
|
+
|
24
|
+
expect(stub).to have_been_requested
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -10,7 +10,7 @@ describe LHC do
|
|
10
10
|
let(:body) { { size: 2231 }.to_json }
|
11
11
|
let(:location) { 'http://local.ch/uploads/image.jpg' }
|
12
12
|
|
13
|
-
it '
|
13
|
+
it 'formats requests to be multipart/form-data' do
|
14
14
|
stub_request(:post, 'http://local.ch/') do |request|
|
15
15
|
raise 'Content-Type header wrong' unless request.headers['Content-Type'] == 'multipart/form-data'
|
16
16
|
raise 'Body wrongly formatted' unless request.body.match(/file=%23%3CActionDispatch%3A%3AHttp%3A%3AUploadedFile%3A.*%3E&type=Image/)
|
@@ -31,4 +31,14 @@ describe LHC::Auth do
|
|
31
31
|
LHC.config.endpoint(:local, 'http://local.ch', auth: options.merge(reauthenticated: true))
|
32
32
|
expect { LHC.get(:local) }.to raise_error(LHC::Unauthorized)
|
33
33
|
end
|
34
|
+
|
35
|
+
context 'token format' do
|
36
|
+
let(:initial_token) { 'BAsZ-98-ZZZ' }
|
37
|
+
|
38
|
+
it 'refreshes tokens with various formats' do
|
39
|
+
LHC.config.endpoint(:local, 'http://local.ch', auth: options)
|
40
|
+
LHC.get(:local)
|
41
|
+
expect(auth_suceeding_after_recovery).to have_been_made.once
|
42
|
+
end
|
43
|
+
end
|
34
44
|
end
|
@@ -62,4 +62,12 @@ describe LHC::Request do
|
|
62
62
|
}.to raise_error(LHC::NotFound)
|
63
63
|
end
|
64
64
|
end
|
65
|
+
|
66
|
+
context 'passing keys instead of arrays' do
|
67
|
+
before { stub_request(:get, 'http://local.ch').to_return(status: 404) }
|
68
|
+
|
69
|
+
it "does not raise an error when ignored errors is a key instead of an array" do
|
70
|
+
LHC.get('http://local.ch', ignored_errors: LHC::NotFound)
|
71
|
+
end
|
72
|
+
end
|
65
73
|
end
|
@@ -37,4 +37,23 @@ describe LHC::Request do
|
|
37
37
|
expect(@called).to eq 2
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
41
|
+
context 'webmock disabled' do
|
42
|
+
before do
|
43
|
+
WebMock.disable!
|
44
|
+
end
|
45
|
+
|
46
|
+
after do
|
47
|
+
WebMock.enable!
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'does not memorize parallelization handlers in typhoeus (hydra) in case one request of the parallization fails' do
|
51
|
+
begin
|
52
|
+
LHC.request([{ url: 'https://www.google.com/' }, { url: 'https://nonexisting123' }, { url: 'https://www.google.com/' }, { url: 'https://nonexisting123' }])
|
53
|
+
rescue LHC::UnknownError
|
54
|
+
end
|
55
|
+
|
56
|
+
LHC.request([{ url: 'https://www.google.com' }])
|
57
|
+
end
|
58
|
+
end
|
40
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 11.
|
4
|
+
version: 11.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/local-ch/lhc/contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -230,6 +230,7 @@ files:
|
|
230
230
|
- lib/lhc/errors/unknown_error.rb
|
231
231
|
- lib/lhc/format.rb
|
232
232
|
- lib/lhc/formats.rb
|
233
|
+
- lib/lhc/formats/form.rb
|
233
234
|
- lib/lhc/formats/json.rb
|
234
235
|
- lib/lhc/formats/multipart.rb
|
235
236
|
- lib/lhc/formats/plain.rb
|
@@ -316,6 +317,7 @@ files:
|
|
316
317
|
- spec/error/response_spec.rb
|
317
318
|
- spec/error/timeout_spec.rb
|
318
319
|
- spec/error/to_s_spec.rb
|
320
|
+
- spec/formats/form_spec.rb
|
319
321
|
- spec/formats/json_spec.rb
|
320
322
|
- spec/formats/multipart_spec.rb
|
321
323
|
- spec/formats/plain_spec.rb
|
@@ -465,6 +467,7 @@ test_files:
|
|
465
467
|
- spec/error/response_spec.rb
|
466
468
|
- spec/error/timeout_spec.rb
|
467
469
|
- spec/error/to_s_spec.rb
|
470
|
+
- spec/formats/form_spec.rb
|
468
471
|
- spec/formats/json_spec.rb
|
469
472
|
- spec/formats/multipart_spec.rb
|
470
473
|
- spec/formats/plain_spec.rb
|