Class: Acmesmith::Cloudflare::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/acmesmith/cloudflare/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_token:, api_base: nil) ⇒ Client

Returns a new instance of Client.



12
13
14
15
# File 'lib/acmesmith/cloudflare/client.rb', line 12

def initialize(api_token:, api_base: nil)
  @api_token = api_token
  @api_base = (api_base || DEFAULT_API_BASE).sub(%r{/*$}, '')
end

Instance Method Details

#create_dns_record(zone_id:, name:, type:, content:, ttl:, comment: nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/acmesmith/cloudflare/client.rb', line 35

def create_dns_record(zone_id:, name:, type:, content:, ttl:, comment: nil)
  payload = {
    type: type,
    name: name,
    content: content,
    ttl: ttl,
    proxied: false,
  }
  payload[:comment] = comment if comment

  post("/zones/#{zone_id}/dns_records", body: payload)
end

#delete_dns_record(zone_id:, record_id:) ⇒ Object



48
49
50
# File 'lib/acmesmith/cloudflare/client.rb', line 48

def delete_dns_record(zone_id:, record_id:)
  delete("/zones/#{zone_id}/dns_records/#{record_id}")
end

#list_dns_records(zone_id:, page: 1, per_page: 100, type: nil) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/acmesmith/cloudflare/client.rb', line 25

def list_dns_records(zone_id:, page: 1, per_page: 100, type: nil)
  query = {
    page: page.to_s,
    per_page: per_page.to_s,
  }
  query[:type] = type if type

  get("/zones/#{zone_id}/dns_records", query: query)
end

#list_zones(name:) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/acmesmith/cloudflare/client.rb', line 17

def list_zones(name:)
  get('/zones', query: {
    name: name,
    status: 'active',
    per_page: '50',
  })
end