flexirest 1.3.9 → 1.3.10

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: 8a9faf13ef3eccc8b4e00f771eac639c048eebac
4
- data.tar.gz: 97436ce0b23e2edf6c56c88cf32f3bea86f86d3d
3
+ metadata.gz: 5e651c2b737f396357909fdc4aaab2d28997ee1f
4
+ data.tar.gz: e38300b96dcace5b1da4f5d81c7d523f3304e6e7
5
5
  SHA512:
6
- metadata.gz: 01e5b88653f5b6f0c943dd0c742dd1320b27371b244bda060ad7af86cf5ec0df8f41ce9a2a42137a7849e4460af72f3c85bf379eb923592003d061c964319b30
7
- data.tar.gz: cd4c7b5d05801455c9956d0edd64134471525f8900d594b0d0b9b99b1042059f2db7009f7b56d85d5b14f7ef65708be42b2c10118c5dba86b8d13fefbc01406b
6
+ metadata.gz: a358ba93a1e908eac336bed2c07697d77b7e1a780da1b1059d5c7c7de4caa9e50dd9a7f40f19ed1f835f927d3208029dd70cc87c75b73657c45f9d2e4620f8c0
7
+ data.tar.gz: a616506f250aa49f5e517542b170a338d24ec10683c0db9e1be9081ac87ee8cf586c4355b291e7fa9b0af501fa9a3cada17c695a6095534d5b2d1e95ba7dff8a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.3.10
4
+
5
+ Feature:
6
+
7
+ - Added per-request params encoding so you can choose between `param[]=foo&param[]=bar` or `param=foo&param=bar` (thanks to bkubic for the PR).
8
+
3
9
  ## 1.3.9
4
10
 
5
11
  Feature:
data/README.md CHANGED
@@ -617,6 +617,33 @@ class Person < Flexirest::Base
617
617
  end
618
618
  ```
619
619
 
620
+ ### Per-request Params Encoding
621
+
622
+ When url-encoding get parameters, Rudy adds brackets([]) by default to any parameters in an Array. For example, if you tried to pass these parameters:
623
+
624
+ ```ruby
625
+ Person.all(param: [1, 2, 3])
626
+ ```
627
+
628
+ Ruby would encode the url as
629
+
630
+ ```
631
+ ?param[]=1&param[]=2&param[]=3
632
+ ```
633
+
634
+ If you prefer flattened notation instead, pass a `params_encoder` option of `:flat` when mapping the call. So this call:
635
+
636
+ ```ruby
637
+ class Person < Flexirest::Base
638
+ get :all, '/people', params_encoder: :flat
639
+ end
640
+ ```
641
+ would output the following url
642
+
643
+ ```
644
+ ?param=1&param=2&param=3
645
+ ```
646
+
620
647
  ### Raw Requests
621
648
 
622
649
  Sometimes you have have a URL that you just want to force through, but have the response handled in the same way as normal objects or you want to have the filters run (say for authentication). The easiest way to do that is to call `_request` on the class:
@@ -266,7 +266,11 @@ module Flexirest
266
266
 
267
267
  def append_get_parameters
268
268
  if @get_params.any?
269
- @url += "?" + @get_params.to_query
269
+ if @method[:options][:params_encoder] == :flat
270
+ @url += "?" + URI.encode_www_form(@get_params)
271
+ else
272
+ @url += "?" + @get_params.to_query
273
+ end
270
274
  end
271
275
  end
272
276
 
@@ -1,3 +1,3 @@
1
1
  module Flexirest
2
- VERSION = "1.3.9"
2
+ VERSION = "1.3.10"
3
3
  end
@@ -22,6 +22,7 @@ describe Flexirest::Request do
22
22
  end
23
23
 
24
24
  get :all, "/", :has_many => {:expenses => ExampleOtherClient}
25
+ get :flat, "/", :params_encoder => :flat
25
26
  get :array, "/johnny", array: [:likes, :dislikes]
26
27
  get :babies, "/babies", :has_many => {:children => ExampleOtherClient}
27
28
  get :single_association, "/single", :has_one => {:single => ExampleSingleClient}, :has_many => {:children => ExampleOtherClient}
@@ -188,6 +189,11 @@ describe Flexirest::Request do
188
189
  ExampleClient.all :include => [:your,:friends]
189
190
  end
190
191
 
192
+ it "should pass through 'array type' get parameters using the same parameter name if a flat param_encoder is chosen" do
193
+ expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/?include=your&include=friends", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"result\":true}", response_headers:{})))
194
+ ExampleClient.flat :include => [:your,:friends]
195
+ end
196
+
191
197
  it "should encode the body in a form-encoded format by default" do
192
198
  expect_any_instance_of(Flexirest::Connection).to receive(:put).with("/put/1234", "debug=true&test=foo", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"result\":true}", response_headers:{})))
193
199
  ExampleClient.update id:1234, debug:true, test:'foo'
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.3.9
4
+ version: 1.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-08 00:00:00.000000000 Z
11
+ date: 2016-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler