grape-batch 1.1.2 → 1.1.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/grape/batch.rb +2 -1
- data/lib/grape/batch/hash_converter.rb +26 -0
- data/lib/grape/batch/version.rb +1 -1
- data/spec/api.rb +9 -0
- data/spec/requests_spec.rb +11 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a41ffb8fd6505834517b904ba91f5af4ea891327
|
4
|
+
data.tar.gz: d1a99a6c05a9b2c4dc6291366d5469c5e05ceae1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b9b9cb1822facd4f090cda89d973a91ba7ae4f9ead8427dd6efadeaa0d2912c36ed272b2fb57860a6230bbf269d21a105be90b13e8c69cd78a8135307288271
|
7
|
+
data.tar.gz: f50b49ed2fd3cf5589ba7c2f7803285c9b3fc349531baf730597d155a84267c0c9b18946d5a0fc4db3d86b7b343f5da723b79ecc398db3f412401774f52ca65b
|
data/CHANGELOG.md
ADDED
data/lib/grape/batch.rb
CHANGED
@@ -4,6 +4,7 @@ require 'grape/batch/log_subscriber'
|
|
4
4
|
require 'grape/batch/version'
|
5
5
|
require 'grape/batch/errors'
|
6
6
|
require 'grape/batch/configuration'
|
7
|
+
require 'grape/batch/hash_converter'
|
7
8
|
require 'grape/batch/parser'
|
8
9
|
require 'grape/batch/response'
|
9
10
|
require 'multi_json'
|
@@ -75,7 +76,7 @@ module Grape
|
|
75
76
|
|
76
77
|
if method == 'GET'
|
77
78
|
env['rack.input'] = StringIO.new('{}')
|
78
|
-
env['QUERY_STRING'] = URI.encode_www_form(body.to_a)
|
79
|
+
env['QUERY_STRING'] = URI.encode_www_form(HashConverter.encode(body).to_a)
|
79
80
|
else
|
80
81
|
env['rack.input'] = StringIO.new(MultiJson.encode(body))
|
81
82
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Grape
|
2
|
+
module Batch
|
3
|
+
class HashConverter
|
4
|
+
def self.encode(value, key = nil, out_hash = {})
|
5
|
+
case value
|
6
|
+
when Hash then
|
7
|
+
value.each { |k,v| encode(v, append_key(key,k), out_hash) }
|
8
|
+
out_hash
|
9
|
+
when Array then
|
10
|
+
value.each { |v| encode(v, "#{key}[]", out_hash) }
|
11
|
+
out_hash
|
12
|
+
when nil then ''
|
13
|
+
else
|
14
|
+
out_hash[key] = value
|
15
|
+
out_hash
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def self.append_key(root_key, key)
|
22
|
+
root_key.nil? ? :"#{key}" : :"#{root_key}[#{key.to_s}]"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/grape/batch/version.rb
CHANGED
data/spec/api.rb
CHANGED
@@ -32,6 +32,15 @@ module Twitter
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
resource :complex do
|
36
|
+
params do
|
37
|
+
requires :a, type: Hash
|
38
|
+
end
|
39
|
+
get do
|
40
|
+
"hash #{params[:a][:b][:c]}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
35
44
|
resource :status do
|
36
45
|
params do
|
37
46
|
requires :id, type: Integer, desc: "User id."
|
data/spec/requests_spec.rb
CHANGED
@@ -135,6 +135,17 @@ RSpec.describe Grape::Batch::Base do
|
|
135
135
|
it { expect(response.body).to eq(encode([{ success: 'status 856' }])) }
|
136
136
|
end
|
137
137
|
|
138
|
+
context 'with a body and nested hash' do
|
139
|
+
let(:complex) do
|
140
|
+
{ a: { b: { c: 1 } } }
|
141
|
+
end
|
142
|
+
let(:request_body) do
|
143
|
+
encode({ requests: [{ method: 'GET', path: '/api/v1/complex', body: complex}] })
|
144
|
+
end
|
145
|
+
it { expect(response.status).to eq(200) }
|
146
|
+
it { expect(response.body).to eq(encode([{ success: "hash 1" }])) }
|
147
|
+
end
|
148
|
+
|
138
149
|
describe '404 errors' do
|
139
150
|
let(:request_body) { encode({ requests: [{ method: 'GET', path: '/api/v1/unknown' }] }) }
|
140
151
|
it { expect(response.status).to eq(200) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-batch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lionel Oto
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-06-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rack
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- ".ruby-gemset"
|
139
139
|
- ".ruby-version"
|
140
140
|
- ".travis.yml"
|
141
|
+
- CHANGELOG.md
|
141
142
|
- Gemfile
|
142
143
|
- LICENSE.txt
|
143
144
|
- README.md
|
@@ -146,6 +147,7 @@ files:
|
|
146
147
|
- lib/grape/batch.rb
|
147
148
|
- lib/grape/batch/configuration.rb
|
148
149
|
- lib/grape/batch/errors.rb
|
150
|
+
- lib/grape/batch/hash_converter.rb
|
149
151
|
- lib/grape/batch/log_subscriber.rb
|
150
152
|
- lib/grape/batch/parser.rb
|
151
153
|
- lib/grape/batch/response.rb
|