toggl 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/toggl CHANGED
@@ -6,5 +6,8 @@ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
6
6
  require 'toggl'
7
7
  require 'toggl_cmd/runner'
8
8
  require 'toggl_cmd/runner_options'
9
+ require 'hirb'
10
+ require 'hirb/import_object'
9
11
 
12
+ Hirb.enable
10
13
  TogglCmd::Runner.toggl(ARGV)
@@ -73,8 +73,8 @@ class Toggl
73
73
  get 'workspaces'
74
74
  end
75
75
 
76
- def tasks
77
- get 'tasks'
76
+ def tasks(params={})
77
+ get 'tasks', params
78
78
  end
79
79
 
80
80
  def projects
@@ -83,8 +83,8 @@ class Toggl
83
83
 
84
84
  private
85
85
 
86
- def get(resource_name)
87
- self.class.get("/api/v1/#{resource_name}.json", :basic_auth => basic_auth)
86
+ def get(resource_name, data={})
87
+ self.class.get("/api/v1/#{resource_name}.json", :basic_auth => basic_auth, :query => data)
88
88
  end
89
89
 
90
90
  def post(resource_name, data)
@@ -1,19 +1,45 @@
1
1
  require "optparse"
2
+ require "chronic_duration"
2
3
 
3
4
  module TogglCmd
4
5
 
6
+ NAME = "toggl-gem"
7
+ PROJECT_FIELDS = %w(client name)
8
+ TASK_FIELDS = %w(project description start duration billable)
9
+
5
10
  class Runner
6
11
 
7
12
  def self.toggl(args)
13
+ token = IO.readlines(File.expand_path("~/.toggl")).join.strip
8
14
  options = RunnerOptions.new(args)
9
- if options.any?
10
- token = IO.readlines(File.expand_path("~/.toggl")).join
11
- Toggl.new(token, "toggl-gem", options.delete(:debug)).create_task(options)
15
+ if options[:tasks]
16
+ prettify_tasks(Toggl.new(token, NAME).tasks)
17
+ elsif options[:projects]
18
+ prettify_projects(Toggl.new(token, NAME).projects)
19
+ elsif options.any?
20
+ prettify_tasks(Toggl.new(token, NAME, options.delete(:debug)).create_task(options))
12
21
  else
13
22
  puts options.opts
14
23
  end
15
24
  end
16
-
25
+
26
+ private
27
+
28
+ def self.prettify_tasks(values)
29
+ values = [values] unless values.is_a?(Array)
30
+ values.each do |value|
31
+ value["project"] = value["project"]["name"]
32
+ value["workspace"] = value["workspace"]["name"]
33
+ value["duration"] = ChronicDuration.output(value["duration"].to_i, :format => :short)
34
+ value["start"] = DateTime.parse(value["start"]).strftime("%d/%m/%Y")
35
+ end
36
+ values.view(:class => :table, :fields => TASK_FIELDS)
37
+ end
38
+
39
+ def self.prettify_projects(values)
40
+ values.view(:class => :table, :fields => PROJECT_FIELDS)
41
+ end
42
+
17
43
  end
18
-
44
+
19
45
  end
@@ -25,6 +25,14 @@ module TogglCmd
25
25
  self[:start] = date
26
26
  end
27
27
 
28
+ o.on('--tasks', 'Show tasks') do |tasks|
29
+ self[:tasks] = tasks
30
+ end
31
+
32
+ o.on('--projects', 'Show projects') do |projects|
33
+ self[:projects] = projects
34
+ end
35
+
28
36
  o.on('-v', '--verbose', 'What\'s happening?') do |debug|
29
37
  self[:debug] = debug
30
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toggl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koen Van der Auwera
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-25 00:00:00 +01:00
12
+ date: 2010-03-16 00:00:00 +01:00
13
13
  default_executable: toggl
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -32,6 +32,16 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.9.0
34
34
  version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: hirb
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.3.1
44
+ version:
35
45
  description: Toggl provides a simple REST-style JSON API over standard HTTP - http://www.toggl.com
36
46
  email: koen@atog.be
37
47
  executables: