Created
May 23, 2011 17:47
-
-
Save rrichards/987135 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
# An example of using Cloudkick's oauth API. Make sure the | |
# key you're using has read/write privileges (the default | |
# is just execute privileges). You'll need the json and | |
# the oauth gems installed as well for this to work properly. | |
require 'rubygems' | |
require 'oauth' | |
require 'json' | |
# make the consumer out of your secret and key | |
consumer_key = "<key>" | |
consumer_secret = "<secret>" | |
consumer = OAuth::Consumer.new(consumer_key, consumer_secret, | |
:site => "https://api.cloudkick.com", | |
:http_method => :get) | |
# make the access token from your consumer | |
access_token = OAuth::AccessToken.new(consumer) | |
# make a signed request! | |
req = access_token.get("/1.0/query/nodes") | |
case req.response.code | |
when "200" | |
nodes = JSON.parse(req.response.body, :symbolize_names => true) | |
else | |
puts "error: #{req.inspect}" | |
end | |
# loop through all nodes, removing any that have agents in the disconnected state | |
nodes.each do |node| | |
if node[:agent_state] == "disconnected" | |
puts "removing #{node[:name]}..." | |
req = access_token.delete("/1.0/node/#{node[:id]}") | |
puts req.inspect # 204 => successful | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment