CommonThread

Displaying articles with tag

Slicehost API Saves The Day

Posted by ben, Tue May 20 22:25:00 UTC 2008

Thanks to slicehost for giving me an API for managing my DNS zones and records via ActiveResource becauase it saved me lots of time and tedious work. I needed to update my TTL settings in all my domains and rather than having to edit all 61 entries I simply made a ruby script to do it for me:

require 'rubygems'
require 'activeresource'

API_PASSWORD = "MY_SECRET_PASSWORD" 
DEFAULT_TTL = 86400

class Record < ActiveResource::Base
  self.site = "https://#{API_PASSWORD}@api.slicehost.com/" 
end

records = Record.find(:all)

for record in records
  record.ttl = DEFAULT_TTL
  record.save
end

and while we are at it lets output all of our info:

require 'rubygems'
require 'activeresource'

API_PASSWORD = "MY_SECRET_PASSWORD" 

class Zone < ActiveResource::Base
  self.site = "https://#{API_PASSWORD}@api.slicehost.com/" 
end

class Record < ActiveResource::Base
  self.site = "https://#{API_PASSWORD}@api.slicehost.com/" 
end

zones = Zone.find(:all)
records = Record.find(:all)

for zone in zones
  puts "zone: #{zone.origin}" 

  for record in records.find_all{|record| record.zone_id == zone.id}
    puts "  #{record.record_type}: #{record.name} - #{record.data}" 
  end
end

There, that was easy.

1 comment | Filed Under: | Tags:

Ruby Awareness API (A.K.A. My First Gem)

Posted by ben, Mon Mar 26 00:00:00 UTC 2007

So I wrote my first rubygem and put it on rubyforge. It really wasn’t too bad, soon enough I will write a tutorial on packaging your code into a ruby gem and post it.

The Ruby Awareness API (rawapi) is a ruby interface to the FeedBurner Awareness API. it is really simple with one class that needs to be instantiated and only 2 methods right now. You can see the pitiful documentation online. I will be updating it too soon enough when I find motivation.

The cool part is since I registered my project with rubyforge I, and anyone else, can install it via the gem command.

sudo gem install rawapi

Isn’t that nifty?

0 comments | Filed Under: | Tags: