Skip to content

Instantly share code, notes, and snippets.

@fizx
Last active December 12, 2015 07:28
Show Gist options
  • Save fizx/4737058 to your computer and use it in GitHub Desktop.
Save fizx/4737058 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "open-uri"
require "rubygems"
require "json"
unless ENV["ASANA_API_KEY"]
puts "please set ASANA_API_KEY in the env"
exit 1
end
file = File.join(ENV["HOME"], ".asana_cache")
$cache = File.exists?(file) ? eval(File.read(file)) : {}
def get(path, cached = true)
$cache[path] ||= \
JSON.parse(
open("https://app.asana.com/api#{path}",
:http_basic_authentication=>[ENV["ASANA_API_KEY"],""]
).read
)
end
me = get("/1.0/users/me")
me_id = me["data"]["id"]
wk_id = me["data"]["workspaces"].first["id"]
tasks = get("/1.0/tasks?workspace=#{wk_id}&assignee=#{me_id}", false)
tasks["data"].each do |task|
path = "/1.0/tasks/#{task["id"]}"
full_task = get(path)
if(!full_task["data"]["completed"] && full_task["data"]["assignee_status"] == "today")
$cache.delete path
puts task["name"]
break
end
end
File.open(file, "w") {|h| h.puts($cache.inspect) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment