slack-poster 0.0.7 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/README.md +0 -1
- data/lib/slack-poster.rb +5 -1
- data/lib/slack-poster/attachment.rb +41 -0
- data/lib/slack-poster/author.rb +25 -0
- data/lib/slack-poster/field.rb +19 -0
- data/lib/slack-poster/message.rb +36 -0
- data/lib/slack-poster/poster.rb +12 -28
- data/lib/slack-poster/version.rb +1 -1
- data/slack-poster.gemspec +1 -0
- metadata +23 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2983ac4240b7eb64a305d391a72e6a5b938138b
|
4
|
+
data.tar.gz: 4b29f5d41631752102bec277c02e2f860868c390
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9c82fa36fa830aba79fd595e1faf782d11978510d3a94f4635b21519fd941cb64c31e8e5edfbafce579273d1457404584649d1c202d0199b5c255d2ca938e6e
|
7
|
+
data.tar.gz: a9e9275421a04637c0ca462f86548198e90424c09b40407380a533fb42b31e8f312ba490e74a0965a4e9733cdae395d5d33a387f377a166a20337421f3776417
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
slack-poster
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.2
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
[![Dependency Status](https://gemnasium.com/rikas/slack-poster.svg)](https://gemnasium.com/rikas/slack-poster)
|
2
2
|
|
3
3
|
# Slack Poster
|
4
|
-
[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/rikas/slack-poster?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
5
4
|
|
6
5
|
[Slack](https://slack.com/) is a mashup of chatrooms and collaborative sharing tools that are meant to do away with redundant conversations in multiple places.
|
7
6
|
|
data/lib/slack-poster.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
module Slack
|
2
|
+
class Attachment
|
3
|
+
ATTRIBUTES = %i(fallback text title title_link image_url color pretext)
|
4
|
+
|
5
|
+
ATTRIBUTES.each do |attribute|
|
6
|
+
attr_accessor attribute
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :fields, :author
|
10
|
+
|
11
|
+
def initialize(options = {})
|
12
|
+
@fields = []
|
13
|
+
|
14
|
+
ATTRIBUTES.each do |attribute|
|
15
|
+
self.send("#{attribute}=", options.delete(attribute))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_field(title, value, short = false)
|
20
|
+
self.fields << Field.new(title, value, short)
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def author=(author)
|
25
|
+
@author = author
|
26
|
+
end
|
27
|
+
|
28
|
+
def as_json
|
29
|
+
hash = {}
|
30
|
+
|
31
|
+
ATTRIBUTES.each do |attribute|
|
32
|
+
hash[attribute] = send(attribute) if send(attribute)
|
33
|
+
end
|
34
|
+
|
35
|
+
hash.merge!(fields: fields.map(&:as_json)) unless fields.empty?
|
36
|
+
hash.merge!(author: author.as_json) if author
|
37
|
+
|
38
|
+
hash
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Slack
|
2
|
+
class Author
|
3
|
+
ATTRIBUTES = %i(name link icon)
|
4
|
+
|
5
|
+
ATTRIBUTES.each do |attribute|
|
6
|
+
attr_accessor attribute
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
ATTRIBUTES.each do |attribute|
|
11
|
+
self.send("#{attribute}=", options.delete(attribute))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def as_json
|
16
|
+
hash = {}
|
17
|
+
|
18
|
+
ATTRIBUTES.each do |attribute|
|
19
|
+
hash[attribute] = send(attribute) if send(attribute)
|
20
|
+
end
|
21
|
+
|
22
|
+
hash
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Slack
|
2
|
+
class Field
|
3
|
+
attr_accessor :title, :value, :short
|
4
|
+
|
5
|
+
def initialize(title, value, short = false)
|
6
|
+
@title = title
|
7
|
+
@value = value
|
8
|
+
@short = short
|
9
|
+
end
|
10
|
+
|
11
|
+
def as_json
|
12
|
+
{
|
13
|
+
title: title,
|
14
|
+
value: value,
|
15
|
+
short: short
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Slack
|
2
|
+
class Message
|
3
|
+
attr_accessor :text
|
4
|
+
attr_reader :attachments
|
5
|
+
|
6
|
+
def initialize(text, attachment = nil)
|
7
|
+
@text = text
|
8
|
+
@attachments = []
|
9
|
+
@attachments << attachment if attachment
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_attachment(attachment)
|
13
|
+
@attachments << attachment
|
14
|
+
end
|
15
|
+
|
16
|
+
def as_json
|
17
|
+
hash = { text: text }
|
18
|
+
|
19
|
+
merge_attachments(hash) unless attachments.empty?
|
20
|
+
|
21
|
+
hash
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def merge_attachments(hash)
|
27
|
+
json = []
|
28
|
+
|
29
|
+
attachments.each do |attachment|
|
30
|
+
json << attachment.as_json
|
31
|
+
end
|
32
|
+
|
33
|
+
hash.merge!(attachments: json)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/slack-poster/poster.rb
CHANGED
@@ -4,7 +4,7 @@ module Slack
|
|
4
4
|
class Poster
|
5
5
|
include HTTParty
|
6
6
|
|
7
|
-
attr_accessor :
|
7
|
+
attr_accessor :url, :options, :attachments
|
8
8
|
|
9
9
|
# The format of the response. This comes back as 'ok' from slack.
|
10
10
|
format :plain
|
@@ -36,42 +36,26 @@ module Slack
|
|
36
36
|
# => Slack::Poster.new('myteam', 'eNmZHQY6f591ziHyZdzePFz8', username: 'Ricardo',
|
37
37
|
# icon_emoji: 'ghost')
|
38
38
|
#
|
39
|
-
def initialize(
|
40
|
-
self.class.base_uri(
|
41
|
-
self.class.default_params(token: token)
|
39
|
+
def initialize(webhook_url, options = {})
|
40
|
+
self.class.base_uri(webhook_url)
|
42
41
|
|
43
|
-
@
|
44
|
-
@channel = options[:channel] || '#general'
|
42
|
+
@attachments = []
|
45
43
|
|
46
|
-
@
|
47
|
-
@icon_url = options[:icon_url]
|
44
|
+
@options = options
|
48
45
|
|
49
|
-
raise ArgumentError, '
|
50
|
-
raise ArgumentError, 'Token is' if token.nil?
|
46
|
+
raise ArgumentError, 'Webhook URL is required' if webhook_url.nil?
|
51
47
|
end
|
52
48
|
|
53
|
-
|
54
|
-
|
55
|
-
body = { text: text, channel: @channel, username: @username }.merge(avatar_hash)
|
49
|
+
def send_message(message)
|
50
|
+
body = message.is_a?(String) ? options.merge(text: text) : options.merge(message.as_json)
|
56
51
|
|
57
|
-
|
52
|
+
attach_extras(body) unless attachments.empty?
|
58
53
|
|
59
|
-
|
60
|
-
end
|
54
|
+
response = self.class.post('', { body: { payload: body.to_json }})
|
61
55
|
|
62
|
-
|
63
|
-
|
64
|
-
def avatar_hash
|
65
|
-
@icon_emoji ? { icon_emoji: @icon_emoji } : { icon_url: @icon_url }
|
66
|
-
end
|
56
|
+
puts body.to_json
|
67
57
|
|
68
|
-
|
69
|
-
"##{channel.split('#').last}"
|
70
|
-
end
|
71
|
-
|
72
|
-
def format_emoji(emoji)
|
73
|
-
emoji = emoji.to_s.gsub(':', '')
|
74
|
-
emoji.empty? ? nil : ":#{emoji}:"
|
58
|
+
"#{response.body} (#{response.code})"
|
75
59
|
end
|
76
60
|
end
|
77
61
|
end
|
data/lib/slack-poster/version.rb
CHANGED
data/slack-poster.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack-poster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricardo Otero
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: httparty
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -60,11 +74,17 @@ extensions: []
|
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
62
76
|
- ".gitignore"
|
77
|
+
- ".ruby-gemset"
|
78
|
+
- ".ruby-version"
|
63
79
|
- Gemfile
|
64
80
|
- LICENSE.txt
|
65
81
|
- README.md
|
66
82
|
- Rakefile
|
67
83
|
- lib/slack-poster.rb
|
84
|
+
- lib/slack-poster/attachment.rb
|
85
|
+
- lib/slack-poster/author.rb
|
86
|
+
- lib/slack-poster/field.rb
|
87
|
+
- lib/slack-poster/message.rb
|
68
88
|
- lib/slack-poster/poster.rb
|
69
89
|
- lib/slack-poster/version.rb
|
70
90
|
- slack-poster.gemspec
|
@@ -88,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
108
|
version: '0'
|
89
109
|
requirements: []
|
90
110
|
rubyforge_project:
|
91
|
-
rubygems_version: 2.
|
111
|
+
rubygems_version: 2.4.6
|
92
112
|
signing_key:
|
93
113
|
specification_version: 4
|
94
114
|
summary: Slack wrapper for Incoming WebHooks integrations.
|