CloudflareApi.DnsRecord (cloudflare_api v0.6.0)

View Source

Makes a struct and convenience functions around A Cloudflare DNS record.

See Cloudflare docs: https://api.cloudflare.com/#dns-records-for-a-zone-properties

Summary

Functions

cf_url(record) deprecated

Build the Cloudflare DNS records URL for a given record.

Build a CloudflareApi.DnsRecord struct from a Cloudflare-style map.

Convert a CloudflareApi.DnsRecord struct into the JSON body Cloudflare expects when creating or updating a record.

Types

record_type()

@type record_type() ::
  :A
  | :AAAA
  | :CNAME
  | :HTTPS
  | :TXT
  | :SRV
  | :LOC
  | :MX
  | :NS
  | :CERT
  | :DNSKEY
  | :DS
  | :NAPTR
  | :SMIMEA
  | :SSHFP
  | :SVCB
  | :TLSA
  | :URI

t()

@type t() :: %CloudflareApi.DnsRecord{
  created_on: String.t() | nil,
  hostname: String.t(),
  id: String.t() | nil,
  ip: String.t(),
  locked: boolean() | nil,
  proxiable: boolean() | nil,
  proxied: boolean() | nil,
  ttl: non_neg_integer(),
  type: record_type(),
  zone_id: String.t(),
  zone_name: String.t() | nil
}

ttl()

@type ttl() :: record_type()

Functions

cf_url(record)

This function is deprecated. Use t:record_type/0 instead; kept for backward compatibility..
@spec cf_url(t()) :: String.t()

Build the Cloudflare DNS records URL for a given record.

This is primarily useful for debugging or when you need to reason about the REST endpoint for a specific record.

from_cf_json(record)

@spec from_cf_json(map()) :: t()

Build a CloudflareApi.DnsRecord struct from a Cloudflare-style map.

The input may use either atom keys (for example :zone_id) or string keys (for example "zone_id"); keys are normalized before the struct is built.

Examples

iex> source = %{
...>   "id" => "id",
...>   "zone_id" => "zone-id",
...>   "zone_name" => "example.com",
...>   "name" => "www.example.com",
...>   "content" => "1.2.3.4",
...>   "created_on" => "now",
...>   "type" => "A",
...>   "ttl" => 120,
...>   "proxied" => true,
...>   "proxiable" => true,
...>   "locked" => false
...> }
iex> record = CloudflareApi.DnsRecord.from_cf_json(source)
iex> {record.id, record.zone_id, record.hostname, record.ip}
{"id", "zone-id", "www.example.com", "1.2.3.4"}

to_cf_json(record)

@spec to_cf_json(t()) :: map()

Convert a CloudflareApi.DnsRecord struct into the JSON body Cloudflare expects when creating or updating a record.