Module: Cloudflare::DDNS

Defined in:
lib/cloudflare/ddns.rb,
lib/cloudflare/ddns/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

IP_RESOLVER =
'https://api.ipify.org'
VERSION =
'0.1.0'

Class Method Summary collapse

Class Method Details

.fetch_ipObject



22
23
24
# File 'lib/cloudflare/ddns.rb', line 22

def self.fetch_ip
  HTTParty.get(IP_RESOLVER).body
end

.update_record(api_token, zone_name, record_name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/cloudflare/ddns.rb', line 11

def self.update_record(api_token, zone_name, record_name)
  api = API.new(api_token)
  zone_api = api.zone_api(zone_name)
  record = zone_api.record(record_name)
  current_ip = fetch_ip
  return if record['content'] == current_ip

  zone_api.patch_record(record['id'], content: current_ip)
  current_ip
end