slimtimercli 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,11 @@
1
+ == 0.1.5 2008-04-07
2
+ * Under-the-hood changes, now it's easier to maintain and is probably a tad faster
3
+
4
+ == 0.1.4 2008-04-07
5
+ * Ruby 1.9 compatibility
6
+ * use the XDG specification for configuration file storage location, but keep
7
+ compatibility with the older model.
8
+
1
9
  == 0.1.3 2008-04-07
2
10
  * fixed bug that allows starting a nonexisting task
3
11
  * refactored options to start slimtimer
data/bin/slimtimer CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'rubygems'
3
3
 
4
- gem 'slimtimercli'
4
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
5
5
  require 'slimtimercli'
6
6
 
7
7
  include Slimtimercli
8
8
 
9
9
  c = CommandLine.new(ARGV)
10
- c.run
10
+ c.run
data/config/hoe.rb CHANGED
@@ -10,7 +10,7 @@ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
10
 
11
11
  @config_file = "~/.rubyforge/user-config.yml"
12
12
  @config = nil
13
- RUBYFORGE_USERNAME = "unknown"
13
+ RUBYFORGE_USERNAME = "grundprinzip"
14
14
  def rubyforge_username
15
15
  unless @config
16
16
  begin
@@ -67,4 +67,4 @@ end
67
67
  CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
68
68
  PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
69
69
  $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
70
- $hoe.rsync_args = '-av --delete --ignore-errors'
70
+ $hoe.rsync_args = '-av --delete --ignore-errors'
@@ -2,15 +2,13 @@ class SlimTimer
2
2
 
3
3
  DATE_FORMAT = "%Y-%m-%d %H-%M-%S"
4
4
 
5
- @@host = "slimtimer.com"
6
- @@port = 80
7
- #@@api_key = ""
8
-
9
5
  attr_accessor :tasks, :time_entries
10
6
 
11
7
  def initialize(user, pass, api)
12
8
  @user = user; @pass = pass
13
9
  @api_key = api
10
+ @host = "slimtimer.com"
11
+ @port = 80
14
12
  end
15
13
 
16
14
  # Performs the login to the system, and stores
@@ -122,7 +120,7 @@ class SlimTimer
122
120
  params = {"api_key" => @api_key}.merge(params)
123
121
  # If token there merge it
124
122
  params = {"access_token" => @token}.merge(params) if @token
125
- res, body = Net::HTTP.start(@@host,@@port) {|http|
123
+ res, body = Net::HTTP.start(@host,@port) {|http|
126
124
  p params if $DEBUG
127
125
  method.body = params.to_yaml
128
126
  http.request(method)
@@ -2,7 +2,7 @@ module Slimtimercli #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 4
5
+ TINY = 6
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/slimtimercli.rb CHANGED
@@ -1,204 +1,41 @@
1
- $:.unshift(File.dirname(__FILE__)) unless
2
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
-
4
1
  require 'fileutils'
5
2
  require 'net/http'
6
3
  require 'rubygems'
7
4
  require 'active_record'
8
5
  require 'active_support'
9
- require 'yaml'
6
+ require 'yaml'
10
7
  require 'optparse'
11
8
  require 'ostruct'
12
9
 
13
10
  require "slimtimercli/entities"
14
11
  require "slimtimercli/slim_timer"
15
12
  require "slimtimercli/version"
13
+ require "slimtimercli/helper"
16
14
 
17
15
  module Slimtimercli
18
- module Helper
19
- def login
20
- config = load_config
21
- st = SlimTimer.new(config["email"], config["password"],
22
- config["api_key"])
23
- st.login
24
-
25
- st
26
- end
27
-
28
- def root
29
- File.join(ENV["HOME"], ".slimtimer")
30
- end
31
-
32
- def config_file
33
- File.join(root, "config.yml")
34
- end
35
-
36
- def tasks_file
37
- File.join(root, "tasks.yml")
38
- end
39
-
40
- def current_file
41
- File.join(root, "current.yml")
42
- end
43
-
44
- def check_and_create_dir
45
- raise "Home DIR not set!" unless ENV["HOME"]
46
-
47
- unless File.directory?(root)
48
- FileUtils.mkdir(root)
49
- end
50
- end
51
-
52
- def load_config
53
- check_and_create_dir
54
-
55
- unless File.exists?(File.join(root, "config.yml"))
56
- File.open( File.join(root, "config.yml"), 'w' ) do |out|
57
- YAML.dump({}, out )
58
- end
59
- end
60
- load_file("config.yml")
61
- end
62
-
63
- def save_config(config)
64
- dump_to_file(config, "config.yml")
65
- end
66
-
67
- def load_file(file)
68
- File.open( File.join(root, file) ) { |yf| YAML::load( yf ) }
69
- end
70
-
71
- def dump_to_file(object, file)
72
- check_and_create_dir
73
- File.open( File.join(root, file), 'w' ) do |out|
74
- YAML.dump(object, out )
75
- end
76
- end
77
-
78
- def rm_current
79
- FileUtils.rm(current_file) if
80
- File.exists?(current_file)
81
- end
82
-
83
- def parse(args)
84
-
85
- if !args || args.empty?
86
- raise "Need to specify arguments, run slimtimer -h for help"
87
-
88
- end
89
-
90
- options = OpenStruct.new
91
- options.force = false
92
-
93
- opts = OptionParser.new do |opts|
94
-
95
- opts.banner = "Usage: slimtimer [options]"
96
-
97
- opts.on("-s TASK", "--start TASK",
98
- "Start a TASK given by the task name") do |t|
99
-
100
- options.run = "start"
101
- options.task_name = t
102
- end
103
-
104
- opts.on("-c TASK", "--create TASK",
105
- "Create a ne task by the given name") do |t|
106
- options.run = "create"
107
- options.task_name = t
108
- end
109
-
110
- opts.on("-e", "--end" ,"Stops time recording for the given task") do
111
- options.run = "stop"
112
- end
113
-
114
- opts.on("-t", "--tasks", "Prints all available tasks") do
115
- options.run = "tasks"
116
- end
117
-
118
- opts.on("-f", "--force", "Force deletion of tasks") do
119
- options.force = true
120
- end
121
-
122
- opts.on("--setup", "Setup your account") do
123
- options.run = "setup"
124
- end
125
-
126
- opts.on_tail("-h", "Shows this note") do
127
- puts opts
128
- exit
129
- end
130
-
131
- opts.on("--help", "Show verbose help") do
132
- @out.puts <<-HELP
133
- SlimTimer is a tool to record your time spend on a
134
- task. SlimTimer CLI allows you to controll your
135
- SlimTimer directly from where you spend most of your
136
- time - on the command line. To use SlimTimer proceed
137
- with the following steps:
138
-
139
- The first time you need to setup SlimTimer CLI with
140
-
141
- slimtimer --setup
142
-
143
- Now it will ask for your email and password and API key
144
- to use with your account. These information will be stored
145
- in ~/.slimtimer/config.yml
146
-
147
- To create a task run
148
-
149
- slimtimer -c my_shiny_task
150
-
151
- To spend some time on the task you have to make the timer run
152
-
153
- slimtimer -s my_shiny_task
154
-
155
- When you finished working on a task, you can call
156
-
157
- slimtimer -e
158
-
159
- This will write the time spend back to SlimTimer.com.
160
- Finally you can run
161
-
162
- slimtimer -t
163
-
164
- To show all your tasks available.
165
- HELP
166
- exit
167
- end
168
- end
169
-
170
- begin
171
- opts.parse!(args)
172
- rescue
173
- puts $!.message
174
- exit
175
- end
176
- options
177
- end
178
- end
179
16
 
180
17
  class CommandLine
181
-
18
+
182
19
  # Include Helper module
183
20
  include Helper
184
-
21
+
185
22
  def initialize(args, output = $stdout)
186
23
  @args = args
187
- @out = output
188
-
24
+ @out = output
25
+
189
26
  deprecated_calls
190
-
27
+
191
28
  @options = parse(args)
192
29
  end
193
-
194
- def create
30
+
31
+ def create
195
32
  st = login
196
- if st.create_task(@options.task_name)
197
- dump_to_file(st.tasks, "tasks.yml")
33
+ if st.create_task(@options.task_name)
34
+ dump_to_file(st.tasks, tasks_file)
198
35
  @out.puts "Task #{name} successfully created."
199
36
  end
200
37
  end
201
-
38
+
202
39
  def tasks(show = true)
203
40
  tasks = load_tasks
204
41
  return tasks unless show
@@ -207,35 +44,38 @@ HELP
207
44
  @out.puts t.name
208
45
  end
209
46
  end
210
-
47
+
211
48
  def setup
212
49
  config = load_config
213
50
 
214
51
  @out.puts "Slimtimer Login Credentials\n"
215
52
  @out.print "E-Mail: "
216
- config["email"] = STDIN.gets.gsub("\n", "")
53
+ config["email"] = $stdin.gets.strip
217
54
 
218
- @out.print "Password: "
219
- config["password"] = STDIN.gets.gsub("\n", "")
55
+ begin
56
+ @out.print "Password: "
57
+ system("stty -echo")
58
+ config["password"] = $stdin.gets.strip
59
+ ensure
60
+ system("stty echo")
61
+ end
220
62
 
221
- @out.print "API Key: "
222
- config["api_key"] = STDIN.gets.gsub("\n", "")
63
+ # Include the newline here so that both prompts are on the same line
64
+ @out.print "\nAPI Key: "
65
+ config["api_key"] = $stdin.gets.strip
223
66
 
224
67
  save_config(config)
225
-
226
- # clear the screen
227
- system("clear")
228
68
  end
229
-
230
- def start
69
+
70
+ def start
231
71
  if File.exists?(current_file)
232
72
  @out.puts "Need to stop the other task first"
233
- return false
73
+ return false
234
74
  end
235
-
75
+
236
76
  info = {"task" => @options.task_name,
237
77
  "start_time" => Time.now}
238
-
78
+
239
79
  #Find task in tasks yml
240
80
  t = load_tasks.find {|t| t.name == info["task"]}
241
81
  unless t
@@ -243,22 +83,20 @@ HELP
243
83
  return false
244
84
  end
245
85
 
246
- dump_to_file(info, "current.yml")
86
+ dump_to_file(info, current_file)
247
87
  return true
248
88
  end
249
-
250
- def stop
251
89
 
90
+ def stop
252
91
  if @options.force
253
- rm_current
92
+ rm_current
254
93
  @out.puts "Forced ending of task, no entry to slimtimer.com written"
255
94
  return true
256
95
  end
257
-
258
-
96
+
259
97
  begin
260
- info = load_file("current.yml")
261
- rescue
98
+ info = load_file(current_file)
99
+ rescue
262
100
  puts "You must start a task before you finish it"
263
101
  return false
264
102
  end
@@ -269,7 +107,6 @@ HELP
269
107
  @out.puts "Task not found in list. Reload List?"
270
108
  return false
271
109
  end
272
- raise unless t
273
110
 
274
111
  st = login
275
112
  result = st.create_time_entry(t, info["start_time"],
@@ -278,36 +115,39 @@ HELP
278
115
  # Delete yml file
279
116
  if result
280
117
  rm_current
281
-
118
+
282
119
  # Output
283
120
  @out.puts "Wrote new Entry for #{t.name}, duration #{result["duration_in_seconds"] / 60}m"
284
121
  return true
285
- else
122
+ else
286
123
  @out.puts "Coult not write new entry, please try again"
287
124
  return false
288
- end
125
+ end
289
126
  end
290
-
127
+
291
128
  def run
292
129
  send(@options.run.to_sym)
293
130
  end
294
-
131
+
295
132
  alias_method :end, :stop
296
-
133
+
297
134
  private
298
-
135
+
299
136
  # This method checks if the first parameter in args needs to
300
137
  # be transformed to the new one
301
138
  def deprecated_calls
302
139
  case @args[0]
303
- when "start": @args[0] = "-s"
304
- when "end": @args[0] = "-e"
305
- when "create_task": @args[0] = "-c"
306
- when "tasks": @args[0] = "-t"
307
- when "setup": @args[0] = "--setup"
140
+ when "start" then @args[0] = "-s"
141
+ when "end" then @args[0] = "-e"
142
+ when "create_task" then @args[0] = "-c"
143
+ when "tasks" then @args[0] = "-t"
144
+ when "setup" then @args[0] = "--setup"
145
+ else
146
+ puts "Unknown command, listing tasks..."
147
+ @args[0] = "-t"
308
148
  end
309
149
  end
310
-
150
+
311
151
  def load_tasks(force = false)
312
152
  config = load_config
313
153
  st = SlimTimer.new(config["email"], config["password"],
@@ -318,11 +158,11 @@ HELP
318
158
  File.mtime(tasks_file) < (Time.now - 60 * 60 *24) || force
319
159
  st.login
320
160
  tasks = st.tasks
321
- dump_to_file(tasks, "tasks.yml")
161
+ dump_to_file(tasks, tasks_file)
322
162
  else
323
- tasks = load_file("tasks.yml")
163
+ tasks = load_file(tasks_file)
324
164
  end
325
165
  tasks
326
166
  end
327
167
  end
328
- end
168
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slimtimercli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Grund
@@ -9,10 +9,39 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-04-07 00:00:00 +02:00
12
+ date: 2010-02-05 00:00:00 +01:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rubyforge
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.0.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: gemcutter
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: hoe
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.5.0
44
+ version:
16
45
  description: Command line interface to SlimTimer
17
46
  email:
18
47
  - grundprinzip@gmail.com
@@ -49,6 +78,8 @@ files:
49
78
  - tasks/website.rake
50
79
  has_rdoc: true
51
80
  homepage: http://blog.grundprinzip.de
81
+ licenses: []
82
+
52
83
  post_install_message:
53
84
  rdoc_options:
54
85
  - --main
@@ -70,9 +101,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
101
  requirements: []
71
102
 
72
103
  rubyforge_project: rug-b
73
- rubygems_version: 1.1.0
104
+ rubygems_version: 1.3.5
74
105
  signing_key:
75
- specification_version: 2
106
+ specification_version: 3
76
107
  summary: Command line interface to SlimTimer
77
108
  test_files: []
78
109