Skip to content

Instantly share code, notes, and snippets.

@alexdean
Last active December 26, 2015 04:39
Show Gist options
  • Save alexdean/7094687 to your computer and use it in GitHub Desktop.
Save alexdean/7094687 to your computer and use it in GitHub Desktop.
how to use access the Todoist api using ruby & httparty.
  1. Run gem install httparty. This installs the HTTParty gem which the script uses. (A gem is a package containing ruby code which you can use. Hundreds of thousands of gems are available at https://rubygems.org.)
  2. Download the raw version of the ruby script and save it to a file locally. (Look for the 'View Raw' link in the upper-right corner.)
  3. Add your own email & password to the script.
  4. Run it and see how it goes.
  5. Look for ways you can expand this example at http://todoist.com/API/.
require 'httparty'
#
# 'gem install httparty' to install the gem
# more info at http://rubygems.org/gems/httparty
#
login = HTTParty.post('https://todoist.com/API/login', {
:query => {
'email'=>'[email protected]',
'password'=>'get your own, yo.'
}
})
if login.response.code != "200"
raise "Login unsuccessful.\n#{login.response.code}\n#{login.response.body}"
end
puts "Login response was:"
puts login.body
puts
# for JSON responses, you can address keys in the response directly
token = login['token']
projects = HTTParty.post('https://todoist.com/API/getProjects', {
:query => {
'token' => token
}
})
if projects.response.code != "200"
raise "getProjects unsuccessful.\n#{projects.response.code}\n#{projects.response.body}"
end
puts "Projects response was:"
puts projects.body
puts
# the response from getProjects is an array, so we can print out 1 item from the array.
puts "The first project looks like this:"
puts projects[0].inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment