Created
November 29, 2015 22:04
-
-
Save ayosec/126602f30ca0bf943e23 to your computer and use it in GitHub Desktop.
Simple client for 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/ruby | |
require "json" | |
team = nil | |
token = nil | |
if ARGV.size != 1 or ARGV[0] =~ /^-/ | |
STDERR.puts "Usage #$0 'raw text'" | |
exit 1 | |
end | |
File.open(File.expand_path("~/.idonethis.rc")) do |f| | |
f.each_line do |line| | |
case line | |
when /team\s*=\s*"(.*)"/ | |
team = $1 | |
when /token\s*=\s*"(.*)"/ | |
token = $1 | |
end | |
end | |
end | |
raise "Missing token" unless token | |
raise "Missing team" unless team | |
pr, pw = IO.pipe | |
jq = fork do | |
pw.close | |
STDIN.reopen pr | |
exec "jq", "." | |
end | |
curl = fork do | |
data = { "raw_text" => ARGV.first, "team" => team }.to_json | |
pr.close | |
STDOUT.reopen pw | |
exec "curl", "-s", | |
"-H", "Authorization: Token #{token}", | |
"-H", "Content-Type: application/json", | |
"https://idonethis.com/api/v0.1/dones/", | |
"-d", data | |
end | |
pr.close | |
pw.close | |
Process.waitpid(jq) | |
Process.waitpid(curl) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment