Class: TodoistQuerynaut::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(todoist) ⇒ Client

Returns a new instance of Client.



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

def initialize(todoist)
  @todoist = todoist
end

Instance Method Details

#all_itemsObject



19
20
21
# File 'lib/todoist_querynaut/client.rb', line 19

def all_items
  search "view all"
end

#project_name_to_id(name) ⇒ Object



23
24
25
26
27
# File 'lib/todoist_querynaut/client.rb', line 23

def project_name_to_id(name)
  projects = all_projects.select{|p| p["name"].casecmp(name) == 0}
  raise ProjectNotFoundError if projects.empty?
  projects.first["id"].to_i
end

#run(query) ⇒ Object



7
8
9
# File 'lib/todoist_querynaut/client.rb', line 7

def run(query)
  TodoistQuerynaut::Parser.parse(query).run_query self
end

#search(query) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/todoist_querynaut/client.rb', line 11

def search(query)
  # Todoist doesn't always set "query" on the results, hence we cannot
  # search(value)[value] here, as ruby-todoist-api Gem then assigns "nil"
  # as the hash's key.  Instead we do .first.last, to get the value of the
  # first hash entry
  @todoist.query.search(query).first.last.data
end