Module: LinodeDynamicDns
- Defined in:
- lib/linode_dynamic_dns.rb,
lib/linode_dynamic_dns/config.rb,
lib/linode_dynamic_dns/version.rb
Constant Summary collapse
- VERSION =
"1.0.1"
Class Method Summary collapse
- .api ⇒ Object
- .config ⇒ Object
- .get_domain_id ⇒ Object
- .get_my_ip ⇒ Object
- .get_record_id(domain_id) ⇒ Object
- .load_config_from(path) ⇒ Object
- .set_config(path) ⇒ Object
- .ttl ⇒ Object
- .update_record_ip(domain_id, record_id, ip) ⇒ Object
Class Method Details
.api ⇒ Object
6 7 8 |
# File 'lib/linode_dynamic_dns.rb', line 6 def self.api @api ||= Linode.new(:api_key => config.api_key) end |
.config ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/linode_dynamic_dns/config.rb', line 5 def self.config @config ||= load_config_from( File.join( File.dirname(__FILE__), '../..', 'config', 'linode_dynamic_dns.yaml' ) ) end |
.get_domain_id ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/linode_dynamic_dns.rb', line 23 def self.get_domain_id api.domain.list.each do |dom| if dom.domain == config.domain return dom.domainid end end raise "No domain found matching #{config.domain}" end |
.get_my_ip ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/linode_dynamic_dns.rb', line 14 def self.get_my_ip response = Net::HTTP.get_response(URI(config.ip_url)) if response.code.to_i == 200 response.body else raise "Got bad response code #{response.code}" end end |
.get_record_id(domain_id) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/linode_dynamic_dns.rb', line 32 def self.get_record_id(domain_id) api.domain.resource.list(:DomainId => domain_id).each do |res| if res.name == config.record return res.resourceid end end raise "No resource found matching #{config.record}" end |
.load_config_from(path) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/linode_dynamic_dns/config.rb', line 14 def self.load_config_from(path) OpenStruct.new( YAML.load_file( path ) ) end |
.set_config(path) ⇒ Object
22 23 24 |
# File 'lib/linode_dynamic_dns/config.rb', line 22 def self.set_config(path) @config = load_config_from(File.(path)) end |
.ttl ⇒ Object
10 11 12 |
# File 'lib/linode_dynamic_dns.rb', line 10 def self.ttl config.ttl || 300 end |
.update_record_ip(domain_id, record_id, ip) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/linode_dynamic_dns.rb', line 41 def self.update_record_ip(domain_id, record_id, ip) api.domain.resource.update(:DomainId => domain_id, :ResourceId => record_id, :TTL_sec => ttl, :Target => ip) end |