Class: CloudParty::Nodes::Zones

Inherits:
Object
  • Object
show all
Includes:
Context, HTTParty
Defined in:
lib/cloud_party/nodes/zones.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Context

included

Constructor Details

#initialize(options = {}) ⇒ Zones

Returns a new instance of Zones.



30
31
32
33
# File 'lib/cloud_party/nodes/zones.rb', line 30

def initialize(options = {})
  super()
  @options = options
end

Class Method Details

.set_id_by_name(zone) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cloud_party/nodes/zones.rb', line 16

def self.set_id_by_name(zone)
  options = {
      match: 'all',
      name: zone,
      order: 'name'
  }
  if @options.nil?
    @options = options
  else
    @options.merge!(options)
  end

  @@zone = CloudParty::Responses::Zones.new(:get, '/zones', get('/zones', query: @options), @options).result.first.fetch(:id, nil)
end

Instance Method Details

#add_record(type, name, content, opts, zone:) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/cloud_party/nodes/zones.rb', line 43

def add_record(type, name, content, opts, zone:)
  zone_id = nil
  options = {
      type: type,
      name: name,
      content: content
  }
  ttl = opts.fetch('ttl', nil)
  priority = opts.fetch('priority', nil)
  proxied = opts.fetch('proxied', nil)
  options.merge!(ttl: ttl) unless ttl.nil?
  options.merge!(priority: priority) unless priority.nil?
  options.merge!(proxied: proxied) unless proxied.nil?
  if zone
    zone_options = {
        match: 'all',
        name: zone,
        order: 'name'
    }
    zone_id = CloudParty::Responses::Zones.new(:get, '/zones', get('/zones', query: zone_options), @options).result.first.fetch(:id, nil)
  end

  CloudParty::Responses::Zones.new(
      :post,
      '/zones/',
      self.class.get("/zones/#{@@zone || zone_id}/dns_records", options),
      @options)
end

#get(id) ⇒ Object



39
40
41
# File 'lib/cloud_party/nodes/zones.rb', line 39

def get(id)
  CloudParty::Responses::Zones.new(:get, '/zones/:id', self.class.get("/zones/#{id}"), @options)
end

#listObject



35
36
37
# File 'lib/cloud_party/nodes/zones.rb', line 35

def list
  CloudParty::Responses::Zones.new(:get, '/zones', self.class.get('/zones'), @options)
end