Sha256: f6018485694d3b7cb58565ad536d9bf6f92087cc30bec8fc9d8975a13211ad06
Contents?: true
Size: 1.3 KB
Versions: 79
Compression:
Stored size: 1.3 KB
Contents
module Alula module ApiOperations module Request def self.extended(base) base.include(InstanceMethods) end # Load a single model by ID def retrieve(id, built_filters = {}) response = Alula::Client.request(:get, self.resource_url(id), built_filters, {}) if response.ok? item = self.new.construct_from(response.data['data']) item = build_and_merge_item_relationships(item, response.data['included']) if response.data['included'] item.rate_limit = response.rate_limit item else error_class = AlulaError.for_response(response) raise error_class end end def build_and_merge_item_relationships(item, relations) relations.each do |relation| model = Alula.class_from_resource_type(relation['type']) model = model.new.construct_from(relation) # # TODO: Remove this line. This makes us ignore unknown relationships unless get_relationship(model.get_type).nil? item.add_model_to_relationship(model) end end item end module InstanceMethods def request(method, url, params, opts) Alula::Client.request(method, url, params, opts) end end end end end
Version data entries
79 entries across 79 versions & 1 rubygems