slackly 0.0.1.pre.rc1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1530ff7ddef013f0fc511960354b370729c44fa8
4
+ data.tar.gz: 6e08be987ba67e7ee001b7039584b64983172b0b
5
+ SHA512:
6
+ metadata.gz: 0f2e84a5e392453b82b56cd2fcb15f146a8057ae2e0f49bb2523e8b52cede00d72693874f68cac085979265315b6f5d56f258b98b1e645e9b46a90d90b38cce5
7
+ data.tar.gz: bfdc4b8eefaedfb5316bf6baf1685cc3a0cc8a261e085141cc437e122a931f43d16a3db81d13cbe0cb9db8277dffc12e5727461da6c04c3d4674db67eacc4d0e
data/bin/slackly ADDED
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require_relative '../lib/slackly'
4
+
5
+ options = {
6
+ config: './slackly.json'
7
+ }
8
+
9
+ option_parser = OptionParser.new do |opts|
10
+ executable_name = File.basename($PROGRAM_NAME)
11
+ opts.banner = "Usage: #{executable_name} send \"message\" [options]
12
+ Options:
13
+ "
14
+ opts.on('-c CONFIG',
15
+ '--config path_to/config.json',
16
+ "alernate JSON configuration file, defaults to ./slackly.json") do |config|
17
+ options[:config] = config
18
+ end
19
+
20
+ opts.on('-v',
21
+ '--version',
22
+ 'Display Slackly version') do
23
+ ARGV[0] = 'version'
24
+ end
25
+ end
26
+
27
+ begin
28
+ option_parser.parse!
29
+ if ARGV.empty?
30
+ STDERR.puts "Error: you must supply an action"
31
+ STDERR.puts option_parser.help
32
+ exit 1
33
+ end
34
+
35
+ case ARGV[0]
36
+ when 'send'
37
+ if ARGV[1].nil?
38
+ STDERR.puts "Error: you must supply a message"
39
+ STDERR.puts option_parser.help
40
+ exit 1
41
+ end
42
+
43
+ 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 option_parser.help
46
+ exit 1
47
+ end
48
+
49
+ 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"
53
+ STDERR.puts option_parser.help
54
+ exit 1
55
+ end
56
+
57
+ s = Slackly.new(slackly_config["webhook_url"])
58
+ s.send_message(slackly_config.merge({text: ARGV[1]}))
59
+ when 'version'
60
+ puts "Slackly version is #{Gem::Specification::load("#{File.dirname(__FILE__)}/../slackly.gemspec").version}"
61
+ else
62
+ STDERR.puts option_parser
63
+ end
64
+ rescue OptionParser::InvalidArgument => ex
65
+ STDERR.puts ex.message
66
+ STDERR.puts option_parser
67
+ end
@@ -0,0 +1,3 @@
1
+ module Slackly
2
+ VERSION = '0.0.1-rc1'.freeze
3
+ end
data/lib/slackly.rb ADDED
@@ -0,0 +1,30 @@
1
+ require "net/http"
2
+ require "json"
3
+
4
+ class Slackly
5
+ attr_accessor :webhook_url
6
+ attr_accessor :client_options
7
+
8
+ 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
13
+ }.freeze
14
+
15
+ def initialize(webhook_url, client_options={})
16
+ @webhook_url = webhook_url
17
+ @client_options = DEFAULT_OPTIONS.merge(client_options)
18
+ end
19
+
20
+ def send_message(message_options={})
21
+ uri = URI.parse(webhook_url)
22
+ request = Net::HTTP::Post.new(uri.request_uri)
23
+ 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|
25
+ http.request(request)
26
+ end
27
+ rescue => e
28
+ STDERR.puts "Error while sending notification to Slack: #{e.message}"
29
+ end
30
+ end
data/slackly.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ require_relative 'lib/slackly/version'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'slackly'
5
+ s.version = Slackly::VERSION
6
+ s.date = Time.now.strftime("%Y-%m-%d")
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.'
9
+ s.authors = ['Pedro Carriço']
10
+ s.email = 'pedro.carrico@gmail.com'
11
+ s.files = ['lib/slackly.rb', 'lib/slackly/version.rb', 'slackly.gemspec']
12
+ s.executables = 'slackly'
13
+ s.homepage = 'http://www.github.com/pedrocarrico/slackly'
14
+ s.license = 'MIT'
15
+ s.required_ruby_version = '>= 2.0'
16
+
17
+ s.add_runtime_dependency 'json', '~> 1.8', '>= 1.8.2'
18
+
19
+ s.add_development_dependency 'bundler', '~> 1.8', '>= 1.8.2'
20
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slackly
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre.rc1
5
+ platform: ruby
6
+ authors:
7
+ - Pedro Carriço
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.8.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.8'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.8.2
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.8'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.8.2
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.8'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.8.2
53
+ description: Slackly is a simple and easy way to send messages to your Slack channes
54
+ using the incoming webhooks integration.
55
+ email: pedro.carrico@gmail.com
56
+ executables:
57
+ - slackly
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - bin/slackly
62
+ - lib/slackly.rb
63
+ - lib/slackly/version.rb
64
+ - slackly.gemspec
65
+ homepage: http://www.github.com/pedrocarrico/slackly
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '2.0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.3.1
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.2.2
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Slackly
89
+ test_files: []