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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bdfa929415bb8ec5a869549cd9794e0ae9c1ce39
4
- data.tar.gz: d6fab5adbd4df33544ffd08fe14ebfda6c2a87e8
3
+ metadata.gz: f2983ac4240b7eb64a305d391a72e6a5b938138b
4
+ data.tar.gz: 4b29f5d41631752102bec277c02e2f860868c390
5
5
  SHA512:
6
- metadata.gz: 201a3a6f73e820ee07dc0d99fd346e08acc6db0a2de0b4d3fec40363881e09bbe8ffb0ec5e32af766c25912834e80f122255b24bc070b194b6bac08fc84eb278
7
- data.tar.gz: ba2be307db61a287f98aa1b8c0930ac28d8f4be166d3e446763c9fbd6afc5c14728fa6450b1bae027579237c66ca95166981fe63c84602dcc8d377dcb5df360f
6
+ metadata.gz: f9c82fa36fa830aba79fd595e1faf782d11978510d3a94f4635b21519fd941cb64c31e8e5edfbafce579273d1457404584649d1c202d0199b5c255d2ca938e6e
7
+ data.tar.gz: a9e9275421a04637c0ca462f86548198e90424c09b40407380a533fb42b31e8f312ba490e74a0965a4e9733cdae395d5d33a387f377a166a20337421f3776417
@@ -0,0 +1 @@
1
+ slack-poster
@@ -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
 
@@ -1,5 +1,9 @@
1
1
  require 'slack-poster/version'
2
2
  require 'slack-poster/poster'
3
+ require 'slack-poster/author'
4
+ require 'slack-poster/field'
5
+ require 'slack-poster/message'
6
+ require 'slack-poster/attachment'
3
7
 
4
8
  module Slack
5
- end
9
+ end
@@ -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
@@ -4,7 +4,7 @@ module Slack
4
4
  class Poster
5
5
  include HTTParty
6
6
 
7
- attr_accessor :username, :channel
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(team, token, options = {})
40
- self.class.base_uri("https://#{team}.slack.com")
41
- self.class.default_params(token: token)
39
+ def initialize(webhook_url, options = {})
40
+ self.class.base_uri(webhook_url)
42
41
 
43
- @username = options[:username] || 'webhookbot'
44
- @channel = options[:channel] || '#general'
42
+ @attachments = []
45
43
 
46
- @icon_emoji = format_emoji(options[:icon_emoji])
47
- @icon_url = options[:icon_url]
44
+ @options = options
48
45
 
49
- raise ArgumentError, 'Team name is required' if team.nil?
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
- # This method will post to the configured team Slack.
54
- def send_message(text)
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
- response = self.class.post('/services/hooks/incoming-webhook', { body: { payload: body.to_json }})
52
+ attach_extras(body) unless attachments.empty?
58
53
 
59
- "#{response.body} (#{response.code})"
60
- end
54
+ response = self.class.post('', { body: { payload: body.to_json }})
61
55
 
62
- private
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
- def format_channel(channel)
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
@@ -1,3 +1,3 @@
1
1
  module Slack
2
- VERSION = '0.0.7'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency 'bundler', '~> 1.5'
22
22
  spec.add_development_dependency 'rake', '~> 10.1'
23
+ spec.add_development_dependency 'pry'
23
24
 
24
25
  spec.add_dependency 'httparty', '~> 0.12'
25
26
  end
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.7
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-01-14 00:00:00.000000000 Z
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.2.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.