ig3cmd 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/ig3cmd +78 -13
- metadata +4 -3
data/bin/ig3cmd
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
# Client v0.1.
|
3
|
+
# Client v0.1.4 by Lode
|
4
4
|
|
5
5
|
# ----------------
|
6
6
|
# Requirements:
|
@@ -13,9 +13,10 @@ require 'ig3client'
|
|
13
13
|
# ----------------
|
14
14
|
# Items:
|
15
15
|
|
16
|
-
|
16
|
+
INITITEMS = { "cola" => "5449000000996",
|
17
17
|
"colalight" => "5449000050205",
|
18
18
|
"colalightlemon" => "5449000089229",
|
19
|
+
"colazero" => "5449000131805",
|
19
20
|
"fantaorange" => "5449000011527",
|
20
21
|
"fantalemon" => "5449000006004",
|
21
22
|
"minutemaid" => "90494024",
|
@@ -35,7 +36,8 @@ ITEMS = { "cola" => "5449000000996",
|
|
35
36
|
"jempyijshoorntje" => "5400141906080",
|
36
37
|
"icetea" => "5410033820103",
|
37
38
|
"iceteagreen" => "5410033822015",
|
38
|
-
"restolasagne" => "5400141278774"
|
39
|
+
"restolasagne" => "5400141278774",
|
40
|
+
"kinderbueno" => "80052760"
|
39
41
|
}
|
40
42
|
|
41
43
|
# ----------------
|
@@ -46,13 +48,29 @@ module Ig3tool
|
|
46
48
|
# Maak de functies publiek
|
47
49
|
module_function
|
48
50
|
|
51
|
+
class IG3Error < Exception
|
52
|
+
end
|
53
|
+
|
54
|
+
class Token < IG3Error
|
55
|
+
end
|
56
|
+
|
57
|
+
class NotFound < IG3Error
|
58
|
+
end
|
59
|
+
|
49
60
|
class Config
|
50
61
|
@username
|
62
|
+
@items
|
63
|
+
|
51
64
|
def initialize
|
52
65
|
# Ask userinfo if the configfile doesn't exists
|
53
66
|
_ask_userinfo unless File.exists?(File.expand_path("~/.ig3tool"))
|
54
67
|
c = YAML::load(File.open(File.expand_path('~/.ig3tool')))
|
55
68
|
@username = c.username
|
69
|
+
if c.items
|
70
|
+
@items = c.items
|
71
|
+
else
|
72
|
+
@items = INITITEMS
|
73
|
+
end
|
56
74
|
# Ask a password to generate a ig3token
|
57
75
|
_ask_password unless File.exists?(File.expand_path("~/.ig3token"))
|
58
76
|
end
|
@@ -69,6 +87,22 @@ module Ig3tool
|
|
69
87
|
f.close
|
70
88
|
end
|
71
89
|
|
90
|
+
def items
|
91
|
+
@items
|
92
|
+
end
|
93
|
+
|
94
|
+
def item=(newitems)
|
95
|
+
@items = newitems
|
96
|
+
end
|
97
|
+
|
98
|
+
def additem(newitem, barcode)
|
99
|
+
@items[newitem] = barcode
|
100
|
+
# Automatically update the config file
|
101
|
+
f = File.new(File.expand_path('~/.ig3tool'),'wb')
|
102
|
+
f.write self.to_yaml
|
103
|
+
f.close
|
104
|
+
end
|
105
|
+
|
72
106
|
private
|
73
107
|
|
74
108
|
def _ask_userinfo
|
@@ -102,23 +136,39 @@ module Ig3tool
|
|
102
136
|
# Create array with barcodes
|
103
137
|
# Match string with Barcode-list
|
104
138
|
# Scribble expects a list with pairs
|
105
|
-
code =
|
139
|
+
code = $config.items[options.item]
|
106
140
|
code = options.item if code.nil?
|
107
141
|
# If it's not a valid barcode, quit
|
108
142
|
unless code =~ /^\d+$/
|
109
|
-
puts "No
|
143
|
+
puts "No valid barcode or product: #{code}"
|
110
144
|
exit 2
|
111
145
|
end
|
112
146
|
items = [[ code, options.amount ]]
|
113
|
-
username = options.username ||
|
147
|
+
username = options.username || $config.username
|
114
148
|
$client.scribble!({ :debugger => username, :items => items})
|
115
149
|
puts "ScrriiiiiiiiiblleeeDDDDDDDDDD #{options.amount} #{_plural(options.item, options.amount)} for #{username} - oh yeah"
|
116
150
|
exit # Correct executed, exit
|
151
|
+
rescue NotFound
|
152
|
+
puts "Invalid barcode (Product not found)"
|
153
|
+
rescue Token
|
154
|
+
File.delete(File.expand_path("~/.ig3token"))
|
155
|
+
puts "Invalid token deleted!"
|
156
|
+
puts "Please try again..."
|
117
157
|
rescue
|
118
158
|
puts "Error: #{$!}"
|
119
159
|
end
|
120
160
|
end
|
121
161
|
|
162
|
+
def _createitem(options)
|
163
|
+
puts options if options.verbose
|
164
|
+
info = options.item.split(/:/)
|
165
|
+
if info.length == 2
|
166
|
+
$config.additem(info[0], info[1])
|
167
|
+
else
|
168
|
+
puts "Usage: Cola:5449000000996"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
122
172
|
# Start functie
|
123
173
|
def start ()
|
124
174
|
# Connect to ig3tool
|
@@ -127,11 +177,16 @@ module Ig3tool
|
|
127
177
|
$client = Ig3tool::Client.new(host, port)
|
128
178
|
# Load the config
|
129
179
|
# Automatically asks for username if config file doesn't have it filled in
|
130
|
-
|
180
|
+
$config = Config.new
|
131
181
|
# Perform the parse of the arguments
|
132
182
|
options = OptparseIg3tool.parse(ARGV)
|
133
183
|
# Buy/Scribble the items if everything is ok
|
134
|
-
|
184
|
+
case options.action
|
185
|
+
when :buy
|
186
|
+
_buy options
|
187
|
+
when :createitem
|
188
|
+
_createitem options
|
189
|
+
end
|
135
190
|
end
|
136
191
|
|
137
192
|
private
|
@@ -151,16 +206,17 @@ module Ig3tool
|
|
151
206
|
options = OpenStruct.new
|
152
207
|
options.encoding = "utf8"
|
153
208
|
options.verbose = false
|
154
|
-
options.version = "v0.1.
|
209
|
+
options.version = "v0.1.4"
|
155
210
|
options.item = :none
|
211
|
+
options.action = :none
|
156
212
|
options.amount = 1
|
157
213
|
|
158
214
|
opts = OptionParser.new do |opts|
|
159
215
|
|
160
216
|
opts.banner = "\n Ig3tool cmdline (GEEK) Interface\n" +
|
161
|
-
|
162
|
-
|
163
|
-
|
217
|
+
"----------------------------------\n" +
|
218
|
+
"#{options.version} - 27/11/2008\n" +
|
219
|
+
"Usage: ig3cmdtool [options]\n"
|
164
220
|
|
165
221
|
# Actions
|
166
222
|
opts.separator ""
|
@@ -168,11 +224,13 @@ module Ig3tool
|
|
168
224
|
|
169
225
|
opts.on("-c","--cola","Koop een cola") do |n|
|
170
226
|
options.item = "cola"
|
227
|
+
options.action = :buy
|
171
228
|
end
|
172
229
|
|
173
230
|
# with keyword completion ! =))
|
174
|
-
opts.on("-b", "--buy ITEM", String, "Koop een ITEM {#{
|
231
|
+
opts.on("-b", "--buy ITEM", String, "Koop een ITEM {#{$config.items.keys.sort.join(',')}}") do |item|
|
175
232
|
options.item = item
|
233
|
+
options.action = :buy
|
176
234
|
end
|
177
235
|
|
178
236
|
# Boolean switch.
|
@@ -190,6 +248,13 @@ module Ig3tool
|
|
190
248
|
options.username = u
|
191
249
|
end
|
192
250
|
|
251
|
+
# Add item
|
252
|
+
opts.on("-x","--create STRING:BARCODE", String, "Create new item") do |item|
|
253
|
+
options.item = item
|
254
|
+
options.action = :createitem
|
255
|
+
end
|
256
|
+
|
257
|
+
|
193
258
|
# Update Client -> via GEM
|
194
259
|
#opts.on("-U","--update","Update Client") do
|
195
260
|
# path = File.expand_path(__FILE__)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ig3cmd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lode Hoste
|
@@ -9,11 +9,12 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-04
|
12
|
+
date: 2008-12-04 00:00:00 +01:00
|
13
13
|
default_executable: ig3cmd
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: ig3client
|
17
|
+
type: :runtime
|
17
18
|
version_requirement:
|
18
19
|
version_requirements: !ruby/object:Gem::Requirement
|
19
20
|
requirements:
|
@@ -53,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
54
|
requirements: []
|
54
55
|
|
55
56
|
rubyforge_project:
|
56
|
-
rubygems_version: 1.
|
57
|
+
rubygems_version: 1.3.1
|
57
58
|
signing_key:
|
58
59
|
specification_version: 2
|
59
60
|
summary: commandline ig3tool client
|