Sha256: 20bb4d8aac0882f4e04c6dd7849b7dafefee292219e3add5afd7edfa576987f7

Contents?: true

Size: 707 Bytes

Versions: 18

Compression:

Stored size: 707 Bytes

Contents

module NCore
  module All
    extend ActiveSupport::Concern

    module ClassMethods
      def all(params={})
        params = parse_request_params(params)
        parsed, creds = request(:get, resource_path, params)
        if parsed[:errors].any?
          raise module_parent::QueryError, parsed[:errors]
        end
        Collection.new.tap do |coll|
          coll.metadata = parsed[:metadata]
          parsed[:data].each do |hash|
            coll << factory({data: hash, metadata: parsed[:metadata]}, creds)
          end
        end
      end

      def first(params={})
        params = params.with_indifferent_access.merge(max_results: 1)
        all(params).first
      end
    end

  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
ncore-3.12.0 lib/ncore/methods/all.rb
ncore-3.11.0 lib/ncore/methods/all.rb
ncore-3.10.0 lib/ncore/methods/all.rb
ncore-3.9.1 lib/ncore/methods/all.rb
ncore-3.9.0 lib/ncore/methods/all.rb
ncore-3.8.1 lib/ncore/methods/all.rb
ncore-3.8.0 lib/ncore/methods/all.rb
ncore-3.7.1 lib/ncore/methods/all.rb
ncore-3.7.0 lib/ncore/methods/all.rb
ncore-3.6.2 lib/ncore/methods/all.rb
ncore-3.6.1 lib/ncore/methods/all.rb
ncore-3.6.0 lib/ncore/methods/all.rb
ncore-3.5.2 lib/ncore/methods/all.rb
ncore-3.5.1 lib/ncore/methods/all.rb
ncore-3.5.0 lib/ncore/methods/all.rb
ncore-3.4.4 lib/ncore/methods/all.rb
ncore-3.4.3 lib/ncore/methods/all.rb
ncore-3.4.2 lib/ncore/methods/all.rb