Sha256: f6018485694d3b7cb58565ad536d9bf6f92087cc30bec8fc9d8975a13211ad06

Contents?: true

Size: 1.3 KB

Versions: 77

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

77 entries across 77 versions & 1 rubygems

Version Path
alula-ruby-2.6.1 lib/alula/api_operations/request.rb
alula-ruby-2.6.0 lib/alula/api_operations/request.rb
alula-ruby-2.5.0 lib/alula/api_operations/request.rb
alula-ruby-2.4.0 lib/alula/api_operations/request.rb
alula-ruby-2.3.0 lib/alula/api_operations/request.rb
alula-ruby-2.2.0 lib/alula/api_operations/request.rb
alula-ruby-2.1.2 lib/alula/api_operations/request.rb
alula-ruby-2.1.1 lib/alula/api_operations/request.rb
alula-ruby-2.1.0 lib/alula/api_operations/request.rb
alula-ruby-2.0.0 lib/alula/api_operations/request.rb
alula-ruby-1.10.5 lib/alula/api_operations/request.rb
alula-ruby-1.10.4 lib/alula/api_operations/request.rb
alula-ruby-1.10.3 lib/alula/api_operations/request.rb
alula-ruby-1.10.2 lib/alula/api_operations/request.rb
alula-ruby-1.10.1 lib/alula/api_operations/request.rb
alula-ruby-1.10.0 lib/alula/api_operations/request.rb
alula-ruby-1.9.17 lib/alula/api_operations/request.rb
alula-ruby-1.9.16 lib/alula/api_operations/request.rb
alula-ruby-1.9.15 lib/alula/api_operations/request.rb
alula-ruby-1.9.14 lib/alula/api_operations/request.rb