SignalFlare 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/SignalFlare.rb +27 -36
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50d252d8243db61dc1cbfcb54fbdd0043093fbd6
4
- data.tar.gz: abf888564d8165b34b5727dd923d20337c1a0990
3
+ metadata.gz: 28fa142aa0d11b9e0844d0019e58b10ec30d9e27
4
+ data.tar.gz: 2b0ad053313bf7215c18a71a74b9f70cc7add108
5
5
  SHA512:
6
- metadata.gz: 79c823071d2616d1a1351b8335bb9a7cb09b58a384f61189df0a19829f965f117c632b5414fb3dfaed3323966f9bcf4524ce73c087345ef18dafca4bae9c7e94
7
- data.tar.gz: 6103b33e3430224878d99f9189143eae73a61b05fd6c598e9aa40a69b17e9debb1634b6d31a806a69eecf29b65ab98ca6e0e5cdf4237168e23c1849ad4b76fa7
6
+ metadata.gz: fcf4bea7e01f0621a7e2972c8dbc60f9742d9ca64b97883990a3159bd9f2fde077e0a929540904ba4d35cfa721f30bb32880fe9704924a5da817701e88781ec4
7
+ data.tar.gz: b82a3355ac662725dc479f6279f180d93e32871a609a2b14fe29b676ce5cabc3b159df30825355bfee4c837094cdb72ba7103f81c05727d586ca62344b94b417
data/lib/SignalFlare.rb CHANGED
@@ -1,55 +1,46 @@
1
1
  require "open-uri"
2
2
  require "cloudflare"
3
3
 
4
- class RecordNotFound < Exception
5
- end
6
-
7
- class RecordUnchanged < Exception
8
- end
9
-
10
4
  class SignalFlare
11
5
  def initialize(api_key, email)
12
- @api_key = api_key
13
- @email = email
14
- @api = CloudFlare::connection(api_key, email)
6
+ self.api_key = api_key
7
+ self.email = email
8
+ self.api = CloudFlare::connection(api_key, email)
15
9
  end
16
10
 
17
11
  def update_ip(hostname)
18
12
  split = hostname.partition(".")
19
- @host, @domain = split[0], split[2]
20
-
21
- begin
22
- record_id = nil
23
- dns_ip = nil
24
- external_ip = fetch_ip()
25
-
26
- @api.rec_load_all(@domain)["response"]["recs"]["objs"].each do |record|
27
- if record["name"] == hostname
28
- record_id = record["rec_id"]
29
- dns_ip = record["content"]
30
- break
31
- end
32
- end
33
-
34
- if record_id == nil
35
- raise RecordNotFound
36
- end
37
-
38
- if dns_ip == external_ip
39
- raise RecordUnchanged
13
+ host = split[0]
14
+ domain = split[2]
15
+
16
+ record_id = nil
17
+ dns_ip = nil
18
+ external_ip = fetch_ip()
19
+
20
+ self.api.rec_load_all(domain)["response"]["recs"]["objs"].each do |record|
21
+ if record["name"] == hostname
22
+ record_id = record["rec_id"]
23
+ dns_ip = record["content"]
24
+ break
40
25
  end
26
+ end
41
27
 
42
- @api.rec_edit(@domain, "A", record_id, hostname, external_ip, 1)
43
-
44
- puts "IP for #{hostname} has been updated from #{dns_ip} to #{external_ip}"
45
- rescue RecordNotFound
28
+ if record_id == nil
46
29
  puts "Suitable record for #{hostname} not found."
47
- rescue RecordUnchanged
30
+ return
31
+ end
32
+
33
+ if dns_ip == external_ip
48
34
  puts "IP for #{hostname} has not changed."
35
+ return
49
36
  end
37
+
38
+ self.api.rec_edit(domain, "A", record_id, hostname, external_ip, 1)
39
+
40
+ puts "IP for #{hostname} has been updated from #{dns_ip} to #{external_ip}"
50
41
  end
51
42
 
52
43
  def fetch_ip
53
- open("http://api.ipify.org").read
44
+ open("http://curlmyip.com").read
54
45
  end
55
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: SignalFlare
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirk Elifson