Class: Zenlight::Response
- Inherits:
-
Object
- Object
- Zenlight::Response
- Defined in:
- lib/zenlight/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#either ⇒ Object
readonly
Returns the value of attribute either.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#json ⇒ Object
readonly
Returns the value of attribute json.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#remaining ⇒ Object
readonly
Returns the value of attribute remaining.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
-
#initialize(_response, _time = nil) ⇒ Response
constructor
A new instance of Response.
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
#body ⇒ Object (readonly)
Returns the value of attribute body.
10 11 12 |
# File 'lib/zenlight/response.rb', line 10 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
6 7 8 |
# File 'lib/zenlight/response.rb', line 6 def code @code end |
#either ⇒ Object (readonly)
Returns the value of attribute either.
11 12 13 |
# File 'lib/zenlight/response.rb', line 11 def either @either end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
13 14 15 |
# File 'lib/zenlight/response.rb', line 13 def headers @headers end |
#json ⇒ Object (readonly)
Returns the value of attribute json.
7 8 9 |
# File 'lib/zenlight/response.rb', line 7 def json @json end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
8 9 10 |
# File 'lib/zenlight/response.rb', line 8 def limit @limit end |
#remaining ⇒ Object (readonly)
Returns the value of attribute remaining.
9 10 11 |
# File 'lib/zenlight/response.rb', line 9 def remaining @remaining end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
12 13 14 |
# File 'lib/zenlight/response.rb', line 12 def time @time end |