simple_slack 0.2.6 → 0.3.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
  SHA1:
3
- metadata.gz: ce3b8f3eb317bfeb9a76992379ed8b1f76a3d744
4
- data.tar.gz: 28a3b0188ba80a3558464ff196311017f7789fa9
3
+ metadata.gz: 4f4bea98a9191153158ba48bea0d519bd418c039
4
+ data.tar.gz: 39d77eaf78dcda76c5dea8691d6d6100c4e6a37a
5
5
  SHA512:
6
- metadata.gz: cf83868cb60a91e183058da8add0743aa948e0a002ee6dcc07fc71f688c12fb5ebd696bd2cc43be5bcb2e04137b1c71ed93664ce03f15781cfdc3b67169746bc
7
- data.tar.gz: 0f39c119c8e1d9c23d84efdf3ca35ff184721436f448ae3d0e0ecbabe964b36d4054266dc76b802e38597191057c8e8fe4e9a086ff54f15150d62848caa9c22e
6
+ metadata.gz: f4921a67a6391220b7ebd244ed331dcf8e472085543f6a1a361e297856a001d09603f24056b2e4b9e940d2cb5a5add9b56d8f960d1bdd2a29482fdd48dae0c65
7
+ data.tar.gz: 9cf503c52509e2e2e953da9da1a79fb90574e1592c5e11d1352e696f7cd53c1d8957ea337ba5706ac745ee276d9081e0775475f1d112cf78107b04d2bce99790
@@ -2,6 +2,7 @@ require 'slack'
2
2
  require 'simple_slack/getter'
3
3
  require 'simple_slack/poster'
4
4
  require 'simple_slack/botter'
5
+ require 'simple_slack/toggl'
5
6
 
6
7
  class SimpleSlack::Client
7
8
  def initialize(token)
@@ -21,4 +22,8 @@ class SimpleSlack::Client
21
22
  def bot
22
23
  @botter ||= SimpleSlack::Botter.new(@token, self)
23
24
  end
25
+
26
+ def toggl(toggl_api_token = ENV['TOGGL_API_TOKEN'])
27
+ @toggl ||= SimpleSlack::Toggl.new(toggl_api_token, self)
28
+ end
24
29
  end
@@ -4,6 +4,13 @@ class SimpleSlack::Poster
4
4
  @simple_slack = simple_slack
5
5
  end
6
6
 
7
+ def channels(to: , text: , name: "slacker", **options)
8
+ to.all? do |t|
9
+ id = convert_channel_to_id(t.to_s)
10
+ send_chat({ username: name, channel: id, text: text }.merge(options))
11
+ end
12
+ end
13
+
7
14
  def channel(to: , text: , name: "slacker", **options)
8
15
  id = convert_channel_to_id(to.to_s)
9
16
  send_chat({ username: name, channel: id, text: text }.merge(options))
@@ -21,9 +28,16 @@ class SimpleSlack::Poster
21
28
  end
22
29
  end
23
30
 
24
- def im(to: , text: , name: "slacker")
31
+ def ims(to: , text: , name: "slacker", **options)
32
+ to.all? do |t|
33
+ id = convert_im_to_id(t.to_s)
34
+ send_chat({ username: name, channel: id, text: text }.merge(options))
35
+ end
36
+ end
37
+
38
+ def im(to: , text: , name: "slacker", **options)
25
39
  id = convert_im_to_id(to.to_s)
26
- send_chat(username: name, channel: id, text: text)
40
+ send_chat({ username: name, channel: id, text: text }.merge(options))
27
41
  end
28
42
 
29
43
  private
@@ -0,0 +1,54 @@
1
+ require 'togglv8'
2
+ require "simple_slack/toggls/toggl_parameter"
3
+ require "simple_slack/toggls/toggl_dailyreport"
4
+ require "simple_slack/toggls/toggl_dailyreport"
5
+ class SimpleSlack::Toggl
6
+ include TogglParameter
7
+ include TogglDailyreport
8
+
9
+ attr_accessor :toggl_client, :simple_client, :post_channels, :post_bot_name, :post_bot_image, :post_ims
10
+
11
+ URL = "https://toggl.com/"
12
+ TIMER_URL = "#{URL}app/timer"
13
+
14
+ def initialize(toggl_api_token, simple_slack_client)
15
+ @toggl_client = TogglV8::API.new(toggl_api_token)
16
+ @simple_client = simple_slack_client
17
+ @post_bot_name = "slacker"
18
+ @post_bot_image = ":joy:"
19
+ end
20
+
21
+ def configure
22
+ yield self
23
+ end
24
+
25
+ def post_message(type = :regular)
26
+ case type.to_s
27
+ when "morning"
28
+ post_message_by(send_morning_message)
29
+ when "regular"
30
+ post_message_by(send_regular_message)
31
+ when "noon"
32
+ post_message_by(send_noon_message)
33
+ when "after_noon"
34
+ post_message_by(send_after_noon_message)
35
+ when "night"
36
+ post_message_by(send_night_message)
37
+ when "dailyreport"
38
+ post_message_by(send_dailyreport_message)
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def post_message_by(text)
45
+ if post_channels.empty? && post_ims.empty?
46
+ raise "メッセージの送り先チャンネル、IMが指定されていません"
47
+ end
48
+ simple_client.post.channels(to: post_channels, text: text, name: post_bot_name, icon_emoji: post_bot_image) unless post_channels.empty?
49
+ simple_client.post.ims(to: post_ims, text: text, name: post_bot_name, icon_emoji: post_bot_image) unless post_ims.empty?
50
+ text
51
+ end
52
+
53
+ end
54
+
@@ -0,0 +1,15 @@
1
+ module TogglDailyreport
2
+ def dailyreport
3
+ today_entry_reports
4
+ end
5
+
6
+ def today_entry_reports
7
+ reports = []
8
+ day_entries.each do |entry|
9
+ reports << entry_info(entry)
10
+ end
11
+
12
+ reports.join("\n")
13
+ end
14
+
15
+ end
@@ -0,0 +1,45 @@
1
+ module TogglEntriesParameter
2
+
3
+ def entries
4
+ @entries ||= toggl_client.my_time_entries
5
+ end
6
+
7
+ def day_entries(day = Time.now.to_date)
8
+ entries.select do |entry|
9
+ start_date = Time.parse(entry["start"]).getlocal("+09:00").to_date
10
+ start_date == day
11
+ end
12
+ end
13
+
14
+ def latest_entry
15
+ entries.sort_by{ |entry| entry["start"] }.last
16
+ end
17
+
18
+ def working_entry
19
+ if latest_entry["stop"].nil?
20
+ latest_entry
21
+ end
22
+ end
23
+
24
+ def entry_info(entry = latest_entry)
25
+ # 現在作業中(終了時間がない)であれば現在日時を終了時間として取得
26
+ stop_time_org = entry["stop"].nil? ? Time.now : Time.parse(entry["stop"])
27
+
28
+ start_time = Time.parse(entry["start"]).getlocal("+09:00")
29
+ stop_time = stop_time_org.getlocal("+09:00")
30
+ diff_time = (stop_time - start_time)/3600
31
+
32
+ # 0.1h 以下の表示になるようであれば 分表示に変更する
33
+ if diff_time >= 0.1
34
+ work_time = "#{diff_time.round(2)}h"
35
+ else
36
+ work_time = "#{(diff_time * 60).round(2)}m"
37
+ end
38
+
39
+ tag = entry["tags"].join(" ") unless entry["tags"].nil?
40
+ description = entry["description"]
41
+
42
+ "#{tag} #{description} \(#{work_time}\)"
43
+ end
44
+
45
+ end
@@ -0,0 +1,52 @@
1
+ require_relative 'toggl_entries_parameter'
2
+ require_relative 'toggl_send_parameter'
3
+ module TogglParameter
4
+ include TogglEntriesParameter
5
+ include TogglSendParameter
6
+
7
+ def user
8
+ @user ||= toggl_client.me
9
+ end
10
+
11
+ def workspaces
12
+ @workspaces ||= toggl_client.my_workspaces(user)
13
+ end
14
+
15
+ def workspace(id: nil, name: nil)
16
+ if id
17
+ workspaces.find{ |work| work["id"] == id }
18
+ elsif name
19
+ workspaces.find{ |work| work["name"] == name }
20
+ else
21
+ workspaces.first
22
+ end
23
+ end
24
+
25
+ def projects
26
+ @projects ||= toggl_client.my_projects
27
+ end
28
+
29
+ def project(id: nil, name: nil)
30
+ if id
31
+ projects.find{ |project| project["id"] == id }
32
+ elsif name
33
+ projects.find{ |project| project["name"] == name }
34
+ else
35
+ projects.first
36
+ end
37
+ end
38
+
39
+ def tags
40
+ @tags ||= toggl_client.my_tags
41
+ end
42
+
43
+ def tag(id: nil, name: nil)
44
+ if id
45
+ tags.find{ |tag| tag["id"] == id }
46
+ elsif name
47
+ tags.find{ |tag| tag["name"] == name }
48
+ else
49
+ tags.first
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,47 @@
1
+ module TogglSendParameter
2
+ def send_morning_message
3
+ message = "おはようございます。"
4
+
5
+ send_message_select(message)
6
+ end
7
+
8
+ def send_regular_message(current_time = Time.now)
9
+ current_time_s = current_time.strftime("%Y年%m月%d日: %H時")
10
+ message = "#{current_time_s}です。"
11
+
12
+ send_message_select(message)
13
+ end
14
+
15
+ def send_noon_message
16
+ if working_entry
17
+ "お昼です。休憩をするなら作業内容を止めてください。\n■現在作業中の内容。\n#{entry_info(working_entry)}"
18
+ end
19
+ end
20
+
21
+ def send_after_noon_message
22
+ message = "お昼休み終了です。"
23
+ send_message_select(message)
24
+ end
25
+
26
+ def send_night_message
27
+ if working_entry
28
+ message = "業務終了の時間です。残業がないなら作業内容を止めてください。\n■現在作業中の内容。\n#{entry_info(working_entry)}"
29
+ "#{message}\n\nもし残業があるなら終了のリマインドを設定してください。\n\n```\n/remind me in 終了時間 to toggle stop\n```"
30
+ end
31
+ end
32
+
33
+ def send_dailyreport_message(date = Date.today)
34
+ date_s = date.strftime("%Y年%m月%d日")
35
+ "#{date_s}の日報です\n\n#{dailyreport}"
36
+ end
37
+
38
+ private
39
+
40
+ def send_message_select(message)
41
+ if working_entry
42
+ "#{message}\n■現在作業中の内容。\n#{entry_info(working_entry)}"
43
+ else
44
+ "#{message}\n■現在作業中の内容はありません。下記より設定してください。\n#{SimpleSlack::Toggl::TIMER_URL}"
45
+ end
46
+ end
47
+ end
@@ -1,3 +1,3 @@
1
1
  module SimpleSlack
2
- VERSION = "0.2.6"
2
+ VERSION = "0.3.0"
3
3
  end
data/simple_slack.gemspec CHANGED
@@ -32,4 +32,6 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency "rspec"
33
33
 
34
34
  spec.add_dependency "slack-api", '~>1.2.1'
35
+ spec.add_dependency "togglv8"
36
+ spec.add_dependency "awesome_print"
35
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_slack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - toririn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-17 00:00:00.000000000 Z
11
+ date: 2016-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 1.2.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: togglv8
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
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: awesome_print
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  description: simple use slack
70
98
  email:
71
99
  - toririn.paftako@gmail.com
@@ -88,6 +116,11 @@ files:
88
116
  - lib/simple_slack/client.rb
89
117
  - lib/simple_slack/getter.rb
90
118
  - lib/simple_slack/poster.rb
119
+ - lib/simple_slack/toggl.rb
120
+ - lib/simple_slack/toggls/toggl_dailyreport.rb
121
+ - lib/simple_slack/toggls/toggl_entries_parameter.rb
122
+ - lib/simple_slack/toggls/toggl_parameter.rb
123
+ - lib/simple_slack/toggls/toggl_send_parameter.rb
91
124
  - lib/simple_slack/version.rb
92
125
  - simple_slack.gemspec
93
126
  homepage: ''
@@ -116,4 +149,3 @@ signing_key:
116
149
  specification_version: 4
117
150
  summary: simple use slack
118
151
  test_files: []
119
- has_rdoc: