toggl_cli 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/toggl_cli +16 -5
  3. data/lib/toggl_cli.rb +63 -8
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f921feb5c6cf10b6b9e5916f9fec61a94c1ee2dd3126872e8fb8fbb4e8591566
4
- data.tar.gz: 9a0361b9820ea32fd3db5d25f4a175f0ee71cf3ee1927a57b9eeaad18449ca78
3
+ metadata.gz: 3fc24cda91244babd028aad50e489902d8439d09ff28732c9b30542400cb8874
4
+ data.tar.gz: d954b78521ee467b2306ee3398352aaa897fb98d7d91625cae7802f5b7a94841
5
5
  SHA512:
6
- metadata.gz: 654c6d0f915f714224df133fd12ab07f745d2f3e7acf9b50d94909dcd916b87064725ddb4e1cacfa6daf4cbc83a39055a1030c1fcabab3cd40af9cc88866ce10
7
- data.tar.gz: 4e103afcfc01b80d75931ab4e5defc2620e037b0bc092536374c4efe7f04d7fe5fd07c1255f70a53cd0ea2ab76c801c126a1b81053c8ac455d7a26d332ed9b57
6
+ metadata.gz: f0bb0404cdfc0cc5124da5712bc51a693469ca8cb40b899de8b58cf55276e7f43171599cce565d33e141d3ba0ae1f27e4a00875505c3076cc05592984dbc88df
7
+ data.tar.gz: 1e608760d907149ea455ce3d5440bf095e1480e5336788f20136c136df5b88c4fc10057ff5a46a1a07a6e5cf6641d85e0b496b90417b31da9748674737a0e469
@@ -12,17 +12,28 @@ end
12
12
 
13
13
  case command
14
14
  when 'start'
15
- project = ARGV[1]
16
- description = ARGV[2]
17
- @toggl_cli.start(project, description)
15
+ client = ARGV[1]
16
+ project = ARGV[2]
17
+ description = ARGV[3]
18
+ @toggl_cli.start(client, project, description)
18
19
  puts "Timer Started"
19
20
  when 'stop'
20
21
  result = @toggl_cli.stop
21
22
  duration = (result['duration'].to_i / 60.0).round(2)
22
23
  puts "Timer Stopped. Duration: #{duration} minutes."
23
24
  when 'today'
24
- result = @toggl_cli.today
25
- puts "You have logged #{result} minutes or #{(result/60.0).round(2)} hours today"
25
+ client = ARGV[1]
26
+ result = @toggl_cli.today(client)
27
+ puts result[:entries]
28
+ puts "You have logged #{result[:total]} minutes or #{(result[:total]/60.0).round(2)} hours today"
29
+ when 'clients'
30
+ result = @toggl_cli.clients
31
+ puts result
32
+ when 'projects'
33
+ result = @toggl_cli.projects
34
+ result.each do |r|
35
+ puts "#{r['id']} #{r['cid']} #{r['name']}"
36
+ end
26
37
  else
27
38
  puts "Uh-oh! I haven't learned that command yet"
28
39
  end
@@ -12,11 +12,10 @@ class TogglCLI
12
12
  @workspace_id = @workspaces.first['id']
13
13
  end
14
14
 
15
- def start(project, description)
16
- pid = ""
17
- if @config['projects'][project]
18
- pid = @config['projects'][project]
19
- end
15
+ def start(client, project, description)
16
+ cid = client(client)['id']
17
+ pid = project(cid, project)['id']
18
+
20
19
  time_entry = @toggl_api.start_time_entry({
21
20
  'pid' => pid,
22
21
  'description' => "#{description}",
@@ -33,7 +32,18 @@ class TogglCLI
33
32
  end
34
33
  end
35
34
 
36
- def today
35
+ def today(client = nil, project = nil)
36
+ pids = []
37
+ if client
38
+ cid = client(client)['id']
39
+ presult = projects
40
+ presult.each do |r|
41
+ if r['cid'] == cid
42
+ pids << r['id']
43
+ end
44
+ end
45
+ end
46
+ entries = []
37
47
  dates = {
38
48
  start_date: Time.parse(Date.today.to_s).to_s,
39
49
  end_date: Time.now.to_s
@@ -41,8 +51,53 @@ class TogglCLI
41
51
  total = 0
42
52
  result = @toggl_api.get_time_entries(dates)
43
53
  result.each do |r|
44
- total = total + r['duration']
54
+ if (client && (pids.include? r['pid']))
55
+ entries << "#{r['duration']} - #{r['description']}"
56
+ total = total + r['duration']
57
+ end
58
+ end
59
+ {entries: entries, total: (total / 60.0).round(2)}
60
+ end
61
+
62
+ def clients
63
+ clients = []
64
+ result = @toggl_api.my_clients
65
+ result.each do |r|
66
+ clients << "#{r['id']} #{r['name']}"
67
+ end
68
+ clients
69
+ end
70
+
71
+ def client(name)
72
+ client = ""
73
+ result = @toggl_api.my_clients
74
+ result.each do |r|
75
+ if r['name'].downcase == name
76
+ client = r
77
+ end
78
+ end
79
+ client
80
+ end
81
+
82
+ def projects(client_id = nil)
83
+ projects = []
84
+ result = @toggl_api.my_projects
85
+ result.each do |r|
86
+ if r['cid']
87
+ projects << r
88
+ end
89
+ end
90
+ projects
91
+ end
92
+
93
+ def project(client_id, name)
94
+ project = ""
95
+ result = @toggl_api.my_projects
96
+ result.each do |r|
97
+ if r['cid'] == client_id && r['name'].downcase == name
98
+ project = r
99
+ end
45
100
  end
46
- (total / 60.0).round(2)
101
+ project
47
102
  end
48
103
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toggl_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Erickson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-14 00:00:00.000000000 Z
11
+ date: 2019-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: togglv8
@@ -52,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  requirements: []
55
- rubygems_version: 3.0.1
55
+ rubygems_version: 3.0.3
56
56
  signing_key:
57
57
  specification_version: 4
58
58
  summary: A simple command line tool for toggl