Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Commits on Sep 10, 2012
@pranas pranas Allow to implement caching in instrumentation. 408b441
Commits on Sep 15, 2012
@Sutto Merge pull request #5 from Pranas/better_instrumentation
Allow to implement caching in instrumentation
c54cd7f
Showing with 17 additions and 4 deletions.
  1. +3 −4 lib/api_smith/client.rb
  2. +14 −0 spec/api_smith/client_spec.rb
View
7 lib/api_smith/client.rb
@@ -112,9 +112,8 @@ def request!(method, path, options, *param_types)
request_options[type] = merged_options_for(type, options)
end
# Finally, use HTTParty to get the response
- response = nil
- instrument_request method, full_path, options do
- response = self.class.send method, full_path, request_options
+ response = instrument_request method, full_path, options do
+ self.class.send method, full_path, request_options
end
# Pre-process the response to check for errors.
check_response_errors response
@@ -348,4 +347,4 @@ def persistent(value = true, name = 'api_smith')
end
end
-end
+end
View
14 spec/api_smith/client_spec.rb
@@ -12,6 +12,20 @@
let(:client) { client_klass.new }
+ describe 'instrumentation' do
+ subject do
+ Class.new(client_klass) do
+ def instrument_request(*args)
+ 'custom_response'
+ end
+ end.new
+ end
+
+ it 'should allow you to customize reponse' do
+ subject.get('/echo').should == 'custom_response'
+ end
+ end
+
it 'should let you provide instrumentation' do
second_klass = Class.new(client_klass) do
attr_accessor :hits

No commit comments for this range

Something went wrong with that request. Please try again.