Class: Zenlight::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_response, _time = nil) ⇒ Response

Returns a new instance of Response.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/zenlight/response.rb', line 15

def initialize _response, _time = nil
  @limit = _response.headers[:x_rate_limit] || _response.headers[:x_ratelimit_limit_minute] || _response.headers[:x_ratelimit_total]
  @limit = @limit.to_i if @limit
  @remaining = _response.headers[:x_rate_limit_remaining] || _response.headers[:x_ratelimit_remaining_minute] || _response.headers[:x_ratelimit_remaining]
  @remaining = @remaining.to_i if @remaining
  @code = _response.code.to_i
  if content_type = _response.headers[: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.headers
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

#eitherObject (readonly)

Returns the value of attribute either.



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

def either
  @either
end

#headersObject (readonly)

Returns the value of attribute headers.



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

def headers
  @headers
end

#jsonObject (readonly)

Returns the value of attribute json.



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

def json
  @json
end

#limitObject (readonly)

Returns the value of attribute limit.



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

def limit
  @limit
end

#remainingObject (readonly)

Returns the value of attribute remaining.



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

def remaining
  @remaining
end

#timeObject (readonly)

Returns the value of attribute time.



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

def time
  @time
end