slackdraft 0.7.6c → 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: 5e50ebf5183cb3d283edc5f715557586975a11b6
4
- data.tar.gz: ff7919f5e9d145855528f2a86c0c039611deabbb
3
+ metadata.gz: 7dcad482dd1834021d0d51df6e59ca8b0ef8bc69
4
+ data.tar.gz: 055da9c748a5f1ee1a02fb9a2bf608b4cc400d65
5
5
  SHA512:
6
- metadata.gz: f87c2bf0b4f5d15be3f3ebfe550e1112a20eef70d18dda20a1f56d9bc280aa03bf003abd939a547adf4b7d59d46da3011ddbae0f15eb9b19ac6adf635e4ce489
7
- data.tar.gz: 25bbb8556fe4b30fe21cfe6569532f45df7724aeaa8954fb340990f2b0bdf5f56e691da00e2ff18c3e4a1f61827f5e0b39f231edbf6f747d07015a2793cf7886
6
+ metadata.gz: 8aa49f4ceba089f62f776f8092c58b9d62d306d3d240a4593ca2f7dda4d8044487bc1ebc1fa940dbcbb1e54e47df06cf62e99f99649a678cfc9540393019a286
7
+ data.tar.gz: 8b5113394c3e2be2c356173b29e2f5b6152577606c3dcdaee9b68d6678658e128fa1a36c80951697cc74aeb68620f13ea3281fec47262a8979362f46b8cedaa4
data/.travis.yml ADDED
@@ -0,0 +1 @@
1
+ language: ruby
data/Gemfile.lock CHANGED
@@ -1,8 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slackdraft (0.7.6c)
4
+ slackdraft (0.7.7)
5
+ fattr
5
6
  httparty
7
+ methadone
8
+ paint
6
9
 
7
10
  GEM
8
11
  remote: https://rubygems.org/
@@ -11,11 +14,15 @@ GEM
11
14
  crack (0.4.2)
12
15
  safe_yaml (~> 1.0.0)
13
16
  diff-lcs (1.2.5)
17
+ fattr (2.2.2)
14
18
  httparty (0.13.3)
15
19
  json (~> 1.8)
16
20
  multi_xml (>= 0.5.2)
17
21
  json (1.8.2)
22
+ methadone (1.8.0)
23
+ bundler
18
24
  multi_xml (0.5.5)
25
+ paint (0.9.0)
19
26
  rake (10.4.2)
20
27
  rspec (3.2.0)
21
28
  rspec-core (~> 3.2.0)
data/README.md CHANGED
@@ -1,2 +1,70 @@
1
1
  # slackdraft
2
- Simplest way to format messages to Slack
2
+ Simplest way to send messages to Slack.
3
+
4
+ ![TravisCI](https://travis-ci.org/mikemackintosh/slackdraft.svg)
5
+
6
+ # Installation
7
+
8
+ Like any other gem:
9
+
10
+ gem install slackdraft
11
+
12
+
13
+ # Ruby Usage
14
+
15
+ Usage is very simple:
16
+
17
+ require 'slackdraft'
18
+ url = "https://slack/webhook/url"
19
+ slack = Slackdraft::Message.new(url)
20
+
21
+ # Url of the icon or emoji
22
+ # slack.icon_url = "https://..."
23
+ slack.icon_emoji = ":fire:"
24
+
25
+ # Set the bot username
26
+ slack.username = "SlackDraft"
27
+
28
+ # Set the channel
29
+ slack.channel = "#general"
30
+
31
+ # Set text
32
+ slack.text = "Your message here! _*And can have* formatting_"
33
+
34
+ # Or you can pass text in as an array
35
+ # slack.text = ["Your message here!", ">_*And can have* formatting_"]
36
+
37
+ # Send the message
38
+ slack.send!
39
+ #-> true/false
40
+
41
+ For more examples, see the `examples/` directory.
42
+
43
+ # Command-line Usage
44
+
45
+ It's dumb simple. Instead of using `curl`, use this:
46
+
47
+ slackdraft -u mike \
48
+ -c "#slackdraft" \
49
+ -m "This is our *formammted message*" \
50
+ https://hooks.slack.com/services/xxxxxxx
51
+
52
+ > **Note**: The CLI version does not support Slack Attachments
53
+
54
+ ## Help text
55
+
56
+ $ slackdraft -h
57
+ Usage: slackdraft [options] url
58
+
59
+ Slack with less Kurt Russell
60
+
61
+ v0.7.7
62
+
63
+ Options:
64
+ -h, --help Show command line help
65
+ --version Show help/version info
66
+ -c, --channel CHANNEL Channel to send message to
67
+ -u, --username USER User to send message as
68
+ -m, --message MESSAGE Message to send
69
+ -e, --emoji EMOJI Emoji to prefix message with
70
+ -i, --icon ICON Icon to prefix message with
data/bin/slackdraft CHANGED
@@ -2,12 +2,59 @@
2
2
  # coding: utf-8
3
3
 
4
4
  require 'slackdraft'
5
+ require 'methadone'
5
6
 
6
- slack = Slackdraft::Message.new 'https://hooks.slack.com/services/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'
7
- #slack.icon = "this"
8
- #slack.icon_emoji = ":fire:"
9
- slack.channel = "#slackdraft"
10
- slack.text = ["Testing *formatting* and", "> this should be"]
11
- slack.send!
7
+ class App
8
+ include Methadone::Main
12
9
 
13
- puts slack.inspect
10
+ leak_exceptions true
11
+
12
+ # Set Version
13
+ version Slackdraft::VERSION
14
+ description "Slack with less Kurt Russell"
15
+
16
+ # This is the main instructions
17
+ main do |url|
18
+
19
+ # Create instance
20
+ slack = Slackdraft::Message.new(url)
21
+ slack.icon_url = options[:icon]
22
+ slack.icon_emoji = options[:emoji]
23
+ slack.username = options[:username]
24
+ slack.channel = options[:channel]
25
+ slack.text = options[:message]
26
+
27
+ # Send it, and check response
28
+ if slack.send!
29
+ Slackdraft::success("Message successful")
30
+ end
31
+
32
+ end
33
+
34
+ # These are the options
35
+ on('-c', '--channel CHANNEL', "Channel to send message to")
36
+ on('-u', '--username USER', "User to send message as")
37
+ on('-m', '--message MESSAGE', "Message to send")
38
+ on('-e', '--emoji EMOJI', "Emoji to prefix message with")
39
+ on('-i', '--icon ICON', "Icon to prefix message with")
40
+
41
+ # Grab to webhook url
42
+ arg :url
43
+
44
+ begin
45
+
46
+ # No Args?
47
+ if ARGV.empty?
48
+ Slackdraft::fatal("No options given; see slackdraft --help for options.")
49
+ end
50
+
51
+ go!
52
+
53
+ rescue Interrupt
54
+ print "\b\b\n"; # Remove ^C from screen
55
+ Slackdraft::fatal("Caught interrupt; exiting.")
56
+ rescue => e
57
+ Slackdraft::fatal("An error occurred: #{e.class.name}: #{e.message}")
58
+ end
59
+
60
+ end
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ require 'slackdraft'
5
+
6
+ # Set URL
7
+ url = "https://hooks.slack.com/services/xxxxxxxxxx"
8
+
9
+ # Create instance
10
+ slack = Slackdraft::Attachment.new(url)
11
+ slack.fallback = "Fallback text!!!!"
12
+ slack.color = "#439FE0"
13
+ slack.pretext ="Hmm where?"
14
+
15
+ slack.author_name = "Mike"
16
+ slack.author_link = "https://github.com/mikemackintosh"
17
+ slack.author_icon = ":skull:"
18
+
19
+ slack.title = "By Mike Mackintosh"
20
+ slack.title_link = "https://github.com/mikemackintosh"
21
+
22
+ slack.text = "This is pretty cool"
23
+
24
+ slack.add_field("col 1", "blahblahblah")
25
+ slack.add_field("col 2", "derpherp")
26
+
27
+ # Send it, and check response
28
+ if slack.send!
29
+ Slackdraft::success("Message successful")
30
+ end
@@ -0,0 +1,52 @@
1
+ module Slackdraft
2
+
3
+ class Attachment < Base
4
+
5
+ fattr fallback: "This message was sent with Slackdraft"
6
+ fattr color: "#439FE0"
7
+ fattr pretext: nil
8
+
9
+ fattr author_name: nil
10
+ fattr author_link: nil
11
+ fattr author_icon: nil
12
+
13
+ fattr title: nil
14
+ fattr title_link: nil
15
+
16
+ fattr text: nil
17
+ fattr fields: []
18
+
19
+ fattr image_url: nil
20
+
21
+ # Short defines if it's 1 column or not, default: not
22
+ def add_field(title, value, short=true)
23
+ fields.push({:title => title, :value => value, :short => short })
24
+ end
25
+
26
+ # Generate the payload for slack attachments
27
+ def generate_payload
28
+ payload = {}
29
+ payload[:fallback] = self.fallback unless self.fallback.nil?
30
+ payload[:color] = self.color unless self.color.nil?
31
+ payload[:pretext] = self.pretext unless self.pretext.nil?
32
+ payload[:author_name] = self.author_name unless self.author_name.nil?
33
+ payload[:author_link] = self.author_link unless self.author_link.nil?
34
+ payload[:author_icon] = self.author_icon unless self.author_icon.nil?
35
+ payload[:title] = self.title unless self.title.nil?
36
+ payload[:title_link] = self.title_link unless self.title_link.nil?
37
+ payload[:text] = self.text unless self.text.nil?
38
+
39
+ unless self.fields.nil?
40
+ payload[:fields] = self.fields if self.fields.length > 0
41
+ end
42
+
43
+ payload[:image_url] = self.image_url unless self.image_url.nil?
44
+
45
+ puts payload.inspect
46
+
47
+ payload
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,37 @@
1
+ module Slackdraft
2
+ class Base
3
+
4
+ fattr endpoint: 'https://hooks.slack.com/services/'
5
+
6
+ # Init the class
7
+ def initialize(token, &block)
8
+ if /^https?/.match(token)
9
+ @target = token
10
+ else
11
+ @target = "#{self.endpoint}#{@token}"
12
+ end
13
+
14
+ instance_eval(&block) if block_given?
15
+ end
16
+
17
+ def target
18
+ @target
19
+ end
20
+
21
+ # Send the message!
22
+ def send!
23
+
24
+ # Send the request
25
+ request = HTTParty.post(self.target, :body => {
26
+ :payload => generate_payload.to_json
27
+ })
28
+
29
+ unless request.code.eql? 200
30
+ false
31
+ end
32
+
33
+ true
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,65 @@
1
+ module Slackdraft
2
+ class Message < Slackdraft::Base
3
+
4
+ # Attributes
5
+ fattr username: 'slackdraft'
6
+ fattr channel: '#general'
7
+ fattr icon_emoji: ':fire:'
8
+ fattr icon_url: ''
9
+ fattr text: ''
10
+
11
+ # Set the api call username
12
+ def username
13
+ return 'slackdraft' if @username.nil?
14
+ @username
15
+ end
16
+
17
+ # Set the destination channel
18
+ def channel
19
+ return '#general' if @channel.nil?
20
+ @channel
21
+ end
22
+
23
+ # Set the icon URL and default to the emoji
24
+ def icon_url
25
+ @icon_url || icon_emoji
26
+ end
27
+
28
+ # Set the emoji
29
+ def icon_emoji
30
+ return ':fire:' if @icon_emoji.nil?
31
+ end
32
+
33
+ def refchannel(channel)
34
+ "<#C024BE7LR|#{channel}>"
35
+ end
36
+
37
+ def refuser(user)
38
+ "<@U024BE7LH|#{user}>"
39
+ end
40
+
41
+ # Set the text of the message
42
+ def text
43
+
44
+ if @text.kind_of?(Array)
45
+ return @text.join("\n")
46
+ end
47
+
48
+ @text
49
+
50
+ end
51
+
52
+ # Generate the payload if stuff was provided
53
+ def generate_payload
54
+ payload = {}
55
+ payload[:channel] = self.channel unless self.channel.nil?
56
+ payload[:username] = self.username unless self.username.nil?
57
+ payload[:icon_url] = self.icon_url unless self.icon_url.nil?
58
+ payload[:icon_emoji] = self.icon_emoji unless self.icon_emoji.nil?
59
+ payload[:text] = self.text unless self.text.nil?
60
+
61
+ payload
62
+ end
63
+
64
+ end
65
+ end
@@ -1,3 +1,3 @@
1
1
  module Slackdraft
2
- VERSION = '0.7.6c'
2
+ VERSION = '1.0.0'
3
3
  end
data/lib/slackdraft.rb CHANGED
@@ -1,83 +1,34 @@
1
1
  require 'httparty'
2
2
  require 'json'
3
3
  require 'cgi'
4
+ require 'fattr'
5
+ require 'paint'
4
6
 
7
+ require 'slackdraft/base'
8
+ require 'slackdraft/message'
5
9
  require 'slackdraft/version'
6
- #require 'slackdraft/attachment'
7
- #require 'slackdraft/message'
10
+ require 'slackdraft/attachment'
8
11
 
9
12
  module Slackdraft
10
- class Message
11
-
12
- # Attributes
13
- attr_writer :username
14
- attr_writer :channel
15
- attr_writer :icon_url
16
- attr_writer :icon_emoji
17
- attr_writer :text
18
-
19
- # Init the class
20
- def initialize(url)
21
- @webhookuri = url
22
- end
23
-
24
- # Set the api call username
25
- def username
26
- @username ||= 'slackdraft'
27
- end
28
-
29
- # Set the destination channel
30
- def channel
31
- @channel || '#general'
32
- end
33
-
34
- # Set the icon URL and default to the emoji
35
- def icon_url
36
- @icon_url || icon_emoji
37
- end
38
-
39
- # Set the emoji
40
- def icon_emoji
41
- @icon_emoji || ':fire:'
42
- end
43
-
44
- # Set the text of the message
45
- def text
46
- @text.join("\n")
47
- puts @text
48
- end
49
-
50
- # Send the message!
51
- def send!
52
-
53
- puts @channel
54
- puts @username
55
-
56
- request = HTTParty.post(@webhookuri, :body => {
57
- :payload => {
58
- :channel => @channel,
59
- :username => @username,
60
- :text => @text,
61
- :icon_emoji => @icon_emoji,
62
- }.to_json
63
- })
64
-
65
- puts request.code
66
- puts request.body
67
- end
68
-
13
+
14
+ def self.success(message)
15
+ puts " #{Paint['[✓]', :bright, :green]} #{Paint[message, :bright, :white]}"
16
+ exit!
17
+ end
18
+
19
+ def self.info(message)
20
+ puts " #{Paint['[i]', :bright, :blue]} #{Paint[message, :bright, :white]}"
21
+ exit!
69
22
  end
70
23
 
71
- class Attachment
72
- attr_writer :fallback
73
- attr_writer :text
74
- attr_writer :pretext
75
- attr_writer :color
76
- attr_writer :fields
77
-
78
- def initialize
79
-
80
- end
81
-
24
+ def self.warning(message)
25
+ puts " #{Paint['[!]', :bright, :orange]} #{Paint[message, :bright, :white]}"
26
+ exit!
82
27
  end
28
+
29
+ def self.fatal(message)
30
+ puts " #{Paint['[x]', :bright, :red]} #{Paint[message, :bright, :white]}"
31
+ exit!
32
+ end
33
+
83
34
  end
data/slackdraft.gemspec CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
9
9
  s.name = 'slackdraft'
10
10
  s.version = Slackdraft::VERSION
11
11
  s.date = '2015-02-14'
12
- s.summary = "Slack messaging with half the Kurt Russel"
13
- s.description = "Slack messaging with half the Kurt Russel"
12
+ s.summary = "Slack messaging with half the Kurt Russell"
13
+ s.description = "Slack messaging with half the Kurt Russell"
14
14
  s.authors = ["Mike Mackintosh"]
15
15
  s.email = 'm@zyp.io'
16
16
  s.homepage =
@@ -24,6 +24,9 @@ Gem::Specification.new do |s|
24
24
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
25
25
 
26
26
  s.add_dependency 'httparty'
27
+ s.add_dependency 'fattr'
28
+ s.add_dependency 'paint'
29
+ s.add_dependency 'methadone'
27
30
 
28
31
  s.add_development_dependency "bundler"
29
32
  s.add_development_dependency "rake"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slackdraft
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.6c
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Mackintosh
@@ -24,6 +24,48 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: fattr
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: paint
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: methadone
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: bundler
29
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +122,7 @@ dependencies:
80
122
  - - '>='
81
123
  - !ruby/object:Gem::Version
82
124
  version: '0'
83
- description: Slack messaging with half the Kurt Russel
125
+ description: Slack messaging with half the Kurt Russell
84
126
  email: m@zyp.io
85
127
  executables:
86
128
  - slackdraft
@@ -90,13 +132,18 @@ files:
90
132
  - .gitignore
91
133
  - .rock.yml
92
134
  - .rspec
135
+ - .travis.yml
93
136
  - Gemfile
94
137
  - Gemfile.lock
95
138
  - LICENSE.txt
96
139
  - README.md
97
140
  - Rakefile
98
141
  - bin/slackdraft
142
+ - examples/attachment.rb
99
143
  - lib/slackdraft.rb
144
+ - lib/slackdraft/attachment.rb
145
+ - lib/slackdraft/base.rb
146
+ - lib/slackdraft/message.rb
100
147
  - lib/slackdraft/version.rb
101
148
  - slackdraft.gemspec
102
149
  homepage: http://github.com/mikemackintosh/slackdraft
@@ -114,13 +161,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
161
  version: '0'
115
162
  required_rubygems_version: !ruby/object:Gem::Requirement
116
163
  requirements:
117
- - - '>'
164
+ - - '>='
118
165
  - !ruby/object:Gem::Version
119
- version: 1.3.1
166
+ version: '0'
120
167
  requirements: []
121
168
  rubyforge_project:
122
169
  rubygems_version: 2.0.14
123
170
  signing_key:
124
171
  specification_version: 4
125
- summary: Slack messaging with half the Kurt Russel
172
+ summary: Slack messaging with half the Kurt Russell
126
173
  test_files: []