Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'httparty'
- require 'pp'
- class Zone
- ZERIGO_API_KEY = ENV['ZERIGO_API_KEY']
- ZERIGO_API_USER = ENV['ZERIGO_API_USER']
- include HTTParty
- format :xml
- base_uri 'ns.zerigo.com/api/1.1/'
- basic_auth ZERIGO_API_USER, ZERIGO_API_KEY
- attr_accessor :zone
- def self.all
- get("/zones.xml")['zones']
- end
- def self.find(domain_name)
- all.detect{|z| z['domain'] == domain_name || z['id'] == domain_name}
- end
- def initialize(name=nil, opts={})
- # @auth = {:username => opts[:username], :password => opts[:api_key]}
- self.class.basic_auth ZERIGO_API_USER, ZERIGO_API_KEY
- @zone=self.class.find(name) if name
- end
- def new_host(opts)
- @newhost ||= self.class.get("/zones/#{zone['id']}/hosts.xml")
- end
- def create_host(opts)
- opts=new_host.merge(opts)
- self.class.post("/zones/#{zone['id']}/hosts.xml", opts)
- end
- # TODO
- # def update_host(opts={})
- # self.class.put("/hosts/#{opts['id']}", opts)
- # end
- end
- # puts Zone.all
- # @zone = Zone.new('example.com)
- # p @zone.create_host(:hostname=>'sample', :data=>'10.0.0.1')
Add Comment
Please, Sign In to add comment