Class: MusicTodayApiWrapper::RestClients::CommonResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/rest_clients/common_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}, errors = []) ⇒ CommonResponse

Returns a new instance of CommonResponse.



6
7
8
9
# File 'lib/rest_clients/common_response.rb', line 6

def initialize(data = {}, errors = [])
  @data = data
  @errors = errors
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



4
5
6
# File 'lib/rest_clients/common_response.rb', line 4

def data
  @data
end

#errorsObject

Returns the value of attribute errors.



4
5
6
# File 'lib/rest_clients/common_response.rb', line 4

def errors
  @errors
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/rest_clients/common_response.rb', line 19

def success?
  @errors.empty?
end

#workObject



11
12
13
14
15
16
17
# File 'lib/rest_clients/common_response.rb', line 11

def work
  yield
  self
rescue StandardError => error
  @errors.push(error.message)
  self
end