flexirest 1.2.18 → 1.2.19
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 +13 -0
- data/lib/flexirest/request.rb +6 -2
- data/lib/flexirest/version.rb +1 -1
- data/spec/lib/request_spec.rb +16 -1
- 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: bd0763762a7ac0ddc9a4b65deb81f2351434bb27
|
4
|
+
data.tar.gz: 4c67c29342a607fdddefa1f3685f3694a6ce0f30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e68fc41d9dae157ce978fc60990b9394c393c1781858190abc01e0f63570584846cc52f6f9434bc6efab3a3c7c528365f91c575b2dcf3ca6ea109a2b3478640
|
7
|
+
data.tar.gz: b5d25f4aeb33ad3265f690efcabd0cca78687097cd82b133afbcc3095fb61e73be17cf6ec256a72720c95de68b488b84c007a74cac61e10993a0705b0c01326b
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -746,6 +746,19 @@ end
|
|
746
746
|
@people = Person.all(active:false)
|
747
747
|
```
|
748
748
|
|
749
|
+
If you specify `defaults` as a `Proc` this will be executed with the set parameters (which you can change). For example to allow you to specify a reference (but the API wants it formated as "id-reference") you could use:
|
750
|
+
|
751
|
+
```ruby
|
752
|
+
class Person < Flexirest::Base
|
753
|
+
get :all, "/", defaults: (Proc.new do |params|
|
754
|
+
reference = params.delete(:reference) # Delete the old parameter
|
755
|
+
{
|
756
|
+
id: "id-#{reference}"
|
757
|
+
} # The last thing is the hash of defaults
|
758
|
+
end)
|
759
|
+
end
|
760
|
+
```
|
761
|
+
|
749
762
|
### Required Parameters
|
750
763
|
|
751
764
|
If you want to specify that certain parameters are required for a specific call, you can specify them like:
|
data/lib/flexirest/request.rb
CHANGED
@@ -215,7 +215,11 @@ module Flexirest
|
|
215
215
|
params = {id:params}
|
216
216
|
end
|
217
217
|
|
218
|
-
|
218
|
+
if @method[:options][:defaults].respond_to?(:call)
|
219
|
+
default_params = @method[:options][:defaults].call(params)
|
220
|
+
else
|
221
|
+
default_params = @method[:options][:defaults] || {}
|
222
|
+
end
|
219
223
|
|
220
224
|
if @explicit_parameters
|
221
225
|
params = @explicit_parameters
|
@@ -519,7 +523,7 @@ module Flexirest
|
|
519
523
|
if @method[:options][:has_many][name] || @method[:options][:has_one][name]
|
520
524
|
return name
|
521
525
|
end
|
522
|
-
|
526
|
+
|
523
527
|
parent_name || name
|
524
528
|
end
|
525
529
|
|
data/lib/flexirest/version.rb
CHANGED
data/spec/lib/request_spec.rb
CHANGED
@@ -48,6 +48,16 @@ describe Flexirest::Request do
|
|
48
48
|
get :all, "/"
|
49
49
|
end
|
50
50
|
|
51
|
+
class ProcDefaultExampleClient < Flexirest::Base
|
52
|
+
base_url "http://www.example.com"
|
53
|
+
get :all, "/", defaults: (Proc.new do |params|
|
54
|
+
reference = params.delete(:reference)
|
55
|
+
{
|
56
|
+
id: "id-#{reference}"
|
57
|
+
}
|
58
|
+
end)
|
59
|
+
end
|
60
|
+
|
51
61
|
class LazyLoadedExampleClient < ExampleClient
|
52
62
|
base_url "http://www.example.com"
|
53
63
|
lazy_load!
|
@@ -115,6 +125,11 @@ describe Flexirest::Request do
|
|
115
125
|
ExampleClient.defaults overwrite:"yes"
|
116
126
|
end
|
117
127
|
|
128
|
+
it "should pass through get parameters, calling the proc if one is specified for defaults" do
|
129
|
+
expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/?id=id-123456", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
|
130
|
+
ProcDefaultExampleClient.all reference:"123456"
|
131
|
+
end
|
132
|
+
|
118
133
|
it "should ensure any required parameters are specified" do
|
119
134
|
expect_any_instance_of(Flexirest::Connection).to_not receive(:get)
|
120
135
|
expect{ExampleClient.requires}.to raise_error(Flexirest::MissingParametersException)
|
@@ -262,7 +277,7 @@ describe Flexirest::Request do
|
|
262
277
|
expect(object[1].first_name).to eq("Billy")
|
263
278
|
expect(object._status).to eq(200)
|
264
279
|
end
|
265
|
-
|
280
|
+
|
266
281
|
it "should parse an attribute to be an array if attribute included in array option" do
|
267
282
|
expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/johnny", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"Johnny\", \"likes\":[\"donuts\", \"bacon\"], \"dislikes\":[\"politicians\", \"lawyers\", \"taxes\"]}", status:200, response_headers:{})))
|
268
283
|
object = ExampleClient.array
|
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.2.
|
4
|
+
version: 1.2.19
|
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-02-
|
11
|
+
date: 2016-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|