Sha256: 1eef5f2715e55b4e465020e5ad5ef1ace1f91a69c019b7556f8b83e448d04029

Contents?: true

Size: 978 Bytes

Versions: 15

Compression:

Stored size: 978 Bytes

Contents

require 'intercom/collection_proxy'

module Intercom
  module ApiOperations
    module FindAll
      module ClassMethods
        def find_all(params)
          raise BadRequestError, "#{self}#find takes a hash as its parameter but you supplied #{params.inspect}" unless params.is_a? Hash
          collection_name = Utils.resource_class_to_collection_name(self)
          finder_details = {}
          if params[:id] && !type_switched_finder?(params)
            finder_details[:url] = "/#{collection_name}/#{params[:id]}"
            finder_details[:params] = {}
          else
            finder_details[:url] = "/#{collection_name}"
            finder_details[:params] = params
          end
          CollectionProxy.new(collection_name, finder_details)
        end

        private

        def type_switched_finder?(params)
          params.include?(:type)
        end
      end

      def self.included(base)
        base.extend(ClassMethods)
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
cogniteev-intercom-2.5.4 lib/intercom/api_operations/find_all.rb
intercom-2.5.4 lib/intercom/api_operations/find_all.rb
intercom-2.4.4 lib/intercom/api_operations/find_all.rb
intercom-2.4.3 lib/intercom/api_operations/find_all.rb
intercom-2.4.2 lib/intercom/api_operations/find_all.rb
intercom-2.4.1 lib/intercom/api_operations/find_all.rb
intercom-2.4.0 lib/intercom/api_operations/find_all.rb
intercom-2.3.0 lib/intercom/api_operations/find_all.rb
intercom-2.2.4 lib/intercom/api_operations/find_all.rb
intercom-2.2.3 lib/intercom/api_operations/find_all.rb
intercom-2.2.2 lib/intercom/api_operations/find_all.rb
intercom-2.2.1 lib/intercom/api_operations/find_all.rb
intercom-2.2.0 lib/intercom/api_operations/find_all.rb
intercom-2.1.6 lib/intercom/api_operations/find_all.rb
intercom-2.1.5 lib/intercom/api_operations/find_all.rb