Class: EventHookClientServer::Client::Response

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data: nil, pagination: nil, errors: nil, failure: false) ⇒ Response

Returns a new instance of Response.



18
19
20
21
22
23
24
# File 'lib/event_hook_client_server/client/response.rb', line 18

def initialize(data: nil, pagination: nil, errors: nil, failure: false)
  @data = data
  @pagination = pagination
  @errors = errors
  @failure = failure
  freeze
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

#errorsObject (readonly)

Returns the value of attribute errors.



16
17
18
# File 'lib/event_hook_client_server/client/response.rb', line 16

def errors
  @errors
end

#paginationObject (readonly)

Returns the value of attribute pagination.



15
16
17
# File 'lib/event_hook_client_server/client/response.rb', line 15

def pagination
  @pagination
end

Class Method Details

.fail!(errors) ⇒ Object



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

def self.fail!(errors)
  new(errors: Array(errors), failure: true)
end

.success!(data: nil, pagination: nil) ⇒ Object



6
7
8
# File 'lib/event_hook_client_server/client/response.rb', line 6

def self.success!(data: nil, pagination: nil)
  new(data: data, pagination: pagination)
end

Instance Method Details

#failed?Boolean Also known as: failure?, error?

Returns:

  • (Boolean)


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

def failed?
  failure == true
end

#success?Boolean Also known as: succeeded?, ok?

Returns:

  • (Boolean)


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

def success?
  !failed?
end