Last active
December 20, 2015 20:19
-
-
Save gooley/6189625 to your computer and use it in GitHub Desktop.
Rough example of how to push data into Ducksboard from the Preact API. We run something like this every hour to keep our Ducksboard dashboard up to date. Put in your api_key and secret from https://secure.preact.io/settings/api. For each of the push_duck calls, you pass in the ID from the widget edit page (e.g. 140456 from this screen http://cl.…
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
def update_ducksboard | |
api_key = "" | |
api_secret = "" | |
url = "https://#{api_key}:#{api_secret}@api.preact.io/api/v2/insights/health" | |
data = RestClient.get "#{url}", :content_type => :json, :accept => :json | |
accounts = data["accounts"] | |
# boxes | |
push_duck("YOUR_DATAPOINT_ID", accounts["good"]) # good account health | |
push_duck("YOUR_DATAPOINT_ID", accounts["fair"]) # fair account health | |
push_duck("YOUR_DATAPOINT_ID", accounts["poor"]) # poor account health | |
# stacked chart | |
push_duck("YOUR_DATAPOINT_ID", accounts["good"]) | |
push_duck("YOUR_DATAPOINT_ID", accounts["fair"]) | |
push_duck("YOUR_DATAPOINT_ID", accounts["poor"]) | |
# people | |
people = data["people"] | |
# boxes | |
push_duck("YOUR_DATAPOINT_ID", people["high"]) # high churn risk | |
push_duck("YOUR_DATAPOINT_ID", people["medium"]) # medium churn risk | |
push_duck("YOUR_DATAPOINT_ID", people["low"]) # low churn risk | |
# stacked chart | |
push_duck("YOUR_DATAPOINT_ID", people["high"]) | |
push_duck("YOUR_DATAPOINT_ID", people["medium"]) | |
push_duck("YOUR_DATAPOINT_ID", people["low"]) | |
end | |
def push_duck(key, val) | |
auth_key = "YOUR_DUCKSBOARD_API_KEY" | |
url_base = "https://#{auth_key}:[email protected]/values/" | |
RestClient.post "#{url_base}#{key}", { :value => val }.to_json, :content_type => :json, :accept => :json | |
puts "\t#{key}: #{val}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment