class Cb::Models::ApiResponseModel

Attributes

api_response[RW]

Public Class Methods

new(response = {}) click to toggle source
# File lib/cb/models/api_response_model.rb, line 16
def initialize(response = {})
  @api_response = response
  validate_api_response
  set_model_properties
end

Protected Instance Methods

required_fields() click to toggle source
# File lib/cb/models/api_response_model.rb, line 24
def required_fields
  # return an array of hash keys to check for in your api hash
  fail NotImplementedError.new(__method__)
end
set_model_properties() click to toggle source
# File lib/cb/models/api_response_model.rb, line 29
def set_model_properties
  # do whatever work you need to do to set up the attributes on your model
  fail NotImplementedError.new(__method__)
end

Private Instance Methods

validate_api_response() click to toggle source
# File lib/cb/models/api_response_model.rb, line 36
def validate_api_response
  missing_fields  = required_fields.map { |field| field unless @api_response.key?(field) }.compact
  fail ExpectedResponseFieldMissing.new(missing_fields.join(' ')) unless missing_fields.empty?
end