class DeskLight::Response

Attributes

body[R]
code[R]
either[R]
headers[R]
json[R]
limit[R]
remaining[R]
reset[R]
time[R]

Public Class Methods

new(_response, _time = nil) click to toggle source
# File lib/desk_light/response.rb, line 16
def initialize _response, _time = nil
  @limit = _response['x-rate-limit-limit']
  @limit = @limit.to_i if @limit
  @remaining = _response['x-rate-limit-remaining']
  @remaining = @remaining.to_i if @remaining
  @reset = _response['x-rate-limit-reset']
  @reset = @reset.to_i if @reset
  @code = _response.code.to_i
  if content_type = _response['content-type']
    if content_type.include?("application/json")
      begin
        @json = JSON.parse(_response.body)
      rescue
        @json = nil
      end
    end
  else
    @json = nil
  end
  @body = _response.body
  @either = @json || @body
  @time = (Time.now - _time).to_f if _time
  @headers = {}
  _response.each do |key,val|
    @headers.merge!(key => val)
  end
end