Class: D2L::Valence::Response

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

Overview

Response

Class for interpreting the response from the D2L Valence API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ Response

Returns a new instance of Response.

Parameters:

  • http_response (RestClient::Response)

    response from a request against the Valance API



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_responseObject (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

#bodyString

Returns Plain text response from the D2L server.

Returns:

  • (String)

    Plain text response from the D2L server



15
16
17
# File 'lib/d2l/valence/response.rb', line 15

def body
  @http_response.body
end

#codeSymbol

Returns the interpreted code for the Valance API response.

Returns:

  • (Symbol)

    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_skewInteger

Returns the difference in D2L Valance API Server time and local time.

Returns:

  • (Integer)

    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 timestamp_error.timestamp_out_of_range?

  @server_skew = timestamp_error.server_skew
end

#to_hashHash

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

Returns:

  • (Hash)

    hash based on JSON body



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