Module: Dirble::SimpleApiModel
Instance Method Summary collapse
- #build_from_api_response(target_class, response) ⇒ Object
- #call_api_with_results(options) ⇒ Object
- #parsed_collection(json_response) ⇒ Object
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() factory_klass = .delete(:factory_klass) || self response = Dirble.connection.exec_query().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 |