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

Version Path
alula-ruby-0.69.3 lib/alula/api_operations/request.rb
alula-ruby-0.69.2 lib/alula/api_operations/request.rb
alula-ruby-0.69.1 lib/alula/api_operations/request.rb
alula-ruby-0.69.0 lib/alula/api_operations/request.rb
alula-ruby-0.68.0 lib/alula/api_operations/request.rb
alula-ruby-0.67.0 lib/alula/api_operations/request.rb
alula-ruby-0.66.0 lib/alula/api_operations/request.rb
alula-ruby-0.65.0 lib/alula/api_operations/request.rb
alula-ruby-0.64.0 lib/alula/api_operations/request.rb
alula-ruby-0.63.0 lib/alula/api_operations/request.rb
alula-ruby-0.62.0 lib/alula/api_operations/request.rb
alula-ruby-0.61.0 lib/alula/api_operations/request.rb
alula-ruby-0.60.0 lib/alula/api_operations/request.rb
alula-ruby-0.59.0 lib/alula/api_operations/request.rb
alula-ruby-0.58.0 lib/alula/api_operations/request.rb
alula-ruby-0.57.0 lib/alula/api_operations/request.rb
alula-ruby-0.56.0 lib/alula/api_operations/request.rb
alula-ruby-0.55.0 lib/alula/api_operations/request.rb
alula-ruby-0.54.0 lib/alula/api_operations/request.rb