Class: DeskLight::Response
- Inherits:
-
Object
- Object
- DeskLight::Response
- Defined in:
- lib/desk_light/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.
-
#reset ⇒ Object
readonly
Returns the value of attribute reset.
-
#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.
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
#body ⇒ Object (readonly)
Returns the value of attribute body.
11 12 13 |
# File 'lib/desk_light/response.rb', line 11 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
6 7 8 |
# File 'lib/desk_light/response.rb', line 6 def code @code end |
#either ⇒ Object (readonly)
Returns the value of attribute either.
12 13 14 |
# File 'lib/desk_light/response.rb', line 12 def either @either end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
14 15 16 |
# File 'lib/desk_light/response.rb', line 14 def headers @headers end |
#json ⇒ Object (readonly)
Returns the value of attribute json.
7 8 9 |
# File 'lib/desk_light/response.rb', line 7 def json @json end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
8 9 10 |
# File 'lib/desk_light/response.rb', line 8 def limit @limit end |
#remaining ⇒ Object (readonly)
Returns the value of attribute remaining.
9 10 11 |
# File 'lib/desk_light/response.rb', line 9 def remaining @remaining end |
#reset ⇒ Object (readonly)
Returns the value of attribute reset.
10 11 12 |
# File 'lib/desk_light/response.rb', line 10 def reset @reset end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
13 14 15 |
# File 'lib/desk_light/response.rb', line 13 def time @time end |