1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/dnsimple/models/dns/record.rb

67 lines
1.5 KiB
Ruby
Raw Normal View History

2011-02-24 17:14:50 -08:00
require 'fog/core/model'
module Fog
module DNS
class DNSimple
2011-02-24 17:14:50 -08:00
class Record < Fog::Model
extend Fog::Deprecation
deprecate :ip, :value
deprecate :ip=, :value=
2011-02-24 17:14:50 -08:00
identity :id
attribute :zone_id, :aliases => "domain_id"
2011-02-24 17:14:50 -08:00
attribute :name
attribute :value, :aliases => "content"
2011-02-24 17:14:50 -08:00
attribute :ttl
attribute :priority, :aliases => "prio"
attribute :type, :aliases => "record_type"
2011-02-24 17:14:50 -08:00
attribute :created_at
attribute :updated_at
def initialize(attributes={})
super
end
def destroy
2013-07-28 20:29:49 -07:00
service.delete_record(zone.id, identity)
2011-02-24 17:14:50 -08:00
true
end
def zone
@zone
end
def save
requires :name, :type, :value
2011-02-24 17:14:50 -08:00
options = {}
options[:prio] = priority if priority
options[:ttl] = ttl if ttl
# decide whether its a new record or update of an existing
if id.nil?
2013-07-28 13:20:37 -07:00
data = service.create_record(zone.id, name, type, value, options)
else
options[:name] = name if name
options[:content] = value if value
options[:type] = type if type
2013-07-28 20:33:21 -07:00
data = service.update_record(zone.id, id, options)
end
merge_attributes(data.body["record"])
2011-02-24 17:14:50 -08:00
true
end
private
def zone=(new_zone)
@zone = new_zone
end
end
end
end
end