Module: Dirble::SimpleApiModel

Included in:
Category, Station
Defined in:
lib/dirble/simple_api_model.rb

Instance Method Summary collapse

Instance Method Details

#build_from_api_response(target_class, response) ⇒ Object



9
10
11
12
13
# 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) ⇒ Object



3
4
5
6
7
# 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) ⇒ Object



15
16
17
# File 'lib/dirble/simple_api_model.rb', line 15

def parsed_collection(json_response)
  Array.wrap(JSON.parse(json_response))
end