Class: DeskLight::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/desk_light/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_response, _time = nil) ⇒ Response

Returns a new instance of Response.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 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

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



11
12
13
# File 'lib/desk_light/response.rb', line 11

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



6
7
8
# File 'lib/desk_light/response.rb', line 6

def code
  @code
end

#eitherObject (readonly)

Returns the value of attribute either.



12
13
14
# File 'lib/desk_light/response.rb', line 12

def either
  @either
end

#headersObject (readonly)

Returns the value of attribute headers.



14
15
16
# File 'lib/desk_light/response.rb', line 14

def headers
  @headers
end

#jsonObject (readonly)

Returns the value of attribute json.



7
8
9
# File 'lib/desk_light/response.rb', line 7

def json
  @json
end

#limitObject (readonly)

Returns the value of attribute limit.



8
9
10
# File 'lib/desk_light/response.rb', line 8

def limit
  @limit
end

#remainingObject (readonly)

Returns the value of attribute remaining.



9
10
11
# File 'lib/desk_light/response.rb', line 9

def remaining
  @remaining
end

#resetObject (readonly)

Returns the value of attribute reset.



10
11
12
# File 'lib/desk_light/response.rb', line 10

def reset
  @reset
end

#timeObject (readonly)

Returns the value of attribute time.



13
14
15
# File 'lib/desk_light/response.rb', line 13

def time
  @time
end