Sha256: 4d133e65338658c52fdfd49247dc4493477f47d80e8f37a9f92eb48a1e2db42a

Contents?: true

Size: 1.86 KB

Versions: 39

Compression:

Stored size: 1.86 KB

Contents

#
# Author:: Celso Fernandes (<fernandes@zertico.com>)
# © Copyright IBM Corporation 2014.
#
# LICENSE: MIT (http://opensource.org/licenses/MIT)
#
require 'fog/core/model'

module Fog
  module DNS
    class Softlayer
      class Record < Fog::Model
        identity  :id
        attribute :domain_id,     :aliases => "domainId"
        attribute :name,          :aliases => "host"
        attribute :value,         :aliases => "data"
        attribute :ttl
        attribute :priority,      :aliases => "mxPriority"
        attribute :type
        attribute :expire
        attribute :minimum
        attribute :refresh
        attribute :retry
         
        def initialize(attributes={})
          self.domain_id = attributes[:domain_id]
          super(attributes)
        end

        def destroy
          response = service.delete_record(identity)
          response.body
        end

        def save
          requires :name, :type, :value, :domain_id
          opts = generate_template

          # to save or to update, thats the question
          if id.nil?
            data = service.create_record(opts)
            merge_attributes(data.body)
          else
            data = service.update_record(self.id, opts)
          end
          true
        end

        private
        def generate_template
          template = {}
          template[:host] = self.name
          template[:data] = self.value
          template[:type] = self.type
          template[:domainId] = self.domain_id

          template[:ttl] = self.ttl if self.ttl
          template[:mxPriority] = self.priority if self.priority
          template[:expire] = self.expire if self.expire
          template[:minimum] = self.minimum if self.minimum
          template[:refresh] = self.refresh if self.refresh
          template[:retry] = self.retry if self.retry
          template
        end
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
fog-softlayer-0.4.2.pre lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.4.1 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.4.0 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.3.30 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.3.29 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.3.28 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.3.27 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.3.26 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.3.25 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.3.24 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.3.23 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.3.22 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.3.21 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.3.20 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.3.19 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.3.18 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.3.17 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.3.16 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.3.15 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.3.14 lib/fog/softlayer/models/dns/record.rb