module Dirble::SimpleApiModel

Public Instance Methods

build_from_api_response(target_class, response) click to toggle source
# File lib/dirble/simple_api_model.rb, line 9
def build_from_api_response(target_class, response)
  parsed_collection(response).map do |object_params|
    target_class.new(object_params.with_indifferent_access)
  end
end
call_api_with_results(options) click to toggle source
# File lib/dirble/simple_api_model.rb, line 3
def call_api_with_results(options)
  factory_klass = options.delete(:factory_klass) || self
  response = Dirble.connection.exec_query(options).body
  build_from_api_response(factory_klass, response)
end
parsed_collection(json_response) click to toggle source
# File lib/dirble/simple_api_model.rb, line 15
def parsed_collection(json_response)
  Array.wrap(JSON.parse(json_response))
end