Class: CoachClient::Response

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

Overview

A response from RESTful request to the CyberCoach service.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header, body, code) ⇒ CoachClient::Response

Creates a new response.

Parameters:

  • header (String)

    the headers of the HTTP response

  • body (String)

    the body of the HTTP response

  • code (Integer)

    the HTTP response code



16
17
18
19
20
# File 'lib/coach_client/response.rb', line 16

def initialize(header, body, code)
  @header = header
  @body = body
  @code = code
end

Instance Attribute Details

#codeInteger (readonly)

Returns the HTTP code.

Returns:

  • (Integer)

    the HTTP code



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

def code
  @code
end

#headerString (readonly)

Returns the HTTP headers.

Returns:

  • (String)

    the HTTP headers



8
9
10
# File 'lib/coach_client/response.rb', line 8

def header
  @header
end

Instance Method Details

#to_hHash

Returns the body as Ruby Hash.

Returns:

  • (Hash)


25
26
27
# File 'lib/coach_client/response.rb', line 25

def to_h
  JSON.parse(@body, symbolize_names: true)
end

#to_sString

Returns the body as String.

Returns:

  • (String)


32
33
34
# File 'lib/coach_client/response.rb', line 32

def to_s
  @body.to_s
end