slackit 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3734e3042dec6c637d1f79d9ec03b40de59af16e35c764ef36727b9d26d72ae5
4
- data.tar.gz: ea202040a7466fa8ffcf97b1bb168229c6bd443242aae2122472ce1841ea8081
3
+ metadata.gz: dd46600c8819cc9d3ae4c44b2c94f7f1904436da707d3177872536e3ffe23d33
4
+ data.tar.gz: 72a88c29045497006e754242478125959c4003f17cc7360a93aba624f5d0293f
5
5
  SHA512:
6
- metadata.gz: e3c8ca7bfcf4a1da6ef92b0e01ad7c9034d079823dabbd8b5a9127b21ddb2180be4ab815b45536c90855816bf505231b9de5b168f52dc54233ea76dc476f85ca
7
- data.tar.gz: 339844366ac2722d53fb1f51a4e258e4f3354be03e9294495be50ffb22d16f5f34b4698ba41948ab1e6983c155c1e327ffc8dbf8cec30f6cfa793d77dbfa6862
6
+ metadata.gz: 66d6c556a9958eb0eccd414f2d1fa03622235b055aa8e4af289808fbbd937f8e75d0f45639df83b70fb4cb6609e1215172157eafd3a7f060548083ed71694688
7
+ data.tar.gz: 186f2310fc4b6a7ccf2d2660b6cc7338abbe676c79f066055e75e877cd1ac34220e5b346738a70bad3015a271223412a013fc1c04cf445eb715e8b9467f5735f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 1.1.0 (January 22, 2019)
2
+
3
+ IMPROVEMENTS:
4
+
5
+ * Made the parameter list a map to make it easier to pass different combinations of options. ([@TGWolf][])
6
+ * Added additional testing to ensure a new class instance is created. ([@TGWolf][])
7
+ * Specifying no channel will now send the message to '#general'. ([@TGWolf][])
8
+ * Added better error handling to the CLI tool. ([@TGWolf][])
9
+
1
10
  ## 1.0.1 (January 22, 2019)
2
11
 
3
12
  BUG FIX:
data/README.md CHANGED
@@ -28,12 +28,31 @@ Or install it yourself as:
28
28
 
29
29
  ## Usage
30
30
 
31
- Using this Gem is VERY simply, everything apart from the webhook and the message are optional.
31
+ ```ruby
32
+ require "slackit"
33
+ ```
34
+
35
+ Initialize client:
36
+
37
+ ```ruby
38
+ client = Slackit.new(webhook_url: "slack webhook url")
39
+ ```
40
+
41
+ Initialize with options:
32
42
 
33
43
  ```ruby
34
- s = Slackit.new(webhook, channel, username, emoji)
44
+ client = SlackNotify::Client.new(
45
+ webhook_url: "slack webhook url",
46
+ channel: "#development",
47
+ username: "mybot",
48
+ icon_emoji: ":shipit:",
49
+ )
50
+ ```
35
51
 
36
- s.send(message)
52
+ Initialize via shorthand method:
53
+
54
+ ```Ruby
55
+ client = Slackit.new(options)
37
56
  ```
38
57
 
39
58
  ### Command Line Usage
@@ -42,9 +61,9 @@ Using this Gem is VERY simply, everything apart from the webhook and the message
42
61
  Usage: slackit
43
62
  -h, --help Display this screen
44
63
  -c, --channel string The channel to send the message to
45
- -e, --emoji string The emoji to use [default: :wolf:]
64
+ -i, --icon-emoji string The emoji to use as the channel icon [default: :wolf:]
46
65
  -m, --message string The message to send
47
- -w, --webhook string The slack incoming webhook to use
66
+ -w, --webhook-url string The slack incoming webhook url to use
48
67
  -u, --username string The username to send as [default: slackit]
49
68
  ```
50
69
 
@@ -56,6 +75,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
56
75
 
57
76
  ## Testing
58
77
 
78
+ For local testing make sure that you run `bundle exec rspec spec` and then `rake install` to install the gem locally.
79
+
59
80
  ## Contributing
60
81
 
61
82
  Bug reports and pull requests are welcome on GitHub at https://github.com/AntiPhotonltd/slackit. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
data/exe/slackit CHANGED
@@ -10,9 +10,13 @@ require 'slackit'
10
10
  # -------------------------------------------------------------------------------- #
11
11
 
12
12
  def send_message_to_slack(options)
13
- s = Slackit.new(options[:webhook], options[:channel], options[:username], options[:emoji])
14
-
15
- s.send(options[:message])
13
+ begin
14
+ s = Slackit.new(webhook_url: options[:webhook_url], channel: options[:channel], username: options[:username], icon_emoji: options[:icon_emoji])
15
+ s.send(options[:message])
16
+ rescue ArgumentError
17
+ puts "You must specify a webhook_url"
18
+ exit(1)
19
+ end
16
20
  end
17
21
 
18
22
  # -------------------------------------------------------------------------------- #
@@ -27,7 +31,7 @@ end
27
31
  def process_arguments
28
32
  options = {}
29
33
  # Enforce the presence of
30
- mandatory = %I[webhook message]
34
+ mandatory = %I[webhook_url message]
31
35
 
32
36
  optparse = OptionParser.new do |opts|
33
37
  opts.banner = "Usage: #{$PROGRAM_NAME}"
@@ -40,16 +44,16 @@ def process_arguments
40
44
  options[:channel] = channel
41
45
  end
42
46
 
43
- opts.on('-e', '--emoji string', 'The emoji to use [default: :wolf:]') do |emoji|
44
- options[:emoji] = emoji
47
+ opts.on('-i', '--icon-emoji string', 'The emoji to use for the channel icon [default: :wolf:]') do |icon_emoji|
48
+ options[:icon_emoji] = icon_emoji
45
49
  end
46
50
 
47
51
  opts.on('-m', '--message string', 'The message to send') do |message|
48
52
  options[:message] = message
49
53
  end
50
54
 
51
- opts.on('-w', '--webhook string', 'The slack incoming webhook to use') do |webhook|
52
- options[:webhook] = webhook
55
+ opts.on('-w', '--webhook-url string', 'The slack incoming webhook url to use') do |webhook_url|
56
+ options[:webhook_url] = webhook_url
53
57
  end
54
58
 
55
59
  opts.on('-u', '--username string', 'The username to send as [default: slackit]') do |username|
@@ -1,3 +1,3 @@
1
1
  class Slackit
2
- VERSION = '1.0.1'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
data/lib/slackit.rb CHANGED
@@ -5,11 +5,13 @@ require 'httparty'
5
5
  # To follow
6
6
  #
7
7
  class Slackit
8
- def initialize(webhook_url, channel = false, username = 'SlackIT', icon_emoji = ':wolf:')
9
- @webhook_url = webhook_url
10
- @channel = channel
11
- @username = username
12
- @icon_emoji = icon_emoji
8
+ def initialize(options = {})
9
+ @webhook_url = options[:webhook_url]
10
+ @username = options[:username]
11
+ @channel = options[:channel]
12
+ @icon_emoji = options[:icon_emoji]
13
+
14
+ raise ArgumentError.new('Webhook URL required') if @webhook_url.nil?
13
15
  end
14
16
 
15
17
  # sends a notification
@@ -22,7 +24,7 @@ class Slackit
22
24
  body = { 'text': text, 'icon_emoji': @icon_emoji, username: @username }
23
25
 
24
26
  # add the channel if there is one otherwise the default channel
25
- body['channel'] = @channel if @channel
27
+ body['channel'] = @channel || '#general'
26
28
 
27
29
  begin
28
30
  response = HTTParty.post(@webhook_url, body: body.to_json, headers: headers)
data/spec/slackit_spec.rb CHANGED
@@ -4,4 +4,8 @@ RSpec.describe Slackit do
4
4
  it 'has a version number' do
5
5
  expect(Slackit::VERSION).not_to be nil
6
6
  end
7
+
8
+ it 'returns a client instance' do
9
+ expect(Slackit.new(webhook_url: 'someurl')).to be_a Slackit
10
+ end
7
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slackit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Gurney aka Wolf