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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# 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 begin @token = File.read(File.("~/.ig3token")).strip rescue Exception => e userdir = File.join(ENV['userprofile'].to_s, "ig3tool") tokenpath = File.join(userdir, "ig3token") Dir.mkdir(userdir) unless File.exists?(userdir) @token = File.read(tokenpath) end rescue Exception => e @token = nil end begin begin begin @username = File.read(File.("~/.ig3user")).strip rescue Exception => e @username = ENV["USER"] || \ Etc.getpwuid(Process::Sys.geteuid).name end rescue Exception => e userdir = File.join(ENV['userprofile'].to_s, "ig3tool") Dir.mkdir(userdir) unless File.exists?(userdir) usernamepath = File.join(userdir, "ig3user") @username = File.read(usernamepath) end rescue Exception => e @username = nil end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(msg, *args, &block) ⇒ Object
104 105 106 |
# File 'lib/ig3client/generic_client.rb', line 104 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
62 63 64 |
# File 'lib/ig3client/generic_client.rb', line 62 def request!(h) wannabe!(h) end |
#valid_token? ⇒ Boolean
52 53 54 55 56 57 58 59 60 |
# File 'lib/ig3client/generic_client.rb', line 52 def valid_token? # XXX send no-op to server false if @token.nil? begin self.validate rescue return false end end |
#wannabe!(h) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/ig3client/generic_client.rb', line 66 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}) begin File.open(File.("~/.ig3token"), "wb") do |f| f.write @token end rescue Exception => e userdir = File.join(ENV['userprofile'].to_s, "ig3tool") tokenpath = File.join(userdir, "ig3token") Dir.mkdir(userdir) unless File.exists?(userdir) File.open(tokenpath, "wb") do |f| f.write @token end end begin File.open(File.("~/.ig3user"), "wb") do |f| f.write @username end rescue Exception => e userdir = File.join(ENV['userprofile'].to_s, "ig3tool") usernamepath = File.join(userdir, "ig3user") Dir.mkdir(userdir) unless File.exists?(userdir) File.open(usernamepath, "wb") do |f| f.write @username end end #rescue Token => t # raise PermissionDenied end |