class Todoist::Client

Constants

SUCCES_STATUS_CODE

Attributes

_last_response[R]
errors[RW]
queue[R]
seq_no[W]
seq_no_global[W]
token[R]

Public Class Methods

new(token) click to toggle source
# File lib/todoist/client.rb, line 9
def initialize(token)
  @token = token
end

Public Instance Methods

add_to_queue(command) click to toggle source
# File lib/todoist/client.rb, line 89
def add_to_queue(command)
  logger.warn 'Deprecated process_queue'
  queue.add(command)
end
base_url() click to toggle source
# File lib/todoist/client.rb, line 13
def base_url
  "https://todoist.com"
end
filters() click to toggle source
# File lib/todoist/client.rb, line 17
def filters
  @filters ||= Service::Filter.new(self)
end
items() click to toggle source
# File lib/todoist/client.rb, line 21
def items
  @items ||= Service::Item.new(self)
end
labels() click to toggle source
# File lib/todoist/client.rb, line 25
def labels
  @labels ||= Service::Label.new(self)
end
logger() click to toggle source
# File lib/todoist/client.rb, line 57
def logger
  @logger ||= Logger.new($stdout).tap do |log|
    log.progname = 'todoist-api'
  end
end
notes() click to toggle source
# File lib/todoist/client.rb, line 29
def notes
  @notes ||= Service::Note.new(self)
end
post(path, payload) click to toggle source
# File lib/todoist/client.rb, line 63
def post(path, payload)
  post_request = Request.post(path, payload.merge(token: token))

  response = @_last_response = post_request.execute(base_url)

  if response.code.to_i != SUCCES_STATUS_CODE
    self.errors = JSON.parse(@_last_response.body.to_s)
    return false
  else
    parsed_response = JSON.parse(response.body)

    self.seq_no_global = parsed_response['seq_no_global'] if parsed_response.is_a?(Hash) && parsed_response['seq_no_global']

    parsed_response
  end
end
process!() click to toggle source
# File lib/todoist/client.rb, line 80
def process!
  queue.process!
end
process_queue() click to toggle source
# File lib/todoist/client.rb, line 84
def process_queue
  logger.warn 'Deprecated process_queue'
  queue.process!
end
projects() click to toggle source
# File lib/todoist/client.rb, line 33
def projects
  @projects ||= Service::Project.new(self)
end
query() click to toggle source
# File lib/todoist/client.rb, line 41
def query
  @query ||= Query.new(self)
end
reminders() click to toggle source
# File lib/todoist/client.rb, line 37
def reminders
  @reminders ||= Service::Reminder.new(self)
end
seq_no() click to toggle source
# File lib/todoist/client.rb, line 49
def seq_no
  @seq_no ||= 0
end
seq_no_global() click to toggle source
# File lib/todoist/client.rb, line 53
def seq_no_global
  @seq_no_global ||= 0
end