Class: Zonesync::Cloudflare
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
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
if e.message.include?('"code":81058') && e.message.include?("An identical record already exists")
raise DuplicateRecordError.new(record, "CloudFlare error 81058")
else
raise
end
end
end
end
|
#all ⇒ Object
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
|
#read ⇒ Object
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
|