messenger 0.6.0 → 0.7.0

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: 43b99873719b3d45b62713bed93b693e31643d6a
4
+ data.tar.gz: 2acb952179ba9d928f9849c2908e1e3511943d2e
5
+ SHA512:
6
+ metadata.gz: 997bc584e29a1ace9b819a085b24745919d87539e3e0d3f944575883ac3d20e62071c6fe1f4f349b0131c3124319460530f4d136baa9822c1d0099e0d2cd3607
7
+ data.tar.gz: 758920cdfaddcac2265d8a7bcebc0b0216245e9cfec043e8139e47164d1c13c7f56983c8f60fe5673d7823e84a0084bcb798676e496d242ac944641d96268f31
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Brandon Arbini / Zencoder, Inc.
1
+ Copyright (c) 2015 Brightcove, Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -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
- (c) 2010 Brandon Arbini / Zencoder, Inc.
65
+ License
66
+ =======
67
+
68
+ Messenger is licensed under the MIT License. [View the license file](LICENSE)
69
+
70
+ Copyright 2015 Brightcove, Inc
@@ -4,5 +4,7 @@ require 'messenger/result'
4
4
  require 'messenger/email'
5
5
  require 'messenger/web'
6
6
  require 'messenger/campfire'
7
+ require 'messenger/slack'
7
8
  require 'messenger/jabber'
9
+ require 'messenger/version_number'
8
10
  require 'messenger/version'
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Messenger
2
- VERSION = '0.6.0'
2
+ VERSION = Messenger::VersionNumber.new.to_s
3
3
  end
@@ -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
- hash: 7
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
- date: 2013-01-11 00:00:00 Z
20
- dependencies:
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
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
27
19
  - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
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
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
41
26
  - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
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
- requirement: &id003 !ruby/object:Gem::Requirement
53
- none: false
54
- requirements:
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
55
40
  - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
- version: "0"
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
- requirement: &id004 !ruby/object:Gem::Requirement
67
- none: false
68
- requirements:
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
- hash: 3
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
- requirement: &id005 !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
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
- hash: 3
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
- requirement: &id006 !ruby/object:Gem::Requirement
95
- none: false
96
- requirements:
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
97
82
  - - ">="
98
- - !ruby/object:Gem::Version
99
- hash: 3
100
- segments:
101
- - 0
102
- version: "0"
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
- requirement: &id007 !ruby/object:Gem::Requirement
109
- none: false
110
- requirements:
111
- - - ">="
112
- - !ruby/object:Gem::Version
113
- hash: 3
114
- segments:
115
- - 0
116
- version: "0"
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
- requirement: &id008 !ruby/object:Gem::Requirement
123
- none: false
124
- requirements:
125
- - - ">="
126
- - !ruby/object:Gem::Version
127
- hash: 3
128
- segments:
129
- - 0
130
- version: "0"
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
- requirement: &id009 !ruby/object:Gem::Requirement
137
- none: false
138
- requirements:
139
- - - ">="
140
- - !ruby/object:Gem::Version
141
- hash: 3
142
- segments:
143
- - 0
144
- version: "0"
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
- requirement: &id010 !ruby/object:Gem::Requirement
151
- none: false
152
- requirements:
153
- - - ">="
154
- - !ruby/object:Gem::Version
155
- hash: 3
156
- segments:
157
- - 0
158
- version: "0"
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
- version_requirements: *id010
161
- description: "Messenger: easy message sending for various protocols."
162
- email: brandon@zencoder.com
163
- executables:
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
- none: false
194
- requirements:
200
+ required_ruby_version: !ruby/object:Gem::Requirement
201
+ requirements:
195
202
  - - ">="
196
- - !ruby/object:Gem::Version
197
- hash: 3
198
- segments:
199
- - 0
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
- hash: 3
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: 1.8.24
212
+ rubygems_version: 2.4.6
214
213
  signing_key:
215
- specification_version: 3
216
- summary: "Messenger: easy message sending"
214
+ specification_version: 4
215
+ summary: 'Messenger: easy message sending'
217
216
  test_files: []
218
-
219
- has_rdoc: