ruboty-toggl_team 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -13
- data/lib/ruboty/toggl_team/actions/toggl_team.rb +22 -25
- data/lib/ruboty/toggl_team/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28a13c43cbbca66f8a5650acb8ae0cf86d51087f0a187d042d082e93f556bc3a
|
4
|
+
data.tar.gz: 79af0f9046069a1881532a21fb7dcb890ba4ae748c06f28d593bad39d96a3203
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2888884c7b69369aaa54a9680d86732afd68a3d2ccf4a733556e931851dec82ea9605ef4b3719bac75e10b2e8d625ae0e823d38eb1b0983fc3791bb97cc6b9bf
|
7
|
+
data.tar.gz: 8fdc080e2554bad3e31a89053f7d9febfb3086fb8965d2d26bfa8ba61674978738b6927d8b0abf64da82b6f42dc791013360965d2089bbdc92aff092c451de29
|
data/README.md
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
# Ruboty::TogglTeam
|
2
2
|
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ruboty/toggl_team`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
|
-
|
7
3
|
## Installation
|
8
4
|
|
9
5
|
Add this line to your application's Gemfile:
|
@@ -12,23 +8,34 @@ Add this line to your application's Gemfile:
|
|
12
8
|
gem 'ruboty-toggl_team'
|
13
9
|
```
|
14
10
|
|
15
|
-
|
11
|
+
## Usage
|
16
12
|
|
17
|
-
|
13
|
+
### Preparation
|
18
14
|
|
19
|
-
|
15
|
+
Set toggl API token. get from [https://toggl.com/app/profile](https://toggl.com/app/profile)
|
20
16
|
|
21
|
-
|
17
|
+
```
|
18
|
+
ruboty toggl set-token <token>
|
19
|
+
```
|
22
20
|
|
23
|
-
|
21
|
+
Set workspace(name).
|
24
22
|
|
25
|
-
|
23
|
+
```
|
24
|
+
ruboty toggl set-workspace <workspace-name>
|
25
|
+
```
|
26
|
+
|
27
|
+
### Start task
|
26
28
|
|
27
|
-
|
29
|
+
```
|
30
|
+
start <task>
|
31
|
+
start <task> <project-name>
|
32
|
+
```
|
28
33
|
|
29
|
-
|
34
|
+
### Stop task
|
30
35
|
|
31
|
-
|
36
|
+
```
|
37
|
+
stop
|
38
|
+
```
|
32
39
|
|
33
40
|
## Contributing
|
34
41
|
|
@@ -6,7 +6,7 @@ module Ruboty
|
|
6
6
|
module Actions
|
7
7
|
class TogglTeam < Ruboty::Actions::Base
|
8
8
|
BRAIN_KEY_TOKENS = 'toggl_team_tokens'.freeze
|
9
|
-
|
9
|
+
BRAIN_KEY_WORKSPACES = 'toggl_team_workspaces'.freeze
|
10
10
|
|
11
11
|
def set_token
|
12
12
|
tokens = brain.data[BRAIN_KEY_TOKENS] || {}
|
@@ -17,7 +17,7 @@ module Ruboty
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def set_workspace
|
20
|
-
unless
|
20
|
+
unless user_token
|
21
21
|
message.reply("please set #{user}'s toggl token!")
|
22
22
|
return
|
23
23
|
end
|
@@ -26,8 +26,10 @@ module Ruboty
|
|
26
26
|
workspace = toggl.my_workspaces.find {|w| w['name'] == name }
|
27
27
|
|
28
28
|
if workspace
|
29
|
-
brain.data[
|
30
|
-
|
29
|
+
workspaces = brain.data[BRAIN_KEY_WORKSPACES] || {}
|
30
|
+
workspaces[user] = workspace
|
31
|
+
brain.data[BRAIN_KEY_WORKSPACES] = workspaces
|
32
|
+
message.reply("set #{name} workspace to #{user}!")
|
31
33
|
else
|
32
34
|
message.reply("#{name} workspace not found!")
|
33
35
|
end
|
@@ -36,19 +38,20 @@ module Ruboty
|
|
36
38
|
end
|
37
39
|
|
38
40
|
def start
|
39
|
-
|
41
|
+
unless user_token && user_workspace
|
40
42
|
message.reply("please set #{user}'s toggl token and workspace!") and return
|
41
43
|
end
|
42
44
|
|
45
|
+
task = message.match_data[:task].strip
|
46
|
+
|
43
47
|
project_name = message.match_data[:project_name].strip
|
44
|
-
project =
|
45
|
-
|
48
|
+
project = toggl.projects(user_workspace['id'], active: true)&.find do |p|
|
49
|
+
p['name'] =~ /#{project_name != '' ? project_name : task}/
|
46
50
|
end
|
47
51
|
|
48
|
-
task = message.match_data[:task].strip
|
49
52
|
entry = toggl.start_time_entry({
|
50
53
|
description: task,
|
51
|
-
wid:
|
54
|
+
wid: user_workspace['id'],
|
52
55
|
pid: project ? project['id'] : nil
|
53
56
|
}.stringify_keys)
|
54
57
|
|
@@ -58,7 +61,7 @@ module Ruboty
|
|
58
61
|
end
|
59
62
|
|
60
63
|
def stop
|
61
|
-
|
64
|
+
unless user_token && user_workspace
|
62
65
|
message.reply("please set #{user}'s toggl token and workspace!") and return
|
63
66
|
end
|
64
67
|
|
@@ -78,28 +81,22 @@ module Ruboty
|
|
78
81
|
message.robot.brain
|
79
82
|
end
|
80
83
|
|
81
|
-
def
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
def workspace_id
|
86
|
-
if w = brain.data[BRAIN_KEY_WORKSPACE]
|
87
|
-
w['id']
|
88
|
-
else
|
89
|
-
nil
|
90
|
-
end
|
84
|
+
def user
|
85
|
+
message.from_name || 'test'
|
91
86
|
end
|
92
87
|
|
93
|
-
def
|
94
|
-
brain.data[BRAIN_KEY_TOKENS] || {}
|
88
|
+
def user_token
|
89
|
+
user_tokens = brain.data[BRAIN_KEY_TOKENS] || {}
|
90
|
+
user_tokens[user]
|
95
91
|
end
|
96
92
|
|
97
|
-
def
|
98
|
-
|
93
|
+
def user_workspace
|
94
|
+
user_workspaces = brain.data[BRAIN_KEY_WORKSPACES] || {}
|
95
|
+
user_workspaces[user]
|
99
96
|
end
|
100
97
|
|
101
98
|
def toggl
|
102
|
-
TogglV8::API.new(
|
99
|
+
TogglV8::API.new(user_token)
|
103
100
|
end
|
104
101
|
end
|
105
102
|
end
|