Class: Fog::DNS::Rage4::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/rage4/dns.rb,
lib/fog/rage4/requests/dns/get_domain.rb,
lib/fog/rage4/requests/dns/list_domains.rb,
lib/fog/rage4/requests/dns/list_records.rb,
lib/fog/rage4/requests/dns/create_domain.rb,
lib/fog/rage4/requests/dns/create_record.rb,
lib/fog/rage4/requests/dns/delete_domain.rb,
lib/fog/rage4/requests/dns/delete_record.rb,
lib/fog/rage4/requests/dns/update_domain.rb,
lib/fog/rage4/requests/dns/update_record.rb,
lib/fog/rage4/requests/dns/list_geo_regions.rb,
lib/fog/rage4/requests/dns/list_record_types.rb,
lib/fog/rage4/requests/dns/show_global_usage.rb,
lib/fog/rage4/requests/dns/get_domain_by_name.rb,
lib/fog/rage4/requests/dns/show_current_usage.rb,
lib/fog/rage4/requests/dns/bulk_update_records.rb,
lib/fog/rage4/requests/dns/set_record_failover.rb,
lib/fog/rage4/requests/dns/create_domain_vanity.rb,
lib/fog/rage4/requests/dns/create_reverse_domain_4.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fog/rage4/dns.rb', line 36

def initialize(options={})
  @rage4_email = options[:rage4_email]
  @rage4_password  = options[:rage4_api_key]
  @connection_options = options[:connection_options] || {}
  if options[:rage4_url]
    uri = URI.parse(options[:rage4_url])
    options[:host]    = uri.host
    options[:port]    = uri.port
    options[:scheme]  = uri.scheme
  end
  @host       = options[:host]        || "secure.rage4.com"
  @persistent = options[:persistent]  || false
  @port       = options[:port]        || 443
  @scheme     = options[:scheme]      || 'https'
  @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end

Instance Method Details

#bulk_update_records(zone_id, options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fog/rage4/requests/dns/bulk_update_records.rb', line 21

def bulk_update_records(zone_id, options = {})
  path = "/rapi/SetRecordState/#{zone_id}"
  body = options[:body] if options[:body].present?

  request(
          :expects  => 200,
          :method   => 'POST',
          :body     => body,
          :path     => path,
          :headers => {
            'Content-Type' => "application/json; charset=UTF-8",
          },
  )
end

#create_domain(name, options = {}) ⇒ Object

Create a domain.

Parameters

  • name<~String> - domain name

  • email<~String> - email of owner of domain, defaults to email of credentials

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      * 'status'<~Boolean>
      * 'id'<~Integer>
      * 'error'<~String>
      


18
19
20
21
22
23
24
25
# File 'lib/fog/rage4/requests/dns/create_domain.rb', line 18

def create_domain(name, options = {})
  email = options[:email] || @rage4_email
  request(
          :expects  => 200,
          :method   => 'GET',
          :path     => "/rapi/createregulardomain/?name=#{name}&email=#{email}"
  )
end

#create_domain_vanity(name, nsname, options = {}) ⇒ Object

Create a domain with a vanity name server.

Parameters

  • name<~String> - domain name

  • nsname<~String> - vanity ns domain name

  • nsprefix<~String> - prefix for the domain name, defaults to ‘ns’

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      * 'status'<~Boolean>
      * 'id'<~Integer>
      * 'error'<~String>
      


17
18
19
20
21
22
23
24
25
26
# File 'lib/fog/rage4/requests/dns/create_domain_vanity.rb', line 17

def create_domain_vanity(name, nsname, options = {})
  email = options[:email] || @rage4_email
  nsprefix = options[:nsprefix] || 'ns'
  request(
          :expects  => 200,
          :method   => 'GET',
          :path     => "/rapi/createregulardomainext/?name=#{name}&email=#{email}" +
            "&nsname=#{nsname}&nsprefix=#{nsprefix}"
  )
end

#create_record(domain_id, name, content, type, options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fog/rage4/requests/dns/create_record.rb', line 30

def create_record(domain_id, name, content, type, options = {})
  path = "/rapi/createrecord/#{domain_id}"
  path << "?name=#{name}&content=#{content}&type=#{type}"

  path << "&priority=#{options[:priority]}" if options[:priority]

  failover = options[:failover] || 'false'
  path << "&failover=#{failover}"

  path << "&failovercontent=#{options[:failovercontent]}" if options[:failovercontent]

  ttl = options[:ttl] || 3600
  path << "&ttl=#{ttl}"

  path << "&geozone=#{options[:geozone]}" if options[:geozone]
  path << "&geolock=#{options[:geolock]}" if options[:geolock]
  path << "&geolat=#{options[:geolat]}"   if options[:geolat]
  path << "&geolong=#{options[:geolong]}" if options[:geolong]
  path << "&udplimit=#{options[:udplimit]}" if options[:udplimit]

  request(
          :expects  => 200,
          :method   => 'GET',
          :path     => path
  )
end

#create_reverse_domain_4(name, subnet, options = {}) ⇒ Object

Create a reverse domain for an ipv4 address .

Parameters

  • name<~String> - expects an ipv5 address

  • subnet<~Integer> - subnet ie: 9 for /9, range is /8 to /30

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      * 'status'<~Boolean>
      * 'id'<~Integer>
      * 'error'<~String>
      


16
17
18
19
20
21
22
23
24
# File 'lib/fog/rage4/requests/dns/create_reverse_domain_4.rb', line 16

def create_reverse_domain_4(name, subnet, options = {})
  email = options[:email] || @rage4_email
  request(
          :expects  => 200,
          :method   => 'GET',
          :path     => "/rapi/createreversedomain4/?name=#{name}&email=#{email}" +
            "&subnet=#{subnet}"
  )
end

#delete_domain(id) ⇒ Object

Delete a specific domain

Parameters

  • id<~Integer> - numeric ID

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      * 'status'<~Boolean>
      * 'id'<~Integer>
      * 'error'<~String>
      


15
16
17
18
19
20
# File 'lib/fog/rage4/requests/dns/delete_domain.rb', line 15

def delete_domain(id)
  request(
          :expects  => 200,
          :method   => 'GET',
          :path     => "/rapi/deletedomain/#{id}" )
end

#delete_record(id) ⇒ Object

Delete a specific record

Parameters

  • id<~Integer> - numeric record ID

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      * 'status'<~Boolean>
      * 'id'<~Integer>
      * 'error'<~String>
      


15
16
17
18
19
20
# File 'lib/fog/rage4/requests/dns/delete_record.rb', line 15

def delete_record(id)
  request(
          :expects  => 200,
          :method   => 'GET',
          :path     => "/rapi/deleterecord/#{id}" )
end

#get_domain(id) ⇒ Object

Get the details for a specific domain in your account.

Parameters

  • id<~Integer> - numeric ID

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      * 'id'<~Integer>
      * 'name'<~String>
      * 'owner_email'<~String>
      * 'type'<~Integer>
      * 'subnet_mask'<~Integer>
      


17
18
19
20
21
22
# File 'lib/fog/rage4/requests/dns/get_domain.rb', line 17

def get_domain(id)
  request(
          :expects  => 200,
          :method   => 'GET',
          :path     => "/rapi/getdomain/#{id}" )
end

#get_domain_by_name(name) ⇒ Object

Get the details for a specific domain in your account.

Parameters

  • name<~String> - name of domain

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      * 'id'<~Integer>
      * 'name'<~String>
      * 'owner_email'<~String>
      * 'type'<~Integer>
      * 'subnet_mask'<~Integer>
      


17
18
19
20
21
22
# File 'lib/fog/rage4/requests/dns/get_domain_by_name.rb', line 17

def get_domain_by_name(name)
  request(
          :expects  => 200,
          :method   => 'GET',
          :path     => "/rapi/getdomainbyname/?name=#{name}")
end

#list_domainsObject

Get the lsit of all domains for your account.

Parameters

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • ‘domains’<~Hash>

        • ‘id’<~Integer>

        • ‘name’<~String>

        • ‘owner_email’<~String>

        • ‘type’<~Integer>

        • ‘subnet_mask’<~Integer>



17
18
19
20
21
22
23
# File 'lib/fog/rage4/requests/dns/list_domains.rb', line 17

def list_domains
  request(
          :expects  => 200,
          :method   => 'GET',
          :path     => '/rapi/getdomains'
          )
end

#list_geo_regionsObject

List all the geo regions available

Parameters

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • ‘record types’<~Hash> *‘name’ <~String> geo record name *‘value’ <~Integer> Integer value of the type



15
16
17
18
19
20
21
# File 'lib/fog/rage4/requests/dns/list_geo_regions.rb', line 15

def list_geo_regions
  request(
          :expects  => 200,
          :method   => 'GET',
          :path     => '/rapi/listgeoregions'
          )
end

#list_record_typesObject

List all the record types available

Parameters

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • ‘record types’<~Hash> *‘name’ <~String> record type name *‘value’ <~Integer> Integer value of the type



14
15
16
17
18
19
20
# File 'lib/fog/rage4/requests/dns/list_record_types.rb', line 14

def list_record_types
  request(
          :expects  => 200,
          :method   => 'GET',
          :path     => '/rapi/listrecordtypes'
          )
end

#list_records(id) ⇒ Object

Get the list of records for the specific domain.

Parameters

  • id<~Integer>

Returns

  • response<~Excon::Response>:

    • records<Array~>

      • name<~String>

      • ttl<~Integer>

      • updated_at<~String>

      • domain_id<~Integer>

      • id<~Integer>

      • content<~String>

      • record_type<~String>

      • priority<~Integer>



20
21
22
23
24
# File 'lib/fog/rage4/requests/dns/list_records.rb', line 20

def list_records(id)
  request( :expects  => 200,
           :method   => "GET",
           :path     => "/rapi/getrecords/#{id}" )
end

#reloadObject



53
54
55
# File 'lib/fog/rage4/dns.rb', line 53

def reload
  @connection.reset
end

#request(params) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fog/rage4/dns.rb', line 57

def request(params)
  params[:headers] ||= {}
  key = "#{@rage4_email}:#{@rage4_password}"
  params[:headers].merge!({ "Authorization" => "Basic " + Base64.encode64(key).gsub("\n",'')})

  response = @connection.request(params)

  unless response.body.empty?
    response.body = Fog::JSON.decode(response.body)
  end
  response
end

#set_record_failover(id, active, failover) ⇒ Object

Set a failover to on or off

Parameters

  • id<~Integer> - numeric ID

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      * 'status'<~Boolean>
      * 'id'<~Integer>
      * 'error'<~String>
      


15
16
17
18
19
20
21
# File 'lib/fog/rage4/requests/dns/set_record_failover.rb', line 15

def set_record_failover(id, active, failover)
  request(
          :expects  => 200,
          :method   => 'GET',
          :path     => "/rapi/setrecordfailover/#{id}&active=#{active}&failover=#{failover}"
    )
end

#show_current_usage(id) ⇒ Object

Shows current usage for a single domain

Parameters

  • id<~Integer> - domain name numeric ID

Returns

  • response<~Excon::Response>:

    • body<~Array>



12
13
14
15
16
17
# File 'lib/fog/rage4/requests/dns/show_current_usage.rb', line 12

def show_current_usage(id)
  request(
          :expects  => 200,
          :method   => 'GET',
          :path     => "/rapi/showcurrentusage/#{id}" )
end

#show_global_usageObject

Shows global usage for all domains

Parameters

Returns

  • response<~Excon::Response>:

    • body<~Array>



12
13
14
15
16
17
# File 'lib/fog/rage4/requests/dns/show_global_usage.rb', line 12

def show_global_usage
  request(
          :expects  => 200,
          :method   => 'GET',
          :path     => "/rapi/showcurrentglobalusage/" )
end

#update_domain(id, options = {}) ⇒ Object

Update an existing domain

Parameters

  • id<~Integer> - domain integer value

  • email <~String> - email of domain owner

  • nsprefix<~String> - vanity ns prefix (nullable)

  • nsname<~String> - vanity ns domain name (nullable)

  • enablevanity<~String> - activate/deactivate

  • failover<~Boolean> - failover enable

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      * 'status'<~Boolean>
      * 'id'<~Integer>
      * 'error'<~String>
      


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fog/rage4/requests/dns/update_domain.rb', line 20

def update_domain(id, options = {})
  email = options[:email] || @rage4_email

  path = "/rapi/updatedomain/#{id}?email=#{email}"

  path << "&nsname=#{options[:nsname]}"              if options[:nsname]
  path << "&nsprefix=#{options[:nsprefix]}"          if options[:nsprefix]
  path << "&enablevanity=#{options[:enablevanity]}"  if options[:enablevanity]
  path << "&failover=#{options[:failover]}"          if options[:failover]

  request(
          :expects  => 200,
          :method   => 'GET',
          :path     =>  path
  )
end

#update_record(record_id, name, content, type, options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fog/rage4/requests/dns/update_record.rb', line 30

def update_record(record_id, name, content, type, options = {})
  path = "/rapi/updaterecord/#{record_id}"
  path << "?name=#{name}&content=#{content}&type=#{type}"

  path << "&priority=#{options[:priority]}" if options[:priority]

  failover = options[:failover] || 'false'
  path << "&failover=#{failover}"

  path << "&failovercontent=#{options[:failovercontent]}" if options[:failovercontent]

  ttl = options[:ttl] || 3600
  path << "&ttl=#{ttl}"

  path << "&geozone=#{options[:geozone]}" if options[:geozone]
  path << "&geolock=#{options[:geolock]}" if options[:geolock]
  path << "&geolat=#{options[:geolat]}"   if options[:geolat]
  path << "&geolong=#{options[:geolong]}" if options[:geolong]
  path << "&udplimit=#{options[:udplimit]}" if options[:udplimit]

  request(
          :expects  => 200,
          :method   => 'GET',
          :path     => path
  )
end