Class: Todoist::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/todoist/client.rb

Constant Summary collapse

SUCCES_STATUS_CODE =
200

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Client

Returns a new instance of Client.



9
10
11
# File 'lib/todoist/client.rb', line 9

def initialize(token)
  @token = token
end

Instance Attribute Details

#_last_responseObject (readonly)

Returns the value of attribute _last_response.



3
4
5
# File 'lib/todoist/client.rb', line 3

def _last_response
  @_last_response
end

#errorsObject

Returns the value of attribute errors.



5
6
7
# File 'lib/todoist/client.rb', line 5

def errors
  @errors
end

#queueObject (readonly)

Returns the value of attribute queue.



3
4
5
# File 'lib/todoist/client.rb', line 3

def queue
  @queue
end

#seq_noObject



49
50
51
# File 'lib/todoist/client.rb', line 49

def seq_no
  @seq_no ||= 0
end

#seq_no_globalObject



53
54
55
# File 'lib/todoist/client.rb', line 53

def seq_no_global
  @seq_no_global ||= 0
end

#tokenObject (readonly)

Returns the value of attribute token.



3
4
5
# File 'lib/todoist/client.rb', line 3

def token
  @token
end

Instance Method Details

#add_to_queue(command) ⇒ Object



89
90
91
92
# File 'lib/todoist/client.rb', line 89

def add_to_queue(command)
  logger.warn 'Deprecated process_queue'
  queue.add(command)
end

#base_urlObject



13
14
15
# File 'lib/todoist/client.rb', line 13

def base_url
  "https://todoist.com"
end

#filtersObject



17
18
19
# File 'lib/todoist/client.rb', line 17

def filters
  @filters ||= Service::Filter.new(self)
end

#itemsObject



21
22
23
# File 'lib/todoist/client.rb', line 21

def items
  @items ||= Service::Item.new(self)
end

#labelsObject



25
26
27
# File 'lib/todoist/client.rb', line 25

def labels
  @labels ||= Service::Label.new(self)
end

#loggerObject



57
58
59
60
61
# File 'lib/todoist/client.rb', line 57

def logger
  @logger ||= Logger.new($stdout).tap do |log|
    log.progname = 'todoist-api'
  end
end

#notesObject



29
30
31
# File 'lib/todoist/client.rb', line 29

def notes
  @notes ||= Service::Note.new(self)
end

#post(path, payload) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# 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!Object



80
81
82
# File 'lib/todoist/client.rb', line 80

def process!
  queue.process!
end

#process_queueObject



84
85
86
87
# File 'lib/todoist/client.rb', line 84

def process_queue
  logger.warn 'Deprecated process_queue'
  queue.process!
end

#projectsObject



33
34
35
# File 'lib/todoist/client.rb', line 33

def projects
  @projects ||= Service::Project.new(self)
end

#queryObject



41
42
43
# File 'lib/todoist/client.rb', line 41

def query
  @query ||= Query.new(self)
end

#remindersObject



37
38
39
# File 'lib/todoist/client.rb', line 37

def reminders
  @reminders ||= Service::Reminder.new(self)
end