class D2L::Valence::Response
Response
¶ ↑
Class for interpreting the response from the D2L
Valence
API
Attributes
http_response[R]
Public Class Methods
new(http_response)
click to toggle source
@param [RestClient::Response] http_response
response from a request against the Valance API
# File lib/d2l/valence/response.rb, line 9 def initialize(http_response) @http_response = http_response @server_skew = 0 end
Public Instance Methods
body()
click to toggle source
@return [String] Plain text response from the D2L
server
# File lib/d2l/valence/response.rb, line 15 def body @http_response.body end
code()
click to toggle source
@return [Symbol] the interpreted code for the Valance API response
# File lib/d2l/valence/response.rb, line 30 def code interpret_forbidden || http_code end
server_skew()
click to toggle source
@return [Integer] the difference in D2L
Valance API Server time and local time
# File lib/d2l/valence/response.rb, line 35 def server_skew return 0 unless timestamp_error.timestamp_out_of_range? @server_skew = timestamp_error.server_skew end
to_hash()
click to toggle source
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
@return [Hash] hash based on JSON body
# File lib/d2l/valence/response.rb, line 23 def to_hash @to_hash ||= JSON.parse(body) rescue @to_hash = {} end
Private Instance Methods
http_code()
click to toggle source
# File lib/d2l/valence/response.rb, line 43 def http_code "HTTP_#{@http_response.code}".to_sym end
interpret_forbidden()
click to toggle source
# File lib/d2l/valence/response.rb, line 47 def interpret_forbidden return unless @http_response.code == 403 invalid_timestamp || invalid_token end
invalid_timestamp()
click to toggle source
# File lib/d2l/valence/response.rb, line 53 def invalid_timestamp :INVALID_TIMESTAMP if timestamp_error.timestamp_out_of_range? end
invalid_token()
click to toggle source
# File lib/d2l/valence/response.rb, line 61 def invalid_token :INVALID_TOKEN if @http_response.body.include? 'invalid token' end
timestamp_error()
click to toggle source
# File lib/d2l/valence/response.rb, line 57 def timestamp_error @timestamp_error ||= TimestampError.new(@http_response.body) end