messenger 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +1 -1
- data/README.markdown +20 -1
- data/lib/messenger.rb +2 -0
- data/lib/messenger/messenger.rb +2 -0
- data/lib/messenger/slack.rb +79 -0
- data/lib/messenger/version.rb +1 -1
- data/lib/messenger/version_number.rb +35 -0
- metadata +160 -163
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 43b99873719b3d45b62713bed93b693e31643d6a
|
4
|
+
data.tar.gz: 2acb952179ba9d928f9849c2908e1e3511943d2e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 997bc584e29a1ace9b819a085b24745919d87539e3e0d3f944575883ac3d20e62071c6fe1f4f349b0131c3124319460530f4d136baa9822c1d0099e0d2cd3607
|
7
|
+
data.tar.gz: 758920cdfaddcac2265d8a7bcebc0b0216245e9cfec043e8139e47164d1c13c7f56983c8f60fe5673d7823e84a0084bcb798676e496d242ac944641d96268f31
|
data/LICENSE
CHANGED
data/README.markdown
CHANGED
@@ -31,6 +31,20 @@ Campfire messages are sent using the HTTParty gem against the Campfire API.
|
|
31
31
|
messenger campfire://api-key:room-id@subdomain.campfirenow.com "Message"
|
32
32
|
|
33
33
|
|
34
|
+
Slack
|
35
|
+
---
|
36
|
+
|
37
|
+
Slack messages are sent using the HTTParty gem against the [incoming webhooks API](https://api.slack.com/incoming-webhooks). If the message sent is a string, the message will be delivered
|
38
|
+
as such. If it's an object or an array of objects, those will be sent as attachments.
|
39
|
+
|
40
|
+
messenger slack://displayname@hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX/#room "Message"
|
41
|
+
messenger slack://displayname@hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX/#room { fallback: 'Important notice', color: '#0000ff', text: 'Man this is some super important text' }
|
42
|
+
|
43
|
+
You can also specify a custom user image by passing `icon_url` or `icon_emoji` in the options block.
|
44
|
+
|
45
|
+
messenger slack://displayname@hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX/#room "Message" { icon_emoji: ':ghost:' }
|
46
|
+
|
47
|
+
|
34
48
|
Jabber
|
35
49
|
------
|
36
50
|
|
@@ -48,4 +62,9 @@ Messenger will also read in ~/.messenger (a YAML file) for default config inform
|
|
48
62
|
jabber_password: ########
|
49
63
|
|
50
64
|
|
51
|
-
|
65
|
+
License
|
66
|
+
=======
|
67
|
+
|
68
|
+
Messenger is licensed under the MIT License. [View the license file](LICENSE)
|
69
|
+
|
70
|
+
Copyright 2015 Brightcove, Inc
|
data/lib/messenger.rb
CHANGED
data/lib/messenger/messenger.rb
CHANGED
@@ -38,6 +38,7 @@ module Messenger
|
|
38
38
|
when /\Acampfire/ then :campfire
|
39
39
|
when /\Ajabber/ then :jabber
|
40
40
|
when /\Amailto|@+/ then :email
|
41
|
+
when /\Aslack/ then :slack
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
@@ -47,6 +48,7 @@ module Messenger
|
|
47
48
|
when :http then Messenger::Web
|
48
49
|
when :campfire then Messenger::Campfire
|
49
50
|
when :jabber then Messenger::Jabber
|
51
|
+
when :slack then Messenger::Slack
|
50
52
|
else
|
51
53
|
raise Messenger::ProtocolError, "Malformed service URL: #{url}. Either this syntax is wrong or this service type is not yet implemented."
|
52
54
|
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class Messenger::Slack
|
5
|
+
|
6
|
+
def self.valid_url?(url)
|
7
|
+
!!matcher(url)
|
8
|
+
end
|
9
|
+
|
10
|
+
# URL format:
|
11
|
+
# slack://displayname@hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX/#room
|
12
|
+
# Slack supports the notion of attachments, so the messages can be a little fancier. If body is a string, that
|
13
|
+
# string will simply be sent to the room as text. `body` can also be an array of attachments, or a single attachment.
|
14
|
+
# Attachment reference: https://api.slack.com/docs/attachments
|
15
|
+
def self.deliver(url, body, options={})
|
16
|
+
raise Messenger::URLError, "The URL provided is invalid" unless valid_url?(url)
|
17
|
+
parsed_url = matcher(url)
|
18
|
+
|
19
|
+
options[:headers] ||= {}
|
20
|
+
response = HTTParty.post(
|
21
|
+
"https://#{parsed_url[:base_url]}/#{parsed_url[:key_one]}/#{parsed_url[:key_two]}/#{parsed_url[:secret]}",
|
22
|
+
:headers => { "Content-Type" => "application/json"}.merge(options[:headers]),
|
23
|
+
:body => build_message(parsed_url[:channel], parsed_url[:display_name], body, options)
|
24
|
+
)
|
25
|
+
Messenger::Result.new(success?(response), response)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.obfuscate(url)
|
29
|
+
raise Messenger::URLError, "The URL provided is invalid" unless valid_url?(url)
|
30
|
+
parsed_url = matcher(url)
|
31
|
+
"slack://#{parsed_url[:display_name]}@#{parsed_url[:base_url]}/T********/B********/************************/#{parsed_url[:channel]}"
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def self.build_message(channel, display_name, body, options)
|
38
|
+
msg = { channel: channel, username: display_name }
|
39
|
+
|
40
|
+
msg['icon_emoji'] = options[:icon_emoji] if options[:icon_emoji]
|
41
|
+
msg['icon_url'] = options[:icon_url] if options[:icon_url]
|
42
|
+
|
43
|
+
if body.is_a?(String)
|
44
|
+
msg.merge!({ text: body })
|
45
|
+
|
46
|
+
elsif body.is_a?(Array)
|
47
|
+
msg['attachments'] = body
|
48
|
+
|
49
|
+
elsif body.is_a?(Hash)
|
50
|
+
msg['attachments'] = []
|
51
|
+
msg['attachments'].push(body)
|
52
|
+
end
|
53
|
+
|
54
|
+
msg.to_json
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.matcher(url)
|
58
|
+
return false unless match = url.match(/slack:\/\/(.*)@(hooks.slack.com\/services)\/([T].*?)\/([B].*?)\/(.*)\/([#@].*)/)
|
59
|
+
|
60
|
+
{
|
61
|
+
display_name: match[1],
|
62
|
+
base_url: match[2],
|
63
|
+
key_one: match[3],
|
64
|
+
key_two: match[4],
|
65
|
+
secret: match[5],
|
66
|
+
channel: match[6]
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.success?(response)
|
71
|
+
case response.code
|
72
|
+
when 200, 201
|
73
|
+
true
|
74
|
+
else
|
75
|
+
false
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
data/lib/messenger/version.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Messenger
|
4
|
+
class VersionNumber
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@version = YAML.load_file('VERSION.yml')
|
8
|
+
end
|
9
|
+
|
10
|
+
def major
|
11
|
+
@version['major']
|
12
|
+
end
|
13
|
+
|
14
|
+
def minor
|
15
|
+
@version['minor']
|
16
|
+
end
|
17
|
+
|
18
|
+
def patch
|
19
|
+
@version['patch']
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_hash
|
23
|
+
@version.dup
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_a
|
27
|
+
[major, minor, patch]
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
to_a.join(".")
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,219 +1,216 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: messenger
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 6
|
9
|
-
- 0
|
10
|
-
version: 0.6.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Brandon Arbini
|
14
8
|
- Nathan Sutton
|
9
|
+
- Matthew McClure
|
15
10
|
autorequire:
|
16
11
|
bindir: bin
|
17
12
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
- !ruby/object:Gem::Dependency
|
13
|
+
date: 2015-03-03 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
22
16
|
name: scashin133-xmpp4r-simple
|
23
|
-
|
24
|
-
|
25
|
-
none: false
|
26
|
-
requirements:
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
27
19
|
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
33
22
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: mail
|
37
23
|
prerelease: false
|
38
|
-
|
39
|
-
|
40
|
-
requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
41
26
|
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: mail
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
47
36
|
type: :runtime
|
48
|
-
version_requirements: *id002
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: httparty
|
51
37
|
prerelease: false
|
52
|
-
|
53
|
-
|
54
|
-
requirements:
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
55
40
|
- - ">="
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: httparty
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
61
50
|
type: :runtime
|
62
|
-
version_requirements: *id003
|
63
|
-
- !ruby/object:Gem::Dependency
|
64
|
-
name: trollop
|
65
51
|
prerelease: false
|
66
|
-
|
67
|
-
|
68
|
-
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: trollop
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
69
61
|
- - ">="
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
|
72
|
-
segments:
|
73
|
-
- 0
|
74
|
-
version: "0"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
75
64
|
type: :runtime
|
76
|
-
version_requirements: *id004
|
77
|
-
- !ruby/object:Gem::Dependency
|
78
|
-
name: addressable
|
79
65
|
prerelease: false
|
80
|
-
|
81
|
-
|
82
|
-
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: addressable
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
83
75
|
- - ">="
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
|
86
|
-
segments:
|
87
|
-
- 0
|
88
|
-
version: "0"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
89
78
|
type: :runtime
|
90
|
-
version_requirements: *id005
|
91
|
-
- !ruby/object:Gem::Dependency
|
92
|
-
name: shoulda
|
93
79
|
prerelease: false
|
94
|
-
|
95
|
-
|
96
|
-
requirements:
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
97
82
|
- - ">="
|
98
|
-
- !ruby/object:Gem::Version
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: test-unit
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - "~>"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '3.0'
|
103
92
|
type: :development
|
104
|
-
version_requirements: *id006
|
105
|
-
- !ruby/object:Gem::Dependency
|
106
|
-
name: mocha
|
107
93
|
prerelease: false
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - "~>"
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '3.0'
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: shoulda
|
101
|
+
requirement: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '3.5'
|
117
106
|
type: :development
|
118
|
-
version_requirements: *id007
|
119
|
-
- !ruby/object:Gem::Dependency
|
120
|
-
name: webmock
|
121
107
|
prerelease: false
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
108
|
+
version_requirements: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - "~>"
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '3.5'
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: mocha
|
115
|
+
requirement: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - "~>"
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '1.1'
|
131
120
|
type: :development
|
132
|
-
version_requirements: *id008
|
133
|
-
- !ruby/object:Gem::Dependency
|
134
|
-
name: rake
|
135
121
|
prerelease: false
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
122
|
+
version_requirements: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - "~>"
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '1.1'
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
name: webmock
|
129
|
+
requirement: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - "~>"
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '1.20'
|
145
134
|
type: :development
|
146
|
-
version_requirements: *id009
|
147
|
-
- !ruby/object:Gem::Dependency
|
148
|
-
name: rdoc
|
149
135
|
prerelease: false
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - "~>"
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '1.20'
|
141
|
+
- !ruby/object:Gem::Dependency
|
142
|
+
name: rake
|
143
|
+
requirement: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - "~>"
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '10.4'
|
159
148
|
type: :development
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
149
|
+
prerelease: false
|
150
|
+
version_requirements: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - "~>"
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '10.4'
|
155
|
+
- !ruby/object:Gem::Dependency
|
156
|
+
name: rdoc
|
157
|
+
requirement: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - "~>"
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '4.2'
|
162
|
+
type: :development
|
163
|
+
prerelease: false
|
164
|
+
version_requirements: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - "~>"
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '4.2'
|
169
|
+
description: 'Messenger: easy message sending for various protocols.'
|
170
|
+
email: mmcclure@brightcove.com
|
171
|
+
executables:
|
164
172
|
- messenger
|
165
173
|
extensions: []
|
166
|
-
|
167
|
-
extra_rdoc_files:
|
174
|
+
extra_rdoc_files:
|
168
175
|
- LICENSE
|
169
176
|
- README.markdown
|
170
|
-
files:
|
177
|
+
files:
|
178
|
+
- LICENSE
|
179
|
+
- README.markdown
|
180
|
+
- Rakefile
|
181
|
+
- bin/messenger
|
182
|
+
- lib/messenger.rb
|
171
183
|
- lib/messenger/campfire.rb
|
172
184
|
- lib/messenger/email.rb
|
173
185
|
- lib/messenger/errors.rb
|
174
186
|
- lib/messenger/jabber.rb
|
175
187
|
- lib/messenger/messenger.rb
|
176
188
|
- lib/messenger/result.rb
|
189
|
+
- lib/messenger/slack.rb
|
177
190
|
- lib/messenger/version.rb
|
191
|
+
- lib/messenger/version_number.rb
|
178
192
|
- lib/messenger/web.rb
|
179
|
-
- lib/messenger.rb
|
180
|
-
- LICENSE
|
181
|
-
- README.markdown
|
182
|
-
- Rakefile
|
183
|
-
- bin/messenger
|
184
193
|
homepage: http://github.com/zencoder/messenger
|
185
194
|
licenses: []
|
186
|
-
|
195
|
+
metadata: {}
|
187
196
|
post_install_message:
|
188
197
|
rdoc_options: []
|
189
|
-
|
190
|
-
require_paths:
|
198
|
+
require_paths:
|
191
199
|
- lib
|
192
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
193
|
-
|
194
|
-
requirements:
|
200
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
201
|
+
requirements:
|
195
202
|
- - ">="
|
196
|
-
- !ruby/object:Gem::Version
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
version: "0"
|
201
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
202
|
-
none: false
|
203
|
-
requirements:
|
203
|
+
- !ruby/object:Gem::Version
|
204
|
+
version: '0'
|
205
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
206
|
+
requirements:
|
204
207
|
- - ">="
|
205
|
-
- !ruby/object:Gem::Version
|
206
|
-
|
207
|
-
segments:
|
208
|
-
- 0
|
209
|
-
version: "0"
|
208
|
+
- !ruby/object:Gem::Version
|
209
|
+
version: '0'
|
210
210
|
requirements: []
|
211
|
-
|
212
211
|
rubyforge_project: messenger
|
213
|
-
rubygems_version:
|
212
|
+
rubygems_version: 2.4.6
|
214
213
|
signing_key:
|
215
|
-
specification_version:
|
216
|
-
summary:
|
214
|
+
specification_version: 4
|
215
|
+
summary: 'Messenger: easy message sending'
|
217
216
|
test_files: []
|
218
|
-
|
219
|
-
has_rdoc:
|