Last active
August 29, 2015 14:15
-
-
Save ono/e870095150bf44c18fcd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'net/http' | |
require 'json' | |
class GeckoboardClient | |
def initialize(api_key) | |
@api_key = api_key | |
end | |
def url(widget_key) | |
"https://push.geckoboard.com/v1/send/#{widget_key}" | |
end | |
def push(widget_key, data) | |
uri = URI(url(widget_key)) | |
payload = { | |
api_key: @api_key, | |
data: data | |
} | |
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| | |
request = Net::HTTP::Post.new uri.request_uri | |
request['Content-Type'] = 'application/json' | |
request.body = payload.to_json | |
http.request(request) | |
end | |
end | |
end | |
# sending data of number widget | |
gecko = GeckoboardClient.new('XXXXXXX') | |
gecko.push('YYYYYYYY', | |
item: [{ value: 10 }] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment