Sha256: eea78e5088ba5bd07183fb3ca855dc23068a109c1f667032ab2114542e87b732

Contents?: true

Size: 930 Bytes

Versions: 3

Compression:

Stored size: 930 Bytes

Contents

# frozen_string_literal: true

module Typesense
  class Documents
    RESOURCE_PATH = '/documents'

    def initialize(configuration, collection_name)
      @configuration   = configuration
      @collection_name = collection_name
      @documents       = {}
    end

    def create(document)
      ApiCall.new(@configuration).post(endpoint_path, document)
    end

    def export
      ApiCall.new(@configuration).get_unparsed_response(endpoint_path('export')).split("\n")
    end

    def search(search_parameters)
      ApiCall.new(@configuration).get(endpoint_path('search'), search_parameters)
    end

    def [](document_id)
      @documents[document_id] ||= Document.new(@configuration, @collection_name, document_id)
    end

    private

    def endpoint_path(operation = nil)
      "#{Collections::RESOURCE_PATH}/#{@collection_name}#{Documents::RESOURCE_PATH}#{operation.nil? ? '' : '/' + operation}"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
typesense-0.2.0 lib/typesense/documents.rb
typesense-0.1.1 lib/typesense/documents.rb
typesense-0.1.0 lib/typesense/documents.rb