Class: D2L::Valence::Response
- Inherits:
-
Object
- Object
- D2L::Valence::Response
- Defined in:
- lib/d2l/valence/response.rb
Overview
Response
Class for interpreting the response from the D2L Valence API
Instance Attribute Summary collapse
-
#http_response ⇒ Object
readonly
Returns the value of attribute http_response.
Instance Method Summary collapse
-
#body ⇒ String
Plain text response from the D2L server.
-
#code ⇒ Symbol
The interpreted code for the Valance API response.
-
#initialize(http_response) ⇒ Response
constructor
A new instance of Response.
-
#server_skew ⇒ Integer
The difference in D2L Valance API Server time and local time.
-
#to_hash ⇒ Hash
Generates a hash based on a valid JSON response from the D2L server.
Constructor Details
#initialize(http_response) ⇒ Response
Returns a new instance of Response.
9 10 11 12 |
# File 'lib/d2l/valence/response.rb', line 9 def initialize(http_response) @http_response = http_response @server_skew = 0 end |
Instance Attribute Details
#http_response ⇒ Object (readonly)
Returns the value of attribute http_response.
6 7 8 |
# File 'lib/d2l/valence/response.rb', line 6 def http_response @http_response end |
Instance Method Details
#body ⇒ String
Returns Plain text response from the D2L server.
15 16 17 |
# File 'lib/d2l/valence/response.rb', line 15 def body @http_response.body end |
#code ⇒ Symbol
Returns the interpreted code for the Valance API response.
30 31 32 |
# File 'lib/d2l/valence/response.rb', line 30 def code interpret_forbidden || http_code end |
#server_skew ⇒ Integer
Returns the difference in D2L Valance API Server time and local time.
35 36 37 38 39 |
# File 'lib/d2l/valence/response.rb', line 35 def server_skew return 0 unless . @server_skew = .server_skew end |
#to_hash ⇒ Hash
Generates a hash based on a valid JSON response from the D2L server. If the provided response is not in a value JSON format then an empty hash is returned
23 24 25 26 27 |
# File 'lib/d2l/valence/response.rb', line 23 def to_hash @to_hash ||= JSON.parse(body) rescue @to_hash = {} end |