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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +27 -0
- data/lib/flexirest/request.rb +5 -1
- data/lib/flexirest/version.rb +1 -1
- data/spec/lib/request_spec.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e651c2b737f396357909fdc4aaab2d28997ee1f
|
4
|
+
data.tar.gz: e38300b96dcace5b1da4f5d81c7d523f3304e6e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a358ba93a1e908eac336bed2c07697d77b7e1a780da1b1059d5c7c7de4caa9e50dd9a7f40f19ed1f835f927d3208029dd70cc87c75b73657c45f9d2e4620f8c0
|
7
|
+
data.tar.gz: a616506f250aa49f5e517542b170a338d24ec10683c0db9e1be9081ac87ee8cf586c4355b291e7fa9b0af501fa9a3cada17c695a6095534d5b2d1e95ba7dff8a
|
data/CHANGELOG.md
CHANGED
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¶m[]=2¶m[]=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¶m=2¶m=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:
|
data/lib/flexirest/request.rb
CHANGED
@@ -266,7 +266,11 @@ module Flexirest
|
|
266
266
|
|
267
267
|
def append_get_parameters
|
268
268
|
if @get_params.any?
|
269
|
-
@
|
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
|
|
data/lib/flexirest/version.rb
CHANGED
data/spec/lib/request_spec.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2016-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|