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.
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 51 |
# File 'lib/ig3client/generic_client.rb', line 16 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
105 106 107 |
# File 'lib/ig3client/generic_client.rb', line 105 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.
14 15 16 |
# File 'lib/ig3client/generic_client.rb', line 14 def token @token end |
#username ⇒ Object
Returns the value of attribute username.
14 15 16 |
# File 'lib/ig3client/generic_client.rb', line 14 def username @username end |
Instance Method Details
#request!(h) ⇒ Object
63 64 65 |
# File 'lib/ig3client/generic_client.rb', line 63 def request!(h) wannabe!(h) end |
#valid_token? ⇒ Boolean
53 54 55 56 57 58 59 60 61 |
# File 'lib/ig3client/generic_client.rb', line 53 def valid_token? # XXX send no-op to server false if @token.nil? begin self.validate rescue return false end end |
#wannabe!(h) ⇒ Object
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 102 |
# File 'lib/ig3client/generic_client.rb', line 67 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 |