Class: Teapi::Documents

Inherits:
Object
  • Object
show all
Defined in:
lib/teapi/documents.rb

Overview

Manages documents

Class Method Summary collapse

Class Method Details

.bulk(type, created_or_updated, deleted) ⇒ Object

bulk updates a type

Parameters:

  • type (String)

    the document’s type

  • created_or_updated (Array[Hash])

    an array of documents to be created or updated

  • deleted (Array[Hash])

    an array of document [343, 9920,…]



29
30
31
32
# File 'lib/teapi/documents.rb', line 29

def self.bulk(type, created_or_updated, deleted)
  return if (created_or_updated.nil? || created_or_updated.length == 0) && (deleted.nil? || deleted.length == 0)
  Teapi.post(:documents, Oj.dump({type: type, deletes: deleted, upserts: created_or_updated}, mode: :compat))
end

.create(type, doc) ⇒ Object

creates a new document belonging to the given type

Parameters:

  • type (String)

    the document’s type

  • doc (Hash)

    document to create



7
8
9
# File 'lib/teapi/documents.rb', line 7

def self.create(type, doc)
  Teapi.post(:documents, Oj.dump({type: type, doc: doc}, mode: :compat))
end

.delete(type, id) ⇒ Object

deletes the document, by its id, belonging to the given type

Parameters:

  • type (String)

    the document’s type

  • doc (Hash)

    the document to update



21
22
23
# File 'lib/teapi/documents.rb', line 21

def self.delete(type, id)
  Teapi.delete(:documents, Oj.dump({type: type, id: id}, mode: :compat))
end

.update(type, doc) ⇒ Object

updates the document belonging to the given type

Parameters:

  • type (String)

    the document’s type

  • doc (Hash)

    the document to update



14
15
16
# File 'lib/teapi/documents.rb', line 14

def self.update(type, doc)
  Teapi.put(:documents, Oj.dump({type: type, doc: doc}, mode: :compat))
end