chatwork_to 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc5c7fed07fc8b7456643d0a9627017e0ba88424
4
- data.tar.gz: 1f9d67ac01e38dd2352d09c0d2e80dcce5bd806a
3
+ metadata.gz: acd4773bb642d988f03c7bc6d7b3db3ead1fae65
4
+ data.tar.gz: a6324f34b0e64c2442d91902c0ddb5248d2084a3
5
5
  SHA512:
6
- metadata.gz: 98ded13c0aae6cd101b8adaf5dc14a1ad089d9759bc5798217875a9a87f3e0343df8af0ffcdcfa429c3a6afcdb1928aeffd74718573f0680e1b9547abd72367d
7
- data.tar.gz: 2955771706ac358b08c3dfff0252cdedab73eb1f3d1b93749d3f81fb9100f77d41447d4cd416aa8be97711196e1fbb2070b918bee9e8f2bc1b3339e426678f60
6
+ metadata.gz: 144ff3a20f6fb615b87556d20c3fb02fd0a8ab2b0e14b5d8bd03be62610980a69000b4d881a518489c85047befbbdccf55de8a418cd07b8449cd46b9fffea414
7
+ data.tar.gz: 69fd0940f2b69bce6092f4762f94f9c1961482ecf8393096e0007ce12ae36805031c18295bf235fcfd194d2935e51a7291ced72c574646da09a2469aa9f9ecaf
data/lib/chatwork_to.rb CHANGED
@@ -6,6 +6,7 @@ require 'mechanize'
6
6
  require 'chatwork_to/version'
7
7
  require 'chatwork_to/config'
8
8
  require 'chatwork_to/client'
9
+ require 'chatwork_to/message_decorator'
9
10
  require 'chatwork_to/notifier'
10
11
  require 'chatwork_to/response'
11
12
  require 'chatwork_to/process'
@@ -0,0 +1,31 @@
1
+ module ChatworkTo
2
+ module MessageDecorator
3
+ refine String do
4
+ def gsub_quote!
5
+ gsub!(/\[qt\]\[qtmeta.*\](.+)\[\/qt\]/) { "> #{$1.gsub(/\n/, '\n> ')}" } || self
6
+ end
7
+
8
+ def gsub_reply!
9
+ gsub!(/\[rp aid=(.+) to=.+\]/) { "[Re:#{$1}]" } || self
10
+ end
11
+
12
+ def gsub_task_added!
13
+ gsub!(/\[info\]\[title\]\[dtext:task_added\].+\[\/info\]/, 'Added task') || self
14
+ end
15
+
16
+ def gsub_task_done!
17
+ gsub!(/\[info\]\[title\]\[dtext:task_done\].+\[\/info\]/, 'Done task') || self
18
+ end
19
+
20
+ def gsub_file_uploaded!
21
+ gsub!(/\[info\].*\[download:(.+)\](.+)\[\/download\]\[\/info\]/) do
22
+ "#{$2}\nhttps://www.chatwork.com/gateway.php?cmd=download_file&bin=1&file_id=#{$1}"
23
+ end || self
24
+ end
25
+
26
+ def room_url
27
+ "https://www.chatwork.com/#!rid#{self}"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,6 +1,8 @@
1
1
  module ChatworkTo
2
2
  module Notifiers
3
3
  class Slack
4
+ using ChatworkTo::MessageDecorator
5
+
4
6
  def initialize(opts = {})
5
7
  @debug = !!opts.delete('debug')
6
8
  build_uri
@@ -30,16 +32,15 @@ module ChatworkTo
30
32
  def request_body(chat, room, users)
31
33
  fid = chat['aid'].to_s
32
34
  fname = users[fid]['name']
33
- rid = room['id']
35
+ rid = room['id'].to_s
34
36
  rname = room['name'].presence || fname
35
37
  msg = chat['msg']
36
- text = "Message from #{fname} (id:#{fid})"
37
- attachment = {}
38
+ text = "*Message from '#{fname}' (id:#{fid}) in '#{rname}' (rid:#{rid})*"
39
+ attachment = { color: '#D00000' }
38
40
  attachment[:fields] = [
39
41
  {
40
42
  fallback: 'chatwork message',
41
- title: "#{rname} (rid:#{rid})",
42
- value: decorate(msg),
43
+ value: decorate(msg).concat("\n\n#{rid.room_url}"),
43
44
  short: false,
44
45
  }
45
46
  ]
@@ -63,6 +64,11 @@ module ChatworkTo
63
64
 
64
65
  def decorate(text)
65
66
  text
67
+ .gsub_task_added!
68
+ .gsub_task_done!
69
+ .gsub_reply!
70
+ .gsub_file_uploaded!
71
+ .gsub_quote!
66
72
  end
67
73
  end
68
74
  end
@@ -1,3 +1,3 @@
1
1
  module ChatworkTo
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chatwork_to
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - nalabjp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-18 00:00:00.000000000 Z
11
+ date: 2014-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -184,6 +184,7 @@ files:
184
184
  - lib/chatwork_to.rb
185
185
  - lib/chatwork_to/client.rb
186
186
  - lib/chatwork_to/config.rb
187
+ - lib/chatwork_to/message_decorator.rb
187
188
  - lib/chatwork_to/notifier.rb
188
189
  - lib/chatwork_to/notifiers/simple.rb
189
190
  - lib/chatwork_to/notifiers/slack.rb