logankoester-updateafraid 0.1.1

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. data/bin/updateafraid +32 -0
  2. data/lib/updateafraid.rb +57 -0
  3. metadata +71 -0
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+ %w{rubygems optiflag updateafraid}.each { |r| require r }
3
+
4
+ module AfraidCLI extend OptiFlagSet
5
+ flag 'user'
6
+ flag 'password'
7
+ optional_flag 'domain'
8
+ optional_switch_flag 'all'
9
+ and_process!
10
+ end
11
+
12
+ @options = AfraidCLI.flags
13
+ include Updateafraid
14
+
15
+ @account = AfraidAccount.new(@options.user, @options.password)
16
+
17
+ if !@options.domain and !@options.all
18
+ @account.print_domains
19
+ elsif @options.all
20
+ @account.update_all.each {|r| puts r}
21
+ elsif @options.domain
22
+ # Update this specific domain
23
+ updated = @account.update(@options.domain)
24
+ if !updated
25
+ puts "You don't have that domain!\n"
26
+ @account.print_domains
27
+ else
28
+ puts updated
29
+ end
30
+ else
31
+ puts "See --help for usage"
32
+ end
@@ -0,0 +1,57 @@
1
+ %w{rubygems digest/sha1 happymapper open-uri}.each { |r| require r }
2
+
3
+ module Updateafraid
4
+ class AfraidAccount
5
+ attr_accessor :username, :password, :domains
6
+ def initialize(username, password)
7
+ @username, @password = username, password
8
+ @domains = self.getdyndns
9
+ end
10
+
11
+ def getdyndns
12
+ sha1 = Digest::SHA1.hexdigest(@username+'|'+@password)
13
+ xml = open("http://freedns.afraid.org/api/" +
14
+ "?action=getdyndns"+"&sha="+sha1+"&style=xml", "User-Agent" => 'updateafraid.rb').read
15
+ return Domain.parse(xml)
16
+ end
17
+
18
+ def update_all
19
+ responses = Array.new
20
+ @domains.each do |domain|
21
+ responses.push domain.host + " - " + domain.update
22
+ end
23
+ return responses
24
+ end
25
+
26
+ def update(domain)
27
+ o = false
28
+ self.domains.each { |d|
29
+ if d.host == domain
30
+ o = d.update
31
+ break
32
+ end
33
+ }
34
+ return o
35
+ end
36
+
37
+ def print_domains
38
+ puts "You have " + self.domains.size.to_s + " domains:"
39
+ self.domains.each do |d| puts d.host + "\t(" + d.address + ")" end
40
+ end
41
+
42
+ end
43
+
44
+ class Domain
45
+ include HappyMapper
46
+ tag 'item'
47
+ element :host, String
48
+ element :address, String
49
+ element :url, String
50
+
51
+ def update
52
+ open(@url).read
53
+ end
54
+
55
+ end
56
+
57
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logankoester-updateafraid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Logan Koester
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-17 00:00:00 -08:00
13
+ default_executable: bin/updateafraid
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: happymapper
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.1.2
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: optiflag
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 0.6.5
32
+ version:
33
+ description:
34
+ email: logan@logankoester.com
35
+ executables:
36
+ - updateafraid
37
+ extensions: []
38
+
39
+ extra_rdoc_files: []
40
+
41
+ files:
42
+ - bin/updateafraid
43
+ - lib/updateafraid.rb
44
+ has_rdoc: false
45
+ homepage: http://logankoester.com
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project: updateafraid
66
+ rubygems_version: 1.2.0
67
+ signing_key:
68
+ specification_version: 2
69
+ summary: A Dynamic DNS client for domains parked at afraid.org
70
+ test_files: []
71
+