Skip to content

Instantly share code, notes, and snippets.

@stympy
Created July 31, 2014 12:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stympy/1d139a6531fe45023128 to your computer and use it in GitHub Desktop.
Save stympy/1d139a6531fe45023128 to your computer and use it in GitHub Desktop.
Simple client for the iDoneThis API
#!/usr/bin/env ruby
require 'httparty'
require 'json'
class IDoneThis
include HTTParty
base_uri "https://idonethis.com/api/v0.0"
def initialize(token = ENV['IDONETHIS_API_KEY'])
@token = token
end
def headers
{ "Authorization" => "Token #{@token}", "Content-Type" => "application/json" }
end
def teams
self.class.get("/teams/", headers: headers)
end
def dones(query = {})
self.class.get("/dones/", query: query, headers: headers)
end
def done(text, team, date = Date.today)
self.class.post("/dones/", body: { raw_text: text, team: "#{self.class.base_uri}/teams/#{team}/", done_date: date }.to_json, headers: headers)
end
end
client = IDoneThis.new
puts client.teams
puts client.dones(page: 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment