class Cb::Responses::ApiResponse

Attributes

metadata[R]
model[R]
models[R]
response[R]

Public Class Methods

new(raw_response_hash) click to toggle source
# File lib/cb/responses/api_response.rb, line 23
def initialize(raw_response_hash)
  set_response_variable(raw_response_hash)
  @metadata = extract_metadata
  @models   = validated_models
end

Protected Instance Methods

extract_models() click to toggle source
# File lib/cb/responses/api_response.rb, line 33
def extract_models
  fail NotImplementedError.new(__method__)
end
hash_containing_metadata() click to toggle source
# File lib/cb/responses/api_response.rb, line 41
def hash_containing_metadata
  fail NotImplementedError.new(__method__)
end
raise_on_timing_parse_error() click to toggle source
# File lib/cb/responses/api_response.rb, line 45
def raise_on_timing_parse_error
  true
end
required_response_field(field_name, parent_hash) click to toggle source
# File lib/cb/responses/api_response.rb, line 49
def required_response_field(field_name, parent_hash)
  fail ArgumentError.new("field_name can't be nil!")  if field_name.nil?
  fail ArgumentError.new("parent_hash can't be nil!") if parent_hash.nil?
  fail ExpectedResponseFieldMissing.new("Response field missing '#{ field_name }' for #{ self.class.name }") unless parent_hash.key?(field_name)
end
validate_api_hash() click to toggle source
# File lib/cb/responses/api_response.rb, line 37
def validate_api_hash
  fail NotImplementedError.new(__method__)
end

Private Instance Methods

extract_metadata() click to toggle source
# File lib/cb/responses/api_response.rb, line 63
def extract_metadata
  Metadata.new(hash_containing_metadata, raise_on_timing_parse_error) unless hash_containing_metadata.nil?
end
set_response_variable(response_hash) click to toggle source
# File lib/cb/responses/api_response.rb, line 57
def set_response_variable(response_hash)
  should_raise = response_hash.nil? || response_hash.empty?
  fail ApiResponseError.new('Response is empty!') if should_raise
  @response = response_hash
end
validated_models() click to toggle source
# File lib/cb/responses/api_response.rb, line 67
def validated_models
  validate_api_hash
  extract_models
end