Class: Todoist::Client
- Inherits:
-
Object
- Object
- Todoist::Client
- Defined in:
- lib/todoist/client.rb
Constant Summary collapse
- SUCCES_STATUS_CODE =
200
Instance Attribute Summary collapse
-
#_last_response ⇒ Object
readonly
Returns the value of attribute _last_response.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
- #seq_no ⇒ Object
- #seq_no_global ⇒ Object
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #add_to_queue(command) ⇒ Object
- #base_url ⇒ Object
- #filters ⇒ Object
-
#initialize(token) ⇒ Client
constructor
A new instance of Client.
- #items ⇒ Object
- #labels ⇒ Object
- #logger ⇒ Object
- #notes ⇒ Object
- #post(path, payload) ⇒ Object
- #process! ⇒ Object
- #process_queue ⇒ Object
- #projects ⇒ Object
- #query ⇒ Object
- #reminders ⇒ Object
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_response ⇒ Object (readonly)
Returns the value of attribute _last_response.
3 4 5 |
# File 'lib/todoist/client.rb', line 3 def _last_response @_last_response end |
#errors ⇒ Object
Returns the value of attribute errors.
5 6 7 |
# File 'lib/todoist/client.rb', line 5 def errors @errors end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
3 4 5 |
# File 'lib/todoist/client.rb', line 3 def queue @queue end |
#seq_no ⇒ Object
49 50 51 |
# File 'lib/todoist/client.rb', line 49 def seq_no @seq_no ||= 0 end |
#seq_no_global ⇒ Object
53 54 55 |
# File 'lib/todoist/client.rb', line 53 def seq_no_global @seq_no_global ||= 0 end |
#token ⇒ Object (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_url ⇒ Object
13 14 15 |
# File 'lib/todoist/client.rb', line 13 def base_url "https://todoist.com" end |
#filters ⇒ Object
17 18 19 |
# File 'lib/todoist/client.rb', line 17 def filters @filters ||= Service::Filter.new(self) end |
#items ⇒ Object
21 22 23 |
# File 'lib/todoist/client.rb', line 21 def items @items ||= Service::Item.new(self) end |
#labels ⇒ Object
25 26 27 |
# File 'lib/todoist/client.rb', line 25 def labels @labels ||= Service::Label.new(self) end |
#logger ⇒ Object
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 |
#notes ⇒ Object
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_queue ⇒ Object
84 85 86 87 |
# File 'lib/todoist/client.rb', line 84 def process_queue logger.warn 'Deprecated process_queue' queue.process! end |
#projects ⇒ Object
33 34 35 |
# File 'lib/todoist/client.rb', line 33 def projects @projects ||= Service::Project.new(self) end |