Guest User

Untitled

a guest
Mar 14th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. require 'rubygems'
  2. require 'httparty'
  3. require 'pp'
  4.  
  5. class Zone
  6. ZERIGO_API_KEY = ENV['ZERIGO_API_KEY']
  7. ZERIGO_API_USER = ENV['ZERIGO_API_USER']
  8. include HTTParty
  9. format :xml
  10. base_uri 'ns.zerigo.com/api/1.1/'
  11. basic_auth ZERIGO_API_USER, ZERIGO_API_KEY
  12.  
  13. attr_accessor :zone
  14.  
  15. def self.all
  16. get("/zones.xml")['zones']
  17. end
  18.  
  19. def self.find(domain_name)
  20. all.detect{|z| z['domain'] == domain_name || z['id'] == domain_name}
  21. end
  22.  
  23. def initialize(name=nil, opts={})
  24. # @auth = {:username => opts[:username], :password => opts[:api_key]}
  25. self.class.basic_auth ZERIGO_API_USER, ZERIGO_API_KEY
  26. @zone=self.class.find(name) if name
  27. end
  28.  
  29. def new_host(opts)
  30. @newhost ||= self.class.get("/zones/#{zone['id']}/hosts.xml")
  31. end
  32.  
  33. def create_host(opts)
  34. opts=new_host.merge(opts)
  35. self.class.post("/zones/#{zone['id']}/hosts.xml", opts)
  36. end
  37.  
  38. # TODO
  39. # def update_host(opts={})
  40. # self.class.put("/hosts/#{opts['id']}", opts)
  41. # end
  42.  
  43. end
  44.  
  45.  
  46. # puts Zone.all
  47. # @zone = Zone.new('example.com)
  48. # p @zone.create_host(:hostname=>'sample', :data=>'10.0.0.1')
Add Comment
Please, Sign In to add comment