Sha256: b587dff7410c51a482ae5e3a23b7755c9714c0d164116169de565a104e8f93bc

Contents?: true

Size: 1.98 KB

Versions: 9

Compression:

Stored size: 1.98 KB

Contents

module Fog
  module Zerigo
    class DNS
      class Real

        require 'fog/dns/parsers/zerigo/create_host'

        # Create a new host in the specified zone
        #
        # ==== Parameters
        # * zone_id<~Integer>
        # * host_type<~String>
        # * data<~String>
        # * options<~Hash> - optional paramaters
        #   * hostname<~String> - Note: normally this is set/required!!
        #   * notes<~String>
        #   * priority<~Integer> - Note: required for MX or SRV records
        #   * ttl<~Integer>
        # ==== Returns
        # * response<~Excon::Response>: 
        #   * body<~Hash>
        #     * 'created-at'<~String>
        #     * 'data'<~String>
        #     * 'fqdn'<~String>
        #     * 'host-type'<~String>
        #     * 'hostname'<~String>
        #     * 'id'<~Integer>
        #     * 'notes'<~String>
        #     * 'priority'<~Integer>
        #     * 'ttl'<~Integer>
        #     * 'updated-at'<~String>
        #     * 'zone-id'<~String>
        #   * 'status'<~Integer> - 201 if successful        
        def create_host(zone_id, host_type, data, options = {})
          
          optional_tags= ''
          options.each { |option, value|
            case option
            when :hostname
              optional_tags+= "<hostname>#{value}</hostname>"
            when :notes
              optional_tags+= "<notes>#{value}</notes>"
            when :priority
              optional_tags+= "<priority>#{value}</priority>"
            when :ttl
              optional_tags+= "<ttl>#{value}</ttl>"
            end
          }
            
          request(
            :body     => %Q{<?xml version="1.0" encoding="UTF-8"?><host><host-type>#{host_type}</host-type><data>#{data}</data>#{optional_tags}</host>},
            :expects  => 201,
            :method   => 'POST',
            :parser   => Fog::Parsers::Zerigo::DNS::CreateHost.new,
            :path     => "/api/1.1/zones/#{zone_id}/hosts.xml"
          )
        end

      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
fog-0.8.2 lib/fog/dns/requests/zerigo/create_host.rb
fog-0.8.1 lib/fog/dns/requests/zerigo/create_host.rb
fog-0.8.0 lib/fog/dns/requests/zerigo/create_host.rb
fog-0.7.2 lib/fog/dns/requests/zerigo/create_host.rb
fog-0.7.1 lib/fog/dns/requests/zerigo/create_host.rb
fog-0.7.0 lib/fog/dns/requests/zerigo/create_host.rb
fog-0.6.0 lib/fog/dns/requests/zerigo/create_host.rb
fog-0.5.3 lib/fog/dns/requests/zerigo/create_host.rb
fog-0.5.2 lib/fog/dns/requests/zerigo/create_host.rb