Class: Ig3tool::GenericClient

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

Direct Known Subclasses

Client, YAMLClient

Constant Summary collapse

EXPIRY =

15 minuten

900
BIG_QUERIES =
[ :person_debuggers,   :person_honorarymembers,
:person_members,     :person_nonmembers,
:person_everybody,
:product_categories, :product_all ]
@@CACHE =
{}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host = "infogroep.be", port = "2007", timeout = 0) ⇒ GenericClient

Returns a new instance of GenericClient.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ig3client/generic_client.rb', line 15

def initialize(host="infogroep.be", port="2007", timeout=0)
	@host    = host
	@port    = port
	@timeout = timeout # 0 = no timeout.

	begin
		@token = File.read(File.expand_path("~/.ig3token")).strip
	rescue Exception => e
		@token = nil
	end

	begin
		@username = File.read(File.expand_path("~/.ig3user")).strip
	rescue Exception => e
		@username = Etc.getpwuid(Process::Sys.geteuid).name
	end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(msg, *args, &block) ⇒ Object

Raises:

  • (Exception)


67
68
69
# File 'lib/ig3client/generic_client.rb', line 67

def method_missing(msg, *args, &block)
	raise Exception, "this is an abstract class"
end

Instance Attribute Details

#tokenObject

Returns the value of attribute token.



13
14
15
# File 'lib/ig3client/generic_client.rb', line 13

def token
  @token
end

#usernameObject

Returns the value of attribute username.



13
14
15
# File 'lib/ig3client/generic_client.rb', line 13

def username
  @username
end

Instance Method Details

#request!(h) ⇒ Object



43
44
45
# File 'lib/ig3client/generic_client.rb', line 43

def request!(h)
	wannabe!(h)
end

#valid_token?Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
41
# File 'lib/ig3client/generic_client.rb', line 33

def valid_token?
	# XXX send no-op to server
	false if @token.nil?
	begin
		self.validate
	rescue
		return false
	end
end

#wannabe!(h) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ig3client/generic_client.rb', line 47

def wannabe!(h)
	username = h["username"]
	passwd   = h["password"]
	# request token
	# if ok => store in file
	# else => throw exception
	@token = method_missing("wannabe!", {"username" => username,"password" =>  passwd})

	File.open(File.expand_path("~/.ig3token"), "wb") do |f|
		f.write @token
	end

	File.open(File.expand_path("~/.ig3user"), "wb") do |f|
		f.write @username
	end
	#rescue Token => t
	#	raise PermissionDenied
end