lib/whatser/net/http.rb in whatser-0.2.0 vs lib/whatser/net/http.rb in whatser-0.3.0

- old
+ new

@@ -5,22 +5,29 @@ def self.included(base) base_uri base.api_uri end def request(verb, path, params={}, options={}) + log("Whatser API Request: #{verb} @ #{path} with : #{params.to_s}") response = HTTParty.send( verb, compose_url(path), request_options( params ) ) + log("Whatser API Response: #{response.code} with : #{response.body.to_s}") + Whatser::Response.new( response.body, {:code => response.code}.merge(options) ) end private def compose_url(path) "#{api_uri}#{path}" end - def request_options(params={}) + def request_options(params={}, options={}) params ||= {} - return { :query => {:oauth_token => oauth_token}.merge(params[:query] || {}), - :body => params[:body] } + return { :query => query_options(params[:query], options), :body => params[:body] } + end + + def query_options(params, options={}) + base = options[:auth] == :key ? {:client_id => api_key} : {:oauth_token => oauth_token} + base.merge( params || {} ) end end end