Class: Polar::Request
- Inherits:
-
Object
- Object
- Polar::Request
- Defined in:
- lib/polar/request.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(api_key, secret_key, session_key, params) ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize(api_key, secret_key, session_key, params) ⇒ Request
Returns a new instance of Request.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/polar/request.rb', line 11 def initialize(api_key, secret_key, session_key, params) @api_key, @session_key, @secret_key = api_key, session_key, secret_key conn = Faraday.new(:url => Polar::BASE_URL) do |c| c.use Faraday::Request::UrlEncoded c.use Faraday::Adapter::NetHttp end conn.headers["Content-Type"] = ["application/x-www-form-urlencoded"]; params[:api_key] = @api_key params[:call_id] = Time.now.to_i params[:session_key] = @session_key params[:format] = "JSON" params[:sig] = SignatureCalculator.new(@secret_key).calculate(params) raw_response = conn.post do |request| request.body = urlencode_params(params) end raise Polar::Error::HTTPError.new(raw_response.status) if (400..599).include?(raw_response.status) @response = JSON.parse(raw_response.body) raise Polar::Error::APIError.new(@response) if renren_api_error? end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
9 10 11 |
# File 'lib/polar/request.rb', line 9 def response @response end |