Class: Updateafraid::AfraidAccount

Inherits:
Object
  • Object
show all
Defined in:
lib/updateafraid.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ AfraidAccount

Returns a new instance of AfraidAccount.



6
7
8
9
# File 'lib/updateafraid.rb', line 6

def initialize(username, password)
	@username, @password = username, password
	@domains = self.getdyndns
end

Instance Attribute Details

#domainsObject

Returns the value of attribute domains.



5
6
7
# File 'lib/updateafraid.rb', line 5

def domains
  @domains
end

#passwordObject

Returns the value of attribute password.



5
6
7
# File 'lib/updateafraid.rb', line 5

def password
  @password
end

#usernameObject

Returns the value of attribute username.



5
6
7
# File 'lib/updateafraid.rb', line 5

def username
  @username
end

Instance Method Details

#getdyndnsObject



11
12
13
14
15
16
# File 'lib/updateafraid.rb', line 11

def getdyndns
	sha1 = Digest::SHA1.hexdigest(@username+'|'+@password)
	xml = open("http://freedns.afraid.org/api/" + 
		"?action=getdyndns"+"&sha="+sha1+"&style=xml", "User-Agent" => 'updateafraid.rb').read
	return Domain.parse(xml)
end


37
38
39
40
# File 'lib/updateafraid.rb', line 37

def print_domains
	puts "You have " + self.domains.size.to_s + " domains:"
	self.domains.each do |d| puts d.host + "\t(" + d.address + ")" end
end

#update(domain) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/updateafraid.rb', line 26

def update(domain)
	o = false
	self.domains.each { |d|
		if d.host == domain
			o = d.update
			break
		end
	}
	return o
end

#update_allObject



18
19
20
21
22
23
24
# File 'lib/updateafraid.rb', line 18

def update_all
	responses = Array.new
	@domains.each do |domain|
		responses.push domain.host + " - " + domain.update
	end
	return responses
end