lhc 11.0.2 → 11.1.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/formats_concern.rb +4 -0
- data/lib/lhc/formats.rb +1 -0
- data/lib/lhc/formats/form.rb +45 -0
- data/lib/lhc/version.rb +1 -1
- data/spec/formats/form_spec.rb +27 -0
- data/spec/formats/multipart_spec.rb +1 -1
- 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: 0e87a43808e1303e4bc441b72031c3006d101d4f9193c207fa594cafab84a587
|
4
|
+
data.tar.gz: cb849adc725b31f9efed923aec3e40357362d87116603b8def485e2aca2bfe6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02c5069682e8764bb485254089c141751c93bf28ba414d68d4386a64bdbf5fbad3ccbe8362d61cab3725d1b14619790e822b6312e5fd1978099742dcb5e6dd06
|
7
|
+
data.tar.gz: 882ac80b97b12e89088f420f1faf13cbc90c4ed89a14ba078025a42dc01449a29aaf49214d6ba2f7ffca5d29968336a23b62aabb9e679dfd343f92d6f7aab1ed
|
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
|
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/)
|
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.0
|
4
|
+
version: 11.1.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: 2020-
|
11
|
+
date: 2020-03-16 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
|