Module: EntityResponseConcern

Extended by:
ActiveSupport::Concern
Included in:
SBF::Client::BaseEntity, SBF::Client::EntityCollection
Defined in:
lib/stbaldricks/entities/concerns/entity_response_concern.rb

Instance Method Summary collapse

Instance Method Details

#add_errors(error) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/stbaldricks/entities/concerns/entity_response_concern.rb', line 7

def add_errors(error)
  errors.clear
  unless error.fields.nil?
    count = error.fields.length
    error.fields.each do |field|
      field = field.gsub('_id', '') # Hacky, since API returns DB field that errored instead of View Field
      errors.add(field, error.details) if respond_to?(field.to_sym)
      errors.add(:base, "#{field}: #{error.details}") unless respond_to?(field.to_sym)
    end
  end
  errors.instance_variable_set(:@code, error.code)
  errors.instance_variable_set(:@type, error.type)
  errors.add(:base, "#{error.type}: #{error.details}") if count&.zero?
end

#dataObject



45
46
47
48
# File 'lib/stbaldricks/entities/concerns/entity_response_concern.rb', line 45

def data
  log_deprecated('data', caller)
  self
end

#error?Boolean

Returns:



26
27
28
# File 'lib/stbaldricks/entities/concerns/entity_response_concern.rb', line 26

def error?
  !success?
end

#errors?Boolean

Returns:



34
35
36
# File 'lib/stbaldricks/entities/concerns/entity_response_concern.rb', line 34

def errors?
  errors.count.positive?
end

#errors_http_code=(http_code) ⇒ Object



22
23
24
# File 'lib/stbaldricks/entities/concerns/entity_response_concern.rb', line 22

def errors_http_code=(http_code)
  errors.instance_variable_set(:@http_code, http_code)
end

#http_codeObject

Deprecated Methods ############



40
41
42
43
# File 'lib/stbaldricks/entities/concerns/entity_response_concern.rb', line 40

def http_code
  log_deprecated('http_code', caller)
  errors.http_code
end

#success?Boolean

Returns:



30
31
32
# File 'lib/stbaldricks/entities/concerns/entity_response_concern.rb', line 30

def success?
  !errors?
end