Class: Ig3tool::GenericClient
- Inherits:
-
Object
- Object
- Ig3tool::GenericClient
- Defined in:
- lib/ig3client/generic_client.rb
Direct Known Subclasses
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
-
#token ⇒ Object
Returns the value of attribute token.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize(host = "infogroep.be", port = "2007", timeout = 0) ⇒ GenericClient
constructor
A new instance of GenericClient.
- #method_missing(msg, *args, &block) ⇒ Object
- #request!(h) ⇒ Object
- #valid_token? ⇒ Boolean
- #wannabe!(h) ⇒ Object
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.("~/.ig3token")).strip rescue Exception => e @token = nil end begin @username = File.read(File.("~/.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
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
#token ⇒ Object
Returns the value of attribute token.
13 14 15 |
# File 'lib/ig3client/generic_client.rb', line 13 def token @token end |
#username ⇒ Object
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
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.("~/.ig3token"), "wb") do |f| f.write @token end File.open(File.("~/.ig3user"), "wb") do |f| f.write @username end #rescue Token => t # raise PermissionDenied end |