- 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.) - 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.)
- Add your own email & password to the script.
- Run it and see how it goes.
- Look for ways you can expand this example at http://todoist.com/API/.
Last active
December 26, 2015 04:39
-
-
Save alexdean/7094687 to your computer and use it in GitHub Desktop.
how to use access the Todoist api using ruby & httparty.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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