active_rest_client 1.0.0 → 1.0.1

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: 8a08be2e09a1d1735079f01e268c5ac7754ac833
4
- data.tar.gz: ea067f45bc4cf459dfb48a149db5ef9c93e2b2b0
3
+ metadata.gz: 287ff0756e1a325c054bb32e601270ebe459b6c9
4
+ data.tar.gz: 28d6c1a06dde0da5872a96683731ad07741e0159
5
5
  SHA512:
6
- metadata.gz: 816c956a1ccb86051b880b4e3896d189b3953a0d8de0ba35ab05278b783d57ef267a3cb9550f1fff319e5609169f446ce1ddadd0d1ce3c6664e5c9913f82c743
7
- data.tar.gz: 13004f6d21ada93a9c0d3b1eaf57c69d16c08ef9aac1fc90eefc8feb54b04106537712c7a699ae5c3b1dd01bce6c1666cf7287c1154f9ac39079f81dfd6622cf
6
+ metadata.gz: 0081d8815d8bfa568980695683ae889afc68c6f782acfc6759b166f205d0b033c5788ee8973e6ac2e66abd42c9906affbe0913ec71064532009b1626427638f8
7
+ data.tar.gz: 518e02c69f5239f0528d57dfaba126224dc1e0a4b766d8920a6df50bdfecf3b15d05dd3e4c170c16b23ac70614db98573790a8790cff1c70f1cfd4477e477039
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # ActiveRestClient
2
2
 
3
- [![Build Status](https://travis-ci.org/whichdigital/active-rest-client.png?branch=master)](https://travis-ci.org/whichdigital/active-rest-client) [![Coverage Status](https://coveralls.io/repos/whichdigital/active-rest-client/badge.png)](https://coveralls.io/r/whichdigital/active-rest-client) [![Code Climate](https://codeclimate.com/github/whichdigital/active-rest-client.png)](https://codeclimate.com/github/whichdigital/active-rest-client) [![Gem Version](https://badge.fury.io/rb/active_rest_client.png)](http://badge.fury.io/rb/active_rest_client)
3
+ [![Build Status](https://travis-ci.org/whichdigital/active-rest-client.svg?branch=master)](https://travis-ci.org/whichdigital/active-rest-client)
4
+ [![Coverage Status](https://coveralls.io/repos/whichdigital/active-rest-client/badge.png)](https://coveralls.io/r/whichdigital/active-rest-client)
5
+ [![Code Climate](https://codeclimate.com/github/whichdigital/active-rest-client.png)](https://codeclimate.com/github/whichdigital/active-rest-client)
6
+ [![Gem Version](https://badge.fury.io/rb/active_rest_client.png)](http://badge.fury.io/rb/active_rest_client)
4
7
 
5
8
  This gem is for accessing REST services in an ActiveRecord style. ActiveResource already exists for this, but it doesn't work where the resource naming doesn't follow Rails conventions, it doesn't have in-built caching and it's not as flexible in general.
6
9
 
@@ -116,7 +116,7 @@ module ActiveRestClient
116
116
  etag = cached.etag
117
117
  response = do_request(etag)
118
118
  if response.status == 304
119
- ActiveRestClient::Logger.debug " \033[1;4;32m#{ActiveRestClient::NAME}\033[0m #{@instrumentation_name} - Response status 304. Copy is still fresh"
119
+ ActiveRestClient::Logger.debug " \033[1;4;32m#{ActiveRestClient::NAME}\033[0m #{@instrumentation_name} - Etag copy is the same as the server"
120
120
  return handle_cached_response(cached)
121
121
  end
122
122
  end
@@ -132,9 +132,6 @@ module ActiveRestClient
132
132
  @object.record_response(self.url, response)
133
133
  end
134
134
  result = handle_response(response)
135
- if result == :not_modified && cached
136
- result = cached.result
137
- end
138
135
  original_object_class.write_cached_response(self, response, result)
139
136
  result
140
137
  end
@@ -230,7 +227,7 @@ module ActiveRestClient
230
227
  if verbose?
231
228
  ActiveRestClient::Logger.debug "ActiveRestClient Verbose Log:"
232
229
  ActiveRestClient::Logger.debug " Request"
233
- ActiveRestClient::Logger.debug " >> GET #{@url} HTTP/1.1"
230
+ ActiveRestClient::Logger.debug " >> #{http_method.upcase} #{@url} HTTP/1.1"
234
231
  http_headers.each do |k,v|
235
232
  ActiveRestClient::Logger.debug " >> #{k} : #{v}"
236
233
  end
@@ -280,10 +277,6 @@ module ActiveRestClient
280
277
  @response.status ||= 200
281
278
 
282
279
  if (200..399).include? @response.status
283
- if response.status == 304
284
- ActiveRestClient::Logger.debug " \033[1;4;32m#{ActiveRestClient::NAME}\033[0m #{@instrumentation_name} - Etag copy is the same as the server"
285
- return :not_modified
286
- end
287
280
  if @method[:options][:plain]
288
281
  return @response = response.body
289
282
  elsif is_json_response?
@@ -1,3 +1,3 @@
1
1
  module ActiveRestClient
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -37,6 +37,7 @@ describe ActiveRestClient::Request do
37
37
  base_url "http://www.example.com"
38
38
  verbose!
39
39
  get :all, "/all"
40
+ post :create, "/create"
40
41
  end
41
42
 
42
43
  class FilteredBodyExampleClient < ExampleClient
@@ -164,7 +165,7 @@ describe ActiveRestClient::Request do
164
165
  it "should log faked responses" do
165
166
  ActiveRestClient::Logger.stub(:debug)
166
167
  ActiveRestClient::Logger.should_receive(:debug).with {|*args| args.first["Faked response found"]}
167
- object = ExampleClient.fake id:1234, debug:true
168
+ ExampleClient.fake id:1234, debug:true
168
169
  end
169
170
 
170
171
  it "should parse an array within JSON to be a result iterator" do
@@ -208,7 +209,7 @@ describe ActiveRestClient::Request do
208
209
  with("/create", "first_name=John&should_disappear=true", an_instance_of(Hash)).
209
210
  and_return(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", headers:{}, status:200))
210
211
  ActiveRestClient::Logger.should_receive(:info).with {|*args| args.first[%r{Requesting http://www.example.com/create}]}
211
- ActiveRestClient::Logger.should_receive(:debug).at_least(1).times.with {|*args| args.first[/Response received \d+ bytes/] || args.first["Reading from cache"]}
212
+ ActiveRestClient::Logger.should_receive(:debug).at_least(1).times.with {|*args| args.first[/Response received \d+ bytes/] || args.first["Trying to read from cache"]}
212
213
 
213
214
  object = ExampleClient.new(first_name:"John", should_disappear:true)
214
215
  object.create
@@ -222,12 +223,25 @@ describe ActiveRestClient::Request do
222
223
  with("/create", "first_name=John&should_disappear=true", an_instance_of(Hash)).
223
224
  and_return(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", headers:{}, status:200))
224
225
  ActiveRestClient::Logger.should_receive(:info).with {|*args| args.first[%r{Requesting http://www.example.com/create}]}
225
- ActiveRestClient::Logger.should_receive(:debug).at_least(1).times.with {|*args| args.first[/Response received \d+ bytes/] || args.first["Reading from cache"]}
226
+ ActiveRestClient::Logger.should_receive(:debug).at_least(1).times.with {|*args| args.first[/Response received \d+ bytes/] || args.first["Trying to read from cache"]}
226
227
 
227
228
  object = ExampleClient.new(first_name:"John", should_disappear:true)
228
229
  object.create
229
230
  end
230
231
 
232
+ it "should verbose debug the with the right http verb" do
233
+ ActiveRestClient::Connection.
234
+ any_instance.
235
+ should_receive(:post).
236
+ with("/create", "first_name=John&should_disappear=true", an_instance_of(Hash)).
237
+ and_return(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", headers:{}, status:200))
238
+ ActiveRestClient::Logger.should_receive(:debug).with(/ POST /)
239
+ ActiveRestClient::Logger.stub(:debug).with(any_args)
240
+
241
+ object = VerboseExampleClient.new(first_name:"John", should_disappear:true)
242
+ object.create
243
+ end
244
+
231
245
  it "should verbose log if enabled" do
232
246
  connection = double(ActiveRestClient::Connection).as_null_object
233
247
  ActiveRestClient::ConnectionManager.should_receive(:get_connection).and_return(connection)
@@ -459,7 +473,7 @@ describe ActiveRestClient::Request do
459
473
  connection.
460
474
  should_receive(:get).
461
475
  with("/some/url", an_instance_of(Hash)).
462
- and_return(OpenStruct.new(body:"", headers:{}, status:304))
476
+ and_return(OpenStruct.new(body:"{}", headers:{}, status:304))
463
477
  connection.
464
478
  stub(:base_url).
465
479
  and_return("http://other.example.com")
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: 1.0.0
4
+ version: 1.0.1
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-04-01 00:00:00.000000000 Z
12
+ date: 2014-04-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler