Sha256: 46eb20ca90bbc9d58faefbb179dc4f6d25ddad938d4026014fd5281b0697619f

Contents?: true

Size: 1.36 KB

Versions: 75

Compression:

Stored size: 1.36 KB

Contents

module Alula
  module ApiOperations
    module List
      def self.extended(base)
        base.include(InstanceMethods)
      end

    	def method_missing(method, *args, &block)
        QueryInterface.new(self).send(method, *args, &block)
      end

      def list(filters = {}, opts = {})
        response = Alula::Client.request(:get, resource_url, filters, opts)
        if response.ok?
        	list = ListObject.construct_from_response(self, response, opts)
          list = build_and_merge_list_relationships(list, response.data['included']) if response.data['included']
          list
        else
        	error_class = AlulaError.for_response(response)
        	raise error_class
        end
      end

      def build_and_merge_list_relationships(collection, relations)
        relations.each do |relation|
          model = Alula.class_from_resource_type(relation['type'])
          model = model.new.construct_from(relation)
          key = { type: model.get_type, id: model.id }.freeze

          #
          # TODO: Remove this line. This makes us ignore unknown relationships
          unless get_relationship(model.get_type).nil?
            collection.select{ |m| m.link_matchers.include?(key) }
                      .each { |m| m.add_model_to_relationship(model) }
          end
        end

        collection
      end

      module InstanceMethods
      end
    end
  end
end

Version data entries

75 entries across 75 versions & 1 rubygems

Version Path
alula-ruby-2.1.2 lib/alula/api_operations/list.rb
alula-ruby-2.1.1 lib/alula/api_operations/list.rb
alula-ruby-2.1.0 lib/alula/api_operations/list.rb
alula-ruby-2.0.0 lib/alula/api_operations/list.rb
alula-ruby-1.10.5 lib/alula/api_operations/list.rb
alula-ruby-1.10.4 lib/alula/api_operations/list.rb
alula-ruby-1.10.3 lib/alula/api_operations/list.rb
alula-ruby-1.10.2 lib/alula/api_operations/list.rb
alula-ruby-1.10.1 lib/alula/api_operations/list.rb
alula-ruby-1.10.0 lib/alula/api_operations/list.rb
alula-ruby-1.9.17 lib/alula/api_operations/list.rb
alula-ruby-1.9.16 lib/alula/api_operations/list.rb
alula-ruby-1.9.15 lib/alula/api_operations/list.rb
alula-ruby-1.9.14 lib/alula/api_operations/list.rb
alula-ruby-1.9.13 lib/alula/api_operations/list.rb
alula-ruby-1.9.12 lib/alula/api_operations/list.rb
alula-ruby-1.9.11 lib/alula/api_operations/list.rb
alula-ruby-1.9.10 lib/alula/api_operations/list.rb
alula-ruby-1.9.9 lib/alula/api_operations/list.rb
alula-ruby-1.9.8 lib/alula/api_operations/list.rb