ruboty-toggl 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3b4fe19c8c3bbef4f2a60fd9ac8f9828a1ed6006
4
+ data.tar.gz: 92809784ebf386641551ea2dae399bb5c3a055d4
5
+ SHA512:
6
+ metadata.gz: d6f08e9b3937753c0324716716449eb8e0c2da95a42407cdf0bf2e50cc9bf988a90e73b2ad78b2c31966eee2440e71bdb0dd00ad8da237c9ab0e24d06720929b
7
+ data.tar.gz: 0089eb20861d8232b464163e3459342b5a749573922018821c5538fb80f3cda10ffddfcbbe2f5a1e5cb846b1dca47dd51bbf173289f2b339280322fae3544cc8
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
@@ -0,0 +1,2 @@
1
+ ## 0.0.1
2
+ - 1st Release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-toggl.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,23 @@
1
+ # Ruboty::Toggl
2
+ Manage Toggl via Ruboty.
3
+
4
+ ## Install
5
+ ```ruby
6
+ # Gemfile
7
+ gem "ruboty-toggl"
8
+ ```
9
+
10
+ ## Usage
11
+ ```
12
+ @ruboty token <token> - Remember sender's Toggl access token.
13
+ @ruboty workspace <workspace> - Remember sender's Workspace.
14
+ @ruboty start <description> <project_name> - stop current toggl, and start new toggl.
15
+ @ruboty stop - stop current toggl.
16
+ ```
17
+
18
+ ## ENV
19
+ ```
20
+ NONE
21
+ ```
22
+
23
+ ## Image
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,55 @@
1
+ module Ruboty
2
+ module Handlers
3
+ class Toggl < Base
4
+
5
+ on(
6
+ /token (?<token>.+)\z/,
7
+ name: "token",
8
+ description: "Remember sender's Toggl access token",
9
+ )
10
+ on(
11
+ /workspace (?<workspace_id>.+)\z/,
12
+ name: "workspace",
13
+ description: "Remember sender's Toggle Workspace",
14
+ )
15
+
16
+ on(
17
+ /workspaces\z/,
18
+ name: "workspaces",
19
+ description: "Show user's Workspaces",
20
+ )
21
+
22
+ on(
23
+ /start (?<description>.+) (?<project>.+)\z/,
24
+ name: "start",
25
+ description: "start toggl",
26
+ )
27
+
28
+ on(
29
+ /stop\z/,
30
+ name: "stop",
31
+ description: "stop current toggl",
32
+ )
33
+
34
+ def token(message)
35
+ Ruboty::Toggl::Actions::Token.new(message).call
36
+ end
37
+
38
+ def workspace(message)
39
+ Ruboty::Toggl::Actions::Workspace.new(message).call
40
+ end
41
+
42
+ def workspaces(message)
43
+ Ruboty::Toggl::Actions::Workspaces.new(message).call
44
+ end
45
+
46
+ def start(message)
47
+ Ruboty::Toggl::Actions::Start.new(message).call
48
+ end
49
+
50
+ def stop(message)
51
+ Ruboty::Toggl::Actions::Stop.new(message).call
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,9 @@
1
+ require 'ruboty'
2
+ require 'togglv8'
3
+ require 'ruboty/handlers/toggl'
4
+ require 'ruboty/toggl/actions/base'
5
+ require 'ruboty/toggl/actions/token'
6
+ require 'ruboty/toggl/actions/start'
7
+ require 'ruboty/toggl/actions/stop'
8
+ require 'ruboty/toggl/actions/workspace'
9
+ require 'ruboty/toggl/actions/workspaces'
@@ -0,0 +1,80 @@
1
+ module Ruboty
2
+ module Toggl
3
+ module Actions
4
+ class Base
5
+ NAMESPACE = "toggl."
6
+ TOKEN = "access_token"
7
+ WORKSPACE = "workspace"
8
+
9
+ attr_reader :message
10
+
11
+ def initialize(message)
12
+ @message = message
13
+ end
14
+
15
+ private
16
+
17
+ def access_tokens
18
+ message.robot.brain.data[NAMESPACE + TOKEN] ||= {}
19
+ end
20
+
21
+ def body
22
+ message[:description] || ""
23
+ end
24
+
25
+ def sender_name
26
+ message.from_name
27
+ end
28
+
29
+ def require_access_token
30
+ message.reply("I don't know your toggl access token")
31
+ end
32
+
33
+ def access_token?
34
+ !access_token.nil?
35
+ end
36
+
37
+ def access_token
38
+ @access_token ||= access_tokens[sender_name]
39
+ end
40
+
41
+ def workspaces
42
+ message.robot.brain.data[NAMESPACE + WORKSPACE] ||= {}
43
+ end
44
+
45
+ def require_workspace
46
+ message.reply("I don't know your default workspace.your can get your workspace list by `workspaces`")
47
+ end
48
+
49
+ def workspace?
50
+ !workspace.nil?
51
+ end
52
+
53
+ def workspace
54
+ @workspace ||= workspaces[sender_name]
55
+ end
56
+
57
+ def project
58
+ @project ||= projects.find{|h| h['name'].start_with? message[:project]}
59
+ end
60
+
61
+ def projects
62
+ toggl.projects(workspace)
63
+ end
64
+
65
+ def toggl
66
+ @toggl ||= TogglV8::API.new(access_token)
67
+ end
68
+
69
+ def current_time_entry
70
+ @current_time_entry ||= toggl.get_current_time_entry
71
+ end
72
+
73
+ def reply_my_workspaces
74
+ message.reply("Select your main workspace.\n #{toggl.my_workspaces.map { |h| "`workspace #{h['id']}` #{h['name']}" }.join("\n")} ")
75
+ end
76
+
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,40 @@
1
+ module Ruboty
2
+ module Toggl
3
+ module Actions
4
+ class Start < Base
5
+ def call
6
+ if access_token?
7
+ unless workspace?
8
+ return require_workspace
9
+ end
10
+ start
11
+ else
12
+ require_access_token
13
+ end
14
+ rescue => exception
15
+ message.reply("Failed by #{exception.class}")
16
+ end
17
+
18
+ private
19
+
20
+ def start
21
+ unless project
22
+ return message.reply("project #{message[:project]} not found.")
23
+ end
24
+ message.reply("Start `#{time_entity['description']}` in project `#{project['name']}` !")
25
+ end
26
+
27
+ def time_entity
28
+ params= {
29
+ 'billable' => false,
30
+ 'description' => message[:description],
31
+ 'pid' => project['id'],
32
+ 'wid' => workspace,
33
+ }
34
+ toggl.start_time_entry(params)
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,33 @@
1
+ module Ruboty
2
+ module Toggl
3
+ module Actions
4
+ class Stop < Base
5
+ def call
6
+ if access_token?
7
+ unless workspace?
8
+ return require_workspace
9
+ end
10
+ stop
11
+ report
12
+ else
13
+ require_access_token
14
+ end
15
+ rescue => exception
16
+ message.reply("Failed by #{exception.class}")
17
+ end
18
+
19
+ private
20
+
21
+ def stop
22
+ toggl.stop_time_entry current_time_entry["id"]
23
+ end
24
+
25
+ def report
26
+ project = toggl.get_project(current_time_entry['pid'])
27
+ message.reply("Stop `#{current_time_entry['description']}` in project `#{project['name']}` !")
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,34 @@
1
+ module Ruboty
2
+ module Toggl
3
+ module Actions
4
+ class Token < Base
5
+ def call
6
+ token
7
+ rescue => exception
8
+ message.reply("Failed by #{exception.class}")
9
+ end
10
+
11
+ private
12
+
13
+ def token
14
+ unless valid_access_token
15
+ return message.reply("invalid access token. https://toggl.com/app/profile")
16
+ end
17
+ access_tokens[sender_name] = given_access_token
18
+ message.reply("Remembered #{sender_name}'s toggl access token")
19
+ reply_my_workspaces
20
+ end
21
+
22
+ def given_access_token
23
+ message[:token]
24
+ end
25
+
26
+ def valid_access_token
27
+ return TogglV8::API.new(given_access_token).workspaces
28
+ rescue => _
29
+ return false
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,37 @@
1
+ module Ruboty
2
+ module Toggl
3
+ module Actions
4
+ class Workspace < Base
5
+ def call
6
+ if access_token?
7
+ set_workspace
8
+ else
9
+ require_access_token
10
+ end
11
+ rescue => exception
12
+ message.reply("Failed by #{exception.class}")
13
+ end
14
+
15
+ private
16
+ def set_workspace
17
+ unless valid_workspace
18
+ message.reply("Invalid workspace id #{given_workspace}")
19
+ return reply_my_workspaces
20
+ end
21
+ workspaces[sender_name] = given_workspace
22
+ message.reply("Remembered #{sender_name}'s workspace")
23
+ end
24
+
25
+ def given_workspace
26
+ message[:workspace_id]
27
+ end
28
+
29
+ def valid_workspace
30
+ return toggl.projects given_workspace
31
+ rescue => _
32
+ return false
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,19 @@
1
+ module Ruboty
2
+ module Toggl
3
+ module Actions
4
+ class Workspaces < Base
5
+ def call
6
+ if access_token?
7
+ reply_my_workspaces
8
+ else
9
+ require_access_token
10
+ end
11
+ rescue => exception
12
+ message.reply("Failed by #{exception.class}")
13
+ end
14
+
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Toggl
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'ruboty/toggl/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ruboty-toggl"
7
+ spec.version = Ruboty::Toggl::VERSION
8
+ spec.authors = ["hayato iida"]
9
+ spec.email = [""]
10
+ spec.summary = "Manage Toggl via Ruboty."
11
+ spec.homepage = "https://github.com/iida-hayato/ruboty-toggl"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "ruboty"
20
+ spec.add_dependency "togglv8"
21
+ spec.add_dependency "awesome_print"
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec", "2.14.1"
25
+ spec.add_development_dependency "simplecov"
26
+ spec.add_development_dependency "webmock"
27
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-toggl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - hayato iida
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruboty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: togglv8
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: awesome_print
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 2.14.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 2.14.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description:
126
+ email:
127
+ - ''
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - CHANGELOG.md
134
+ - Gemfile
135
+ - LICENSE
136
+ - README.md
137
+ - Rakefile
138
+ - lib/ruboty/handlers/toggl.rb
139
+ - lib/ruboty/toggl.rb
140
+ - lib/ruboty/toggl/actions/base.rb
141
+ - lib/ruboty/toggl/actions/start.rb
142
+ - lib/ruboty/toggl/actions/stop.rb
143
+ - lib/ruboty/toggl/actions/token.rb
144
+ - lib/ruboty/toggl/actions/workspace.rb
145
+ - lib/ruboty/toggl/actions/workspaces.rb
146
+ - lib/ruboty/toggl/version.rb
147
+ - ruboty-toggl.gemspec
148
+ homepage: https://github.com/iida-hayato/ruboty-toggl
149
+ licenses:
150
+ - MIT
151
+ metadata: {}
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 2.4.7
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: Manage Toggl via Ruboty.
172
+ test_files: []