Skip to content

Instantly share code, notes, and snippets.

@azcoov
Forked from gooley/push_ducksboard.rb
Created August 14, 2013 16:25
Show Gist options
  • Save azcoov/6232763 to your computer and use it in GitHub Desktop.
Save azcoov/6232763 to your computer and use it in GitHub Desktop.
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}:x@push.ducksboard.com/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