Created
July 31, 2014 12:59
-
-
Save stympy/1d139a6531fe45023128 to your computer and use it in GitHub Desktop.
Simple client for the iDoneThis API
This file contains 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
#!/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