Class: Zonesync::Cloudflare

Inherits:
Provider show all
Defined in:
lib/zonesync/cloudflare.rb

Instance Attribute Summary

Attributes inherited from Provider

#config

Instance Method Summary collapse

Methods inherited from Provider

#add_with_duplicate_handling, #diff, #diff!, #diffable_records, from, #initialize, #manifest, #records, #write

Constructor Details

This class inherits a constructor from Zonesync::Provider

Instance Method Details

#add(record) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/zonesync/cloudflare.rb', line 28

def add record
  add_with_duplicate_handling(record) do
    begin
      http.post("", to_hash(record))
    rescue RuntimeError => e
      # Convert CloudFlare-specific duplicate error to standard exception
      if e.message.include?('"code":81058') && e.message.include?("An identical record already exists")
        raise DuplicateRecordError.new(record, "CloudFlare error 81058")
      else
        # Re-raise other errors
        raise
      end
    end
  end
end

#allObject



45
46
47
48
49
50
# File 'lib/zonesync/cloudflare.rb', line 45

def all
  response = http.get("")
  response["result"].reduce({}) do |map, attrs|
    map.merge to_record(attrs) => attrs["id"]
  end
end

#change(old_record, new_record) ⇒ Object



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

def change old_record, new_record
  id = all.fetch(old_record)
  http.patch("/#{id}", to_hash(new_record))
end

#readObject



10
11
12
13
# File 'lib/zonesync/cloudflare.rb', line 10

def read
  records = [fake_soa] + all.keys
  records.map(&:to_s).join("\n") + "\n"
end

#remove(record) ⇒ Object



16
17
18
19
# File 'lib/zonesync/cloudflare.rb', line 16

def remove record
  id = all.fetch(record)
  http.delete("/#{id}")
end