-
-
Save azcoov/6232763 to your computer and use it in GitHub Desktop.
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