Class: Todoist::Queue

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/todoist/queue.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Queue

Returns a new instance of Queue.



7
8
9
# File 'lib/todoist/queue.rb', line 7

def initialize(client)
  @client = client
end

Instance Method Details

#add(command) ⇒ Object



34
35
36
37
# File 'lib/todoist/queue.rb', line 34

def add(command)
  @queue ||= []
  @queue << command
end

#clear_queue!Object



30
31
32
# File 'lib/todoist/queue.rb', line 30

def clear_queue!
  @queue = []
end

#lengthObject



19
20
21
# File 'lib/todoist/queue.rb', line 19

def length
  queue.length
end

#pathObject



15
16
17
# File 'lib/todoist/queue.rb', line 15

def path
  "/API/v6/sync"
end

#process!Object



23
24
25
26
27
28
# File 'lib/todoist/queue.rb', line 23

def process!
  return if queue == []
  commands = queue
  clear_queue!
  @client.post(path, { commands: commands.map(&:to_hash).to_json})
end

#queueObject



11
12
13
# File 'lib/todoist/queue.rb', line 11

def queue
  @queue ||= []
end