slackly 0.0.1.pre.rc1 → 0.1.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: 1530ff7ddef013f0fc511960354b370729c44fa8
4
- data.tar.gz: 6e08be987ba67e7ee001b7039584b64983172b0b
3
+ metadata.gz: 15be28ce0b3e3609ed9d263a2fe2e559a4b07a35
4
+ data.tar.gz: 899521b635ab50f1209dda6d2117a8c8f8bea18d
5
5
  SHA512:
6
- metadata.gz: 0f2e84a5e392453b82b56cd2fcb15f146a8057ae2e0f49bb2523e8b52cede00d72693874f68cac085979265315b6f5d56f258b98b1e645e9b46a90d90b38cce5
7
- data.tar.gz: bfdc4b8eefaedfb5316bf6baf1685cc3a0cc8a261e085141cc437e122a931f43d16a3db81d13cbe0cb9db8277dffc12e5727461da6c04c3d4674db67eacc4d0e
6
+ metadata.gz: f10c0e603eb9e7c83976273218a0e04c820f1abe84e5b5b14128e31fc509f3781dc2a7763c053d0a3c16bc658b2ee850cac56742c9aed9c82ab446ac350521e9
7
+ data.tar.gz: a9968c77758428f96ae67d54d80b78ddfe54db948113466fcff3e42d63148b3e6685b8055a8333e4d0c1662951fb9bbe3681a953ff650d93776cb1c79805dfdb
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2010-2015 Pedro Carriço
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # Slackly
2
+
3
+ ## Description
4
+ Slackly is a simple and easy way to send messages to your Slack channels using the incoming webhooks integration.
5
+ You can use it directly in your code or through the command line.
6
+
7
+ ## Installation
8
+ ```
9
+ gem install slackly
10
+ ```
11
+
12
+ ## Usage
13
+ In your code:
14
+ ```
15
+ s = Slackly.new(webhook_url)
16
+ s.message(text: 'Hello from Slackly')
17
+ ```
18
+
19
+ Command line:
20
+ ```
21
+ slackly message 'Hello from Slackly!'
22
+ ```
23
+
24
+ ## Configuration
25
+ In your code:
26
+ ```
27
+ # these options will be the default client options and may be overriden by the message options
28
+ client_options = {
29
+ username: 'slackly',
30
+ icon_emoji: ':ghost:'
31
+ }
32
+ s = Slackly.new(webhook_url, client_options)
33
+
34
+ # these options will be sent for this message and will override any client options
35
+ message_options = {
36
+ text: 'Hello from Slackly',
37
+ channel: '#slackly'
38
+ }
39
+ s.message(message_options)
40
+ ```
41
+
42
+ The command line needs a JSON configuration file in order to configure the webhook, it defaults to './slackly.json'
43
+ but you can override it with the `-c` configuration.
44
+ The JSON configuration file must must have a `webhook_url` option in order for the command line to work:
45
+
46
+ ```
47
+ slackly message 'Hello from Slackly!' -c path_to/config.json
48
+ ```
49
+
50
+ Both the code version and JSON configuration file accept any configuration option provided by Slack as described in
51
+ [here](https://api.slack.com/incoming-webhooks).
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it (https://github.com/pedrocarrico/slackly/fork)
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create a new Pull Request
60
+
61
+ ## License
62
+ Slackly is released under the [MIT License](http://www.opensource.org/licenses/MIT).
data/bin/slackly CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'optparse'
3
- require_relative '../lib/slackly'
4
3
 
5
4
  options = {
6
5
  config: './slackly.json'
@@ -8,12 +7,12 @@ options = {
8
7
 
9
8
  option_parser = OptionParser.new do |opts|
10
9
  executable_name = File.basename($PROGRAM_NAME)
11
- opts.banner = "Usage: #{executable_name} send \"message\" [options]
10
+ opts.banner = "Usage: #{executable_name} message 'text' [options]
12
11
  Options:
13
12
  "
14
13
  opts.on('-c CONFIG',
15
14
  '--config path_to/config.json',
16
- "alernate JSON configuration file, defaults to ./slackly.json") do |config|
15
+ 'alernate JSON configuration file, defaults to ./slackly.json') do |config|
17
16
  options[:config] = config
18
17
  end
19
18
 
@@ -27,37 +26,39 @@ end
27
26
  begin
28
27
  option_parser.parse!
29
28
  if ARGV.empty?
30
- STDERR.puts "Error: you must supply an action"
29
+ STDERR.puts 'Error: you must supply an action'
31
30
  STDERR.puts option_parser.help
32
31
  exit 1
33
32
  end
34
33
 
35
34
  case ARGV[0]
36
- when 'send'
35
+ when 'message'
36
+ require_relative '../lib/slackly'
37
+
37
38
  if ARGV[1].nil?
38
- STDERR.puts "Error: you must supply a message"
39
+ STDERR.puts 'Error: you must supply a message'
39
40
  STDERR.puts option_parser.help
40
41
  exit 1
41
42
  end
42
43
 
43
44
  if !File.exist?(options[:config]) || !File.readable?(options[:config])
44
- STDERR.puts "Error: ensure you supply a valid and readable JSON config file"
45
+ STDERR.puts 'Error: ensure you supply a valid and readable JSON config file'
45
46
  STDERR.puts option_parser.help
46
47
  exit 1
47
48
  end
48
49
 
49
50
  begin
50
- slackly_config = JSON.parse(File.read(options[:config]))
51
- rescue JSON::ParserError => e
52
- STDERR.puts "Error: file \"#{options[:config]}\" is not a valid JSON file"
51
+ slackly_config = JSON.parse(File.read(options[:config]), symbolize_names: true)
52
+ rescue JSON::ParserError
53
+ STDERR.puts 'Error: file \"#{options[:config]}\" is not a valid JSON file'
53
54
  STDERR.puts option_parser.help
54
55
  exit 1
55
56
  end
56
57
 
57
- s = Slackly.new(slackly_config["webhook_url"])
58
- s.send_message(slackly_config.merge({text: ARGV[1]}))
58
+ s = Slackly.new(slackly_config[:webhook_url])
59
+ s.message(slackly_config.merge(text: ARGV[1]))
59
60
  when 'version'
60
- puts "Slackly version is #{Gem::Specification::load("#{File.dirname(__FILE__)}/../slackly.gemspec").version}"
61
+ puts "Slackly version is #{Gem::Specification.load("#{File.dirname(__FILE__)}/../slackly.gemspec").version}"
61
62
  else
62
63
  STDERR.puts option_parser
63
64
  end
@@ -1,3 +1,3 @@
1
1
  module Slackly
2
- VERSION = '0.0.1-rc1'.freeze
2
+ VERSION = '0.1.0'.freeze
3
3
  end
data/lib/slackly.rb CHANGED
@@ -1,30 +1,38 @@
1
- require "net/http"
2
- require "json"
1
+ require 'net/http'
2
+ require 'json'
3
3
 
4
4
  class Slackly
5
- attr_accessor :webhook_url
5
+ class InvalidMessageTextError < StandardError; end
6
+
7
+ attr_accessor :webhook_uri
6
8
  attr_accessor :client_options
7
9
 
8
10
  DEFAULT_OPTIONS = {
9
- 'username' => 'slackly',
10
- 'text' => 'Hello from slackly! Check me out at https://github.com/pedrocarrico/slackly!',
11
- 'icon_emoji' => ':sunglasses:',
12
- 'unfurl_links' => true
11
+ username: 'slackly',
12
+ icon_emoji: ':sunglasses:',
13
+ unfurl_links: true
13
14
  }.freeze
14
15
 
15
- def initialize(webhook_url, client_options={})
16
- @webhook_url = webhook_url
16
+ def initialize(webhook_url, client_options = {})
17
+ @webhook_uri = URI.parse(webhook_url)
17
18
  @client_options = DEFAULT_OPTIONS.merge(client_options)
18
19
  end
19
20
 
20
- def send_message(message_options={})
21
- uri = URI.parse(webhook_url)
22
- request = Net::HTTP::Post.new(uri.request_uri)
21
+ def message(message_options = {})
22
+ fail Slackly::InvalidMessageTextError, 'Please supply a valid message text' if message_options[:text].nil?
23
+
24
+ request = Net::HTTP::Post.new(webhook_uri.request_uri)
23
25
  request.body = "payload=#{client_options.merge(message_options).to_json}"
24
- Net::HTTP.start(uri.host, uri.port, use_ssl: ('https' == uri.scheme)) do |http|
26
+ Net::HTTP.start(webhook_uri.host, webhook_uri.port, use_ssl: webhook_uses_ssl?) do |http|
25
27
  http.request(request)
26
28
  end
27
- rescue => e
28
- STDERR.puts "Error while sending notification to Slack: #{e.message}"
29
+ rescue => exception
30
+ STDERR.puts "Error while sending message to Slack: #{exception.message}"
31
+ end
32
+
33
+ private
34
+
35
+ def webhook_uses_ssl?
36
+ 'https' == webhook_uri.scheme
29
37
  end
30
38
  end
data/slackly.gemspec CHANGED
@@ -3,12 +3,13 @@ require_relative 'lib/slackly/version'
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'slackly'
5
5
  s.version = Slackly::VERSION
6
- s.date = Time.now.strftime("%Y-%m-%d")
6
+ s.date = Time.now.strftime('%Y-%m-%d')
7
7
  s.summary = 'Slackly'
8
- s.description = 'Slackly is a simple and easy way to send messages to your Slack channes using the incoming webhooks integration.'
8
+ s.description = 'Slackly is a simple and easy way to send messages to your Slack channels using the incoming'\
9
+ ' webhooks integration.'
9
10
  s.authors = ['Pedro Carriço']
10
11
  s.email = 'pedro.carrico@gmail.com'
11
- s.files = ['lib/slackly.rb', 'lib/slackly/version.rb', 'slackly.gemspec']
12
+ s.files = ['lib/slackly.rb', 'lib/slackly/version.rb', 'slackly.gemspec', 'LICENSE', 'README.md']
12
13
  s.executables = 'slackly'
13
14
  s.homepage = 'http://www.github.com/pedrocarrico/slackly'
14
15
  s.license = 'MIT'
@@ -17,4 +18,5 @@ Gem::Specification.new do |s|
17
18
  s.add_runtime_dependency 'json', '~> 1.8', '>= 1.8.2'
18
19
 
19
20
  s.add_development_dependency 'bundler', '~> 1.8', '>= 1.8.2'
21
+ s.add_development_dependency 'rubocop', '~> 0.30.1', '0.30.1'
20
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slackly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre.rc1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Carriço
@@ -50,7 +50,27 @@ dependencies:
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
52
  version: 1.8.2
53
- description: Slackly is a simple and easy way to send messages to your Slack channes
53
+ - !ruby/object:Gem::Dependency
54
+ name: rubocop
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: 0.30.1
60
+ - - '='
61
+ - !ruby/object:Gem::Version
62
+ version: 0.30.1
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 0.30.1
70
+ - - '='
71
+ - !ruby/object:Gem::Version
72
+ version: 0.30.1
73
+ description: Slackly is a simple and easy way to send messages to your Slack channels
54
74
  using the incoming webhooks integration.
55
75
  email: pedro.carrico@gmail.com
56
76
  executables:
@@ -58,6 +78,8 @@ executables:
58
78
  extensions: []
59
79
  extra_rdoc_files: []
60
80
  files:
81
+ - LICENSE
82
+ - README.md
61
83
  - bin/slackly
62
84
  - lib/slackly.rb
63
85
  - lib/slackly/version.rb
@@ -77,9 +99,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
99
  version: '2.0'
78
100
  required_rubygems_version: !ruby/object:Gem::Requirement
79
101
  requirements:
80
- - - ">"
102
+ - - ">="
81
103
  - !ruby/object:Gem::Version
82
- version: 1.3.1
104
+ version: '0'
83
105
  requirements: []
84
106
  rubyforge_project:
85
107
  rubygems_version: 2.2.2