Sha256: 708e58fb50ec0efa8554dea3f0f14e3dee88ac4dd8da575ad4bb7f17fa318795

Contents?: true

Size: 951 Bytes

Versions: 7

Compression:

Stored size: 951 Bytes

Contents

module Whatser
  module Http
    include HTTParty
    
    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={}, options={})
      params ||= {}
      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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
whatser-0.6.1 lib/whatser/net/http.rb
whatser-0.6.0 lib/whatser/net/http.rb
whatser-0.5.0 lib/whatser/net/http.rb
whatser-0.4.0 lib/whatser/net/http.rb
whatser-0.3.2 lib/whatser/net/http.rb
whatser-0.3.1 lib/whatser/net/http.rb
whatser-0.3.0 lib/whatser/net/http.rb