Created
January 2, 2011 22:38
-
-
Save tmarkiewicz/762889 to your computer and use it in GitHub Desktop.
Example Ruby code for the StatsMix 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
# Full documentation for the StatsMix API can be found here: http://www.statsmix.com/developers | |
# In this example, a stat is posted using Ruby's net/http library. | |
require 'rubygems' | |
require 'net/http' | |
require 'uri' | |
require 'json' | |
url = URI.parse("http://api.statsmix.com/api/v1/stats") | |
http = Net::HTTP.new(url.host, url.port) | |
meta = {'Food' => 'Ice Cream', 'Calories' => 500} | |
request = Net::HTTP::Post.new(url.path) | |
request.add_field("X-StatsMix-Token", "API_KEY") | |
request.set_form_data({ | |
"value" => "VALUE", | |
"profile_id" => "PROFILE_ID", | |
"metric_id" => "METRIC_ID", | |
"generated_at" => "DATE", | |
"meta" => meta.to_json | |
}) | |
response = http.request(request) | |
puts response.body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment