Class: DNSRecordUpdater::DNSUpdater
- Inherits:
-
Object
- Object
- DNSRecordUpdater::DNSUpdater
- Defined in:
- lib/dns_record_updater/dns_updater.rb
Instance Method Summary collapse
-
#initialize(provider, notification_service: nil) ⇒ DNSUpdater
constructor
A new instance of DNSUpdater.
- #update(send_notification: false) ⇒ Object
Constructor Details
#initialize(provider, notification_service: nil) ⇒ DNSUpdater
Returns a new instance of DNSUpdater.
5 6 7 8 |
# File 'lib/dns_record_updater/dns_updater.rb', line 5 def initialize(provider, notification_service: nil) @provider = provider @notification_service = notification_service end |
Instance Method Details
#update(send_notification: false) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dns_record_updater/dns_updater.rb', line 10 def update(send_notification: false) ip = fetch_public_ip puts "Detected public IP: #{ip}" dns_record = @provider.fetch_dns_record record_id = dns_record[:record_id] current_ip = dns_record[:current_ip] if ip == current_ip puts "IP has not changed: #{ip}" return true end success = @provider.update_dns_record(ip, record_id) if send_notification && success @notification_service&.notify("DNS record updated: #{@provider.record_name} -> #{ip}") end success rescue StandardError => e puts "Error during update: #{e.}" false end |