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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8829636e4e97a908203cec1ada5336025adfd2fba39139b8289592774502808
4
- data.tar.gz: b60080a39bc0f109510fe5beaa6be182fbab891208e5d07c27369170cb09a6ca
3
+ metadata.gz: 28a13c43cbbca66f8a5650acb8ae0cf86d51087f0a187d042d082e93f556bc3a
4
+ data.tar.gz: 79af0f9046069a1881532a21fb7dcb890ba4ae748c06f28d593bad39d96a3203
5
5
  SHA512:
6
- metadata.gz: 493b6ac3419316f9ddcf4e1c1a26bd8e9d39a5034c06e3df0c78972ac46f7f40727bdf86eea03d89c607869c3848f5da5f5006579cac0d1963de971890dd804d
7
- data.tar.gz: 6d30f4868de4d547b55b134faa3dfdfddf7d70650183f1c27d53fc7d05d2200ad1b4f945735a1330fca78a24be9ae3e29128863ba77aa6e64d5ba19040e57556
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
- And then execute:
11
+ ## Usage
16
12
 
17
- $ bundle
13
+ ### Preparation
18
14
 
19
- Or install it yourself as:
15
+ Set toggl API token. get from [https://toggl.com/app/profile](https://toggl.com/app/profile)
20
16
 
21
- $ gem install ruboty-toggl_team
17
+ ```
18
+ ruboty toggl set-token <token>
19
+ ```
22
20
 
23
- ## Usage
21
+ Set workspace(name).
24
22
 
25
- TODO: Write usage instructions here
23
+ ```
24
+ ruboty toggl set-workspace <workspace-name>
25
+ ```
26
+
27
+ ### Start task
26
28
 
27
- ## Development
29
+ ```
30
+ start <task>
31
+ start <task> <project-name>
32
+ ```
28
33
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
34
+ ### Stop task
30
35
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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
- BRAIN_KEY_WORKSPACE = 'toggl_team_workspace'.freeze
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 user_tokens.key?(user)
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[BRAIN_KEY_WORKSPACE] = workspace
30
- message.reply("set #{name} workspace!")
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
- if !user_tokens.key?(user) || !workspace_id
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 = if project_name != ''
45
- toggl.projects(workspace_id, active: true)&.find {|p| p['name'] =~ /#{project_name}/ }
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: workspace_id,
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
- if !user_tokens.key?(user) || !workspace_id
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 user_tokens
82
- brain.data[BRAIN_KEY_TOKENS] || {}
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 user_current_tasks
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 user
98
- message.from_name || 'test'
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(user_tokens[user])
99
+ TogglV8::API.new(user_token)
103
100
  end
104
101
  end
105
102
  end
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module TogglTeam
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-toggl_team
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kimromi