ig3client 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/ig3client.rb +19 -8
  2. data/lib/lib/errors.rb +6 -0
  3. metadata +5 -2
data/lib/ig3client.rb CHANGED
@@ -1,10 +1,11 @@
1
- require 'lib/util.rb'
2
- require 'lib/errors.rb'
1
+ require 'etc'
3
2
  require 'net/http'
4
3
  require 'yaml'
5
4
  require 'timeout'
6
5
  require 'rubygems'
7
6
  require 'facets'
7
+ require 'lib/util.rb'
8
+ require 'lib/errors.rb'
8
9
 
9
10
  # External Options:
10
11
  #
@@ -40,7 +41,7 @@ module Ig3tool
40
41
 
41
42
  class Client
42
43
 
43
- attr_accessor :token
44
+ attr_accessor :token, :username
44
45
 
45
46
  def initialize(host="infogroep.be", port="2007", timeout=0)
46
47
  @host = host
@@ -52,6 +53,12 @@ module Ig3tool
52
53
  rescue Exception => e
53
54
  @token = nil
54
55
  end
56
+
57
+ begin
58
+ @username = File.read(File.expand_path("~/.ig3user")).strip
59
+ rescue Exception => e
60
+ @username = Etc.getpwuid(Process::Sys.geteuid).name
61
+ end
55
62
  end
56
63
 
57
64
  def valid_token?
@@ -70,14 +77,19 @@ module Ig3tool
70
77
 
71
78
  def wannabe!(h)
72
79
  username = h["username"]
73
- passwd = h["password"]
80
+ passwd = h["password"]
74
81
  # request token
75
82
  # if ok => store in file
76
83
  # else => throw exception
77
84
  @token = method_missing("wannabe!", {"username" => username,"password" => passwd})
78
- f = File.new(File.expand_path("~/.ig3token"), "wb")
79
- f.write @token
80
- f.close
85
+
86
+ File.open(File.expand_path("~/.ig3token"), "wb") do |f|
87
+ f.write @token
88
+ end
89
+
90
+ File.open(File.expand_path("~/.ig3user"), "wb") do |f|
91
+ f.write @username
92
+ end
81
93
  #rescue Token => t
82
94
  # raise PermissionDenied
83
95
  end
@@ -86,7 +98,6 @@ module Ig3tool
86
98
  def method_missing(msg, *args, &block)
87
99
  msg = msg.to_s
88
100
 
89
-
90
101
  if match = /^async_(.*)/.match(msg)
91
102
  raise "Async method called, no block given!" unless block_given?
92
103
  Thread.new do
data/lib/lib/errors.rb CHANGED
@@ -30,6 +30,12 @@ module Ig3tool
30
30
  class WrongRequestType < IG3Error
31
31
  end
32
32
 
33
+ class InternalError < IG3Error
34
+ end
35
+
36
+ class StockEmpty < IG3Error
37
+ end
38
+
33
39
 
34
40
  # PRINTING
35
41
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ig3client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Pinte
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-03-05 00:00:00 +01:00
12
+ date: 2008-03-23 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -31,6 +31,7 @@ extra_rdoc_files: []
31
31
 
32
32
  files:
33
33
  - lib/ig3client.rb
34
+ - lib/lib
34
35
  - lib/lib/errors.rb
35
36
  - lib/lib/util.rb
36
37
  has_rdoc: false
@@ -40,6 +41,8 @@ rdoc_options: []
40
41
 
41
42
  require_paths:
42
43
  - lib
44
+ - lib
45
+ - lib/ui
43
46
  required_ruby_version: !ruby/object:Gem::Requirement
44
47
  requirements:
45
48
  - - ">="