Class: Openpix::RubySdk::ApiResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/openpix/ruby_sdk/api_response.rb

Overview

An Object representing the response from a call to Woovi API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, body:, single_resource: nil, collection_resource: nil) ⇒ ApiResponse

Returns a new instance of ApiResponse.



9
10
11
12
13
14
15
# File 'lib/openpix/ruby_sdk/api_response.rb', line 9

def initialize(status:, body:, single_resource: nil, collection_resource: nil)
  @success = status == 200
  @status = status
  @body = body
  @single_resource = single_resource
  @collection_resource = collection_resource
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/openpix/ruby_sdk/api_response.rb', line 7

def body
  @body
end

#statusObject (readonly)

Returns the value of attribute status.



7
8
9
# File 'lib/openpix/ruby_sdk/api_response.rb', line 7

def status
  @status
end

#successObject (readonly)

Returns the value of attribute success.



7
8
9
# File 'lib/openpix/ruby_sdk/api_response.rb', line 7

def success
  @success
end

Instance Method Details

#error_responseObject



27
28
29
30
31
32
# File 'lib/openpix/ruby_sdk/api_response.rb', line 27

def error_response
  return @body['error'] if @body['error']
  return @body['errors'].first['message'] if @body['errors'] && !@body['errors'].empty?

  ''
end

#pagination_metaObject



34
35
36
37
38
# File 'lib/openpix/ruby_sdk/api_response.rb', line 34

def pagination_meta
  return @body['pageInfo'] if @body['pageInfo']

  {}
end

#resource_responseObject



21
22
23
24
25
# File 'lib/openpix/ruby_sdk/api_response.rb', line 21

def resource_response
  return @body[@single_resource] if @single_resource

  @body[@collection_resource]
end

#success?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/openpix/ruby_sdk/api_response.rb', line 17

def success?
  success
end