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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 951a773aca32f3710bae2ee3ed2f4a34c4ee9232
4
- data.tar.gz: d0857284056ec1f1c6b563e1d67f92c8fcae81bd
3
+ metadata.gz: bd0763762a7ac0ddc9a4b65deb81f2351434bb27
4
+ data.tar.gz: 4c67c29342a607fdddefa1f3685f3694a6ce0f30
5
5
  SHA512:
6
- metadata.gz: 29904f4d2b02428fbb1d056667c3ade2bf42cae9f859e4f328c4cd3ebde47a57160f6c8df00fab0f4967e23cc734bbd26f27e54714b6ebbdb4b46a53986f92fa
7
- data.tar.gz: bf945048697c7dc7aa235cc4ef4fffe6a5d6260731d806395f413b797f05e95aa4b1d5f1ab9d1b58f02880bf5c53dd3ca5a14bf4dda1a0673eba34d7c4eac522
6
+ metadata.gz: 7e68fc41d9dae157ce978fc60990b9394c393c1781858190abc01e0f63570584846cc52f6f9434bc6efab3a3c7c528365f91c575b2dcf3ca6ea109a2b3478640
7
+ data.tar.gz: b5d25f4aeb33ad3265f690efcabd0cca78687097cd82b133afbcc3095fb61e73be17cf6ec256a72720c95de68b488b84c007a74cac61e10993a0705b0c01326b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.19
4
+
5
+ Features:
6
+
7
+ - Allow procs in defaults to be able to use params (for Michael Mealling)
8
+
3
9
  ## 1.2.18
4
10
 
5
11
  Features:
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:
@@ -215,7 +215,11 @@ module Flexirest
215
215
  params = {id:params}
216
216
  end
217
217
 
218
- default_params = @method[:options][:defaults] || {}
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
 
@@ -1,3 +1,3 @@
1
1
  module Flexirest
2
- VERSION = "1.2.18"
2
+ VERSION = "1.2.19"
3
3
  end
@@ -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.18
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-08 00:00:00.000000000 Z
11
+ date: 2016-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler