Class: Teapi::Lists

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

Overview

Manages lists

Class Method Summary collapse

Class Method Details

.delete(type, list, ids = nil) ⇒ Object

deletes the document ids from the list

Parameters:

  • type (String)

    the list’s type

  • list (String)

    the list to insert into

  • optional

    ids [array] the ids, or single id, to insert (nil to delete all)



19
20
21
22
23
# File 'lib/teapi/lists.rb', line 19

def self.delete(type, list, ids = nil)
  ids = [ids] unless ids.is_a?(Array) || ids.nil?
  d = {type: type, list: list, ids: ids}
  Teapi.delete(:lists, Oj.dump(d, mode: :compat))
end

.insert(type, list, ids, truncate = false) ⇒ Object

inserts the document ids into the start of the list

Parameters:

  • type (String)

    the list’s type

  • list (String)

    the list to insert into

  • ids (array)

    the ids, or single id, to insert

  • optional

    truncate [bool] whether to truncate the existing list (replacing all the old ids with the new one)



9
10
11
12
13
# File 'lib/teapi/lists.rb', line 9

def self.insert(type, list, ids, truncate = false)
  ids = [ids] unless ids.is_a?(Array)
  d = {type: type, list: list, truncate: truncate, ids: ids}
  Teapi.post(:lists, Oj.dump(d, mode: :compat))
end