active_rest_client 0.9.69 → 0.9.70

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: 663833914666ae9596d25fecc8c91470f6d11f31
4
- data.tar.gz: aeb47d9988874e5c9d7c44e21786b20ada6ed8c5
3
+ metadata.gz: 937a7fb9791b557ba265f3d538d78b193497c5c8
4
+ data.tar.gz: 41e9cf89ffb0d2f26339d8fa78b079eb0845c8cf
5
5
  SHA512:
6
- metadata.gz: 9a9159302d0244eb37fe0abe62b83d926c4f4c93afcf187b78671a0184e1ac9c3e8bc6cc9212793b8a9589425546223055bf1035e44ffa2250733e253829e35f
7
- data.tar.gz: 0471efd88e0348a3d14fb866fbce31057d17763a17d82b931169b1d0377f254c0d34ebd385919d2b0e4a148eb027d340dbfac669efb171fdef87816131271130
6
+ metadata.gz: dc629bf7df910f02a2b1d26d38beed6029e0e45c4ada2745d1138246221fe4e701f4dc97cfa676bd66a4f8b17a400727bd2b25b6f4f9aa4fb3d60f7210714050
7
+ data.tar.gz: d990eb013e401ab7c2b5a231e05d95548fce79bccc55946b2ff3402bc3f3802f92b2daa60e5c25ea83135f87172f2f59be75f2203c2482e23d46d3ae9fe18180
data/Guardfile CHANGED
@@ -1,7 +1,7 @@
1
1
  # A sample Guardfile
2
2
  # More info at https://github.com/guard/guard#readme
3
3
 
4
- guard :rspec do
4
+ guard :rspec, cmd: 'bundle exec rspec' do
5
5
  watch(%r{^spec/.*/*_spec\.rb$}) { "spec" }
6
6
  watch(%r{^lib/.*/(.+)\.rb$}) { "spec" }
7
7
  watch('spec/spec_helper.rb') { "spec" }
data/README.md CHANGED
@@ -384,7 +384,7 @@ end
384
384
 
385
385
  ### Faking Calls
386
386
 
387
- There are times when an API hasn't been developed yet, so you want to fake the API call response. To do this, simply pass a `fake` option when mapping the call containing the response.
387
+ There are times when an API hasn't been developed yet, so you want to fake the API call response. To do this, you can simply pass a `fake` option when mapping the call containing the response.
388
388
 
389
389
  ```ruby
390
390
  class Person < ActiveRestClient::Base
@@ -392,6 +392,14 @@ class Person < ActiveRestClient::Base
392
392
  end
393
393
  ```
394
394
 
395
+ You may want to run a proc when faking data (to put information from the parameters in to the response or return different responses depending on the parameters). To do this just pass a proc to :fake:
396
+
397
+ ```ruby
398
+ class Person < ActiveRestClient::Base
399
+ get :all, '/people', :fake => ->(request) { "{\"result\":#{request.get_params[:id]}}" }
400
+ end
401
+ ```
402
+
395
403
  ### Raw Requests
396
404
 
397
405
  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:
@@ -79,14 +79,17 @@ module ActiveRestClient
79
79
  result = nil
80
80
  cached = nil
81
81
  ActiveSupport::Notifications.instrument("request_call.active_rest_client", :name => @instrumentation_name) do
82
- if @method[:options][:fake]
83
- ActiveRestClient::Logger.debug " \033[1;4;32m#{ActiveRestClient::NAME}\033[0m #{@instrumentation_name} - Faked response found"
84
- return handle_response(OpenStruct.new(status:200, body:@method[:options][:fake], headers:{"X-ARC-Faked-Response" => "true"}))
85
- end
86
82
  @explicit_parameters = explicit_parameters
87
83
  @body = nil
88
84
  prepare_params
89
85
  prepare_url
86
+ if fake = @method[:options][:fake]
87
+ if fake.respond_to?(:call)
88
+ fake = fake.call(self)
89
+ end
90
+ ActiveRestClient::Logger.debug " \033[1;4;32m#{ActiveRestClient::NAME}\033[0m #{@instrumentation_name} - Faked response found"
91
+ return handle_response(OpenStruct.new(status:200, body:fake, headers:{"X-ARC-Faked-Response" => "true"}))
92
+ end
90
93
  if object_is_class?
91
94
  @object.send(:_filter_request, @method[:name], self)
92
95
  else
@@ -1,3 +1,3 @@
1
1
  module ActiveRestClient
2
- VERSION = "0.9.69"
2
+ VERSION = "0.9.70"
3
3
  end
@@ -21,6 +21,7 @@ describe ActiveRestClient::Request do
21
21
  delete :remove, "/remove/:id"
22
22
  get :hal, "/hal", fake:"{\"_links\":{\"child\": {\"href\": \"/child/1\"}, \"other\": {\"href\": \"/other/1\"}, \"cars\":[{\"href\": \"/car/1\", \"name\":\"car1\"}, {\"href\": \"/car/2\", \"name\":\"car2\"}, {\"href\": \"/car/not-embed\", \"name\":\"car_not_embed\"} ], \"lazy\": {\"href\": \"/lazy/load\"}, \"invalid\": [{\"href\": \"/invalid/1\"}]}, \"_embedded\":{\"other\":{\"name\":\"Jane\"},\"child\":{\"name\":\"Billy\"}, \"cars\":[{\"_links\": {\"self\": {\"href\": \"/car/1\"} }, \"make\": \"Bugatti\", \"model\": \"Veyron\"}, {\"_links\": {\"self\": {\"href\": \"/car/2\"} }, \"make\": \"Ferrari\", \"model\": \"F458 Italia\"} ], \"invalid\": [{\"present\":true, \"_links\": {} } ] } }", has_many:{other:ExampleOtherClient}
23
23
  get :fake, "/fake", fake:"{\"result\":true, \"list\":[1,2,3,{\"test\":true}], \"child\":{\"grandchild\":{\"test\":true}}}"
24
+ get :fake_proc, "/fake", fake:->(request) { "{\"result\":#{request.get_params[:id]}}" }
24
25
  get :defaults, "/defaults", defaults:{overwrite:"no", persist:"yes"}
25
26
  end
26
27
 
@@ -122,6 +123,11 @@ describe ActiveRestClient::Request do
122
123
  expect(object.child.grandchild.test).to eq(true)
123
124
  end
124
125
 
126
+ it "should parse JSON from a fake response generated by a proc" do
127
+ object = ExampleClient.fake_proc id:1234
128
+ expect(object.result).to eq(1234)
129
+ end
130
+
125
131
  it "should return a lazy loader object if lazy loading is enabled" do
126
132
  object = LazyLoadedExampleClient.fake id:1234, debug:true
127
133
  expect(object).to be_an_instance_of(ActiveRestClient::LazyLoader)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_rest_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.69
4
+ version: 0.9.70
5
5
  platform: ruby
6
6
  authors:
7
7
  - Which Ltd
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-28 00:00:00.000000000 Z
12
+ date: 2014-03-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler