Class: Todoist::Queue
- Inherits:
-
Object
- Object
- Todoist::Queue
- Extended by:
- Forwardable
- Defined in:
- lib/todoist/queue.rb
Instance Method Summary collapse
- #add(command) ⇒ Object
- #clear_queue! ⇒ Object
-
#initialize(client) ⇒ Queue
constructor
A new instance of Queue.
- #length ⇒ Object
- #path ⇒ Object
- #process! ⇒ Object
- #queue ⇒ Object
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 |
#length ⇒ Object
19 20 21 |
# File 'lib/todoist/queue.rb', line 19 def length queue.length end |
#path ⇒ Object
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 |
#queue ⇒ Object
11 12 13 |
# File 'lib/todoist/queue.rb', line 11 def queue @queue ||= [] end |