grape-batch 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8bbe03da7123e206a98f1665477f2903ccff61aa
4
- data.tar.gz: 814d658a2f6300f0b99d966be482bf49adf02f41
3
+ metadata.gz: a41ffb8fd6505834517b904ba91f5af4ea891327
4
+ data.tar.gz: d1a99a6c05a9b2c4dc6291366d5469c5e05ceae1
5
5
  SHA512:
6
- metadata.gz: 991c0e72406404557650cda1dbd0303fc0f0b85f701b0570ed8019960223fe64b306af997ce6cb21479932a42d54744bb148433708f458d1326ffa638fb94830
7
- data.tar.gz: 0822eda7abe6aaa04bdcb6ee6797549d4a8f8e745a6cb097abdfe5d81059a3da70f92cb74c9d911d4e81032e1a751758edde913585b8d0d3107ad377abf4bef8
6
+ metadata.gz: 6b9b9cb1822facd4f090cda89d973a91ba7ae4f9ead8427dd6efadeaa0d2912c36ed272b2fb57860a6230bbf269d21a105be90b13e8c69cd78a8135307288271
7
+ data.tar.gz: f50b49ed2fd3cf5589ba7c2f7803285c9b3fc349531baf730597d155a84267c0c9b18946d5a0fc4db3d86b7b343f5da723b79ecc398db3f412401774f52ca65b
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # 1.1.3 (25th June 2014)
2
+ * Fixed nested hash to url_encoded
3
+
4
+ # 1.1.2 (17th February 2014)
5
+ * Added logs
6
+
7
+ # 1.1.1 (31st December 2014)
8
+ * First stable version
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
@@ -1,5 +1,5 @@
1
1
  module Grape
2
2
  module Batch
3
- VERSION = '1.1.2'
3
+ VERSION = '1.1.3'
4
4
  end
5
5
  end
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."
@@ -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.2
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-02-17 00:00:00.000000000 Z
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