Class: ScormEngine::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_response:, result: nil) ⇒ Response

Returns a new instance of Response.



5
6
7
8
# File 'lib/scorm_engine/response.rb', line 5

def initialize(raw_response:, result: nil)
  @raw_response = raw_response
  @result = result
end

Instance Attribute Details

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



3
4
5
# File 'lib/scorm_engine/response.rb', line 3

def raw_response
  @raw_response
end

#resultObject (readonly)

Returns the value of attribute result.



3
4
5
# File 'lib/scorm_engine/response.rb', line 3

def result
  @result
end

Instance Method Details

#bodyObject



18
19
20
# File 'lib/scorm_engine/response.rb', line 18

def body
  raw_response.body
end

#detailed_error_infoObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/scorm_engine/response.rb', line 30

def detailed_error_info
  return "Success" if success?

  headers_hash = begin
    raw_response.headers.to_hash
  rescue NoMethodError
    raw_response.headers
  end

  error_info = {
    status: status,
    message: message,
    body: raw_response.body,
    headers: headers_hash
  }

  error_info.inspect
end

#messageObject



26
27
28
# File 'lib/scorm_engine/response.rb', line 26

def message
  raw_response.body["message"] if raw_response.body.is_a?(Hash)
end

#resultsObject



22
23
24
# File 'lib/scorm_engine/response.rb', line 22

def results
  result.is_a?(Enumerator) ? result : Array(result)
end

#statusObject



14
15
16
# File 'lib/scorm_engine/response.rb', line 14

def status
  raw_response.status
end

#success?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/scorm_engine/response.rb', line 10

def success?
  raw_response.success?
end