Last active
August 29, 2015 14:08
-
-
Save spilth/cf14dab4c0131f7d07de to your computer and use it in GitHub Desktop.
CloudBit Client - run`gem install rest_client` first.
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
# USAGE: | |
# require './cloudbit_client' | |
# client = CloudBitClient.new('your_api_token', 'your_device_id') | |
# client.output(100) | |
# client.output(50, 3000) | |
require 'rest_client' | |
class CloudBitClient | |
def initialize(api_token, device_id) | |
@api_token = api_token | |
@device_id = device_id | |
end | |
def output(percent, duration = -1) | |
RestClient.post "https://api-http.littlebitscloud.cc/devices/#{device_id}/output", | |
{ | |
:percent => percent.to_s, | |
:duration_ms => duration.to_s | |
}, | |
Accept: "application/vnd.littlebits.v2+json", | |
Authorization: "Bearer #{api_token}" | |
end | |
private | |
attr_reader :api_token, :device_id | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment