Class: Direct::API::V5::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/direct/api/v5/response.rb

Defined Under Namespace

Classes: Error, Units

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, headers) ⇒ Response

Returns a new instance of Response.



6
7
8
9
# File 'lib/direct/api/v5/response.rb', line 6

def initialize(body, headers)
  @body = body
  @headers = headers
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/direct/api/v5/response.rb', line 3

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



4
5
6
# File 'lib/direct/api/v5/response.rb', line 4

def headers
  @headers
end

Instance Method Details

#errorObject



27
28
29
30
# File 'lib/direct/api/v5/response.rb', line 27

def error
  return unless error?
  @error ||= Error.new(body[:error])
end

#error?Boolean

Returns:



23
24
25
# File 'lib/direct/api/v5/response.rb', line 23

def error?
  body.key?(:error)
end

#request_idObject



15
16
17
# File 'lib/direct/api/v5/response.rb', line 15

def request_id
  @request_id ||= headers[:RequestId]
end

#resultObject



11
12
13
# File 'lib/direct/api/v5/response.rb', line 11

def result
  body[:result]
end

#unitsObject



19
20
21
# File 'lib/direct/api/v5/response.rb', line 19

def units
  @units ||= Units.new(headers[:Units])
end