slack-post 0.0.1
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 +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +34 -0
- data/Rakefile +1 -0
- data/lib/slack/post/version.rb +5 -0
- data/lib/slack/post.rb +74 -0
- data/slack-post.gemspec +24 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YTVjZjRiYjU4ODg3OTRkMmU5NzlmNjQyMzA5ZGNiNmE1OTJhODhhMw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZWE1MmFiOWUzNzg5ZTAwODU1NTA0ZTI0OTUzNGNkN2U1YjIyODkwMA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZTU4MzU2NDUzNmQ0NDQ5MGMxNzE4YjNhZjMzNDQxZmEzODc0NDg4MDg0Mzlj
|
10
|
+
ZTU3YmEwMjQyYjJiMTk5ZDEzNmM0Y2Y3NDMxNzgzMGUzNWM0MjJkOGM2MDJj
|
11
|
+
NWZjYzhjZDQ0MmEwMDhjNWUyZTAwN2NjYTIwNjMxZjc1Mzk4MjA=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MGU2Zjc2M2M2NTI3MmRiN2IwZjliMjBmNDMyMDQ1NGFlZmYwM2I3NWI4NGM5
|
14
|
+
ZWU0YmNjZTg3NzcwYTI3Mzg4YmY2YWMxZjUyZjEzOTI5NzVlY2M1YzU3M2Nj
|
15
|
+
OTFmYmMxNWMxMzk5NDg2YTRjYTI4NTU0NGJmYThiOTEzMGU3Mjc=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 John Bragg
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Slack::Post
|
2
|
+
|
3
|
+
Just a simple thing to post messages to your [Slack](http://slack.com) rooms.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'slack-post', git: "git@github.com:CozyCo/slack-post.git", branch: "release"
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle install
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
Example:
|
18
|
+
```ruby
|
19
|
+
require 'slack/post'
|
20
|
+
Slack::Post.configure(
|
21
|
+
subdomain: 'myslack',
|
22
|
+
token: 'abc1234567890def',
|
23
|
+
username: 'roboto, mr.'
|
24
|
+
)
|
25
|
+
Slack::Post.post "Domo arigato.", '#general'
|
26
|
+
```
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
1. Fork it
|
31
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
32
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
33
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
34
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/slack/post.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require "slack/post/version"
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
require 'uri'
|
5
|
+
require 'yajl'
|
6
|
+
|
7
|
+
module Slack
|
8
|
+
module Post
|
9
|
+
|
10
|
+
DefaultOpts = {
|
11
|
+
channel: '#general'
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
def self.post(message,chan=nil)
|
15
|
+
raise "You need to call Slack::Post.configure before trying to send messages." unless configured?(chan.nil?)
|
16
|
+
pkt = {
|
17
|
+
channel: chan || config[:channel],
|
18
|
+
text: message,
|
19
|
+
}
|
20
|
+
if config[:username]
|
21
|
+
pkt[:username] = config[:username]
|
22
|
+
end
|
23
|
+
uri = URI.parse(post_url)
|
24
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
25
|
+
http.use_ssl = true
|
26
|
+
http.ssl_version = :SSLv3
|
27
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
28
|
+
req = Net::HTTP::Post.new(uri.request_uri)
|
29
|
+
req.body = Yajl::Encoder.encode(pkt)
|
30
|
+
req["Content-Type"] = 'application/json'
|
31
|
+
resp = http.request(req)
|
32
|
+
case resp
|
33
|
+
when Net::HTTPSuccess
|
34
|
+
return true
|
35
|
+
else
|
36
|
+
raise "There was an error while trying to post. Error was: #{resp.body}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.post_url
|
41
|
+
"https://#{config[:subdomain]}.slack.com/services/hooks/incoming-webhook?token=#{config[:token]}"
|
42
|
+
end
|
43
|
+
|
44
|
+
NecessaryConfigParams = [:subdomain,:token].freeze
|
45
|
+
|
46
|
+
def self.configured?(needs_channel=true)
|
47
|
+
return false if needs_channel and !config[:channel]
|
48
|
+
NecessaryConfigParams.all? do |parm|
|
49
|
+
config[parm]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.config
|
54
|
+
@config ||= DefaultOpts
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.configure(opts)
|
58
|
+
@config = config.merge(prune(opts))
|
59
|
+
end
|
60
|
+
|
61
|
+
KnownConfigParams = [:username,:channel,:subdomain,:token].freeze
|
62
|
+
|
63
|
+
def self.prune(opts)
|
64
|
+
opts.inject({}) do |acc,(k,v)|
|
65
|
+
k = k.to_sym
|
66
|
+
if KnownConfigParams.include?(k)
|
67
|
+
acc[k] = v
|
68
|
+
end
|
69
|
+
acc
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
data/slack-post.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'slack/post/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "slack-post"
|
8
|
+
spec.version = Slack::Post::VERSION
|
9
|
+
spec.authors = ["John Bragg"]
|
10
|
+
spec.email = ["remotezygote@gmail.com"]
|
11
|
+
spec.description = %q{Pretty simple really. It posts to slack fer ya.}
|
12
|
+
spec.summary = %q{It's for posting messages to your slack.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_dependency 'yajl-ruby'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slack-post
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Bragg
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: yajl-ruby
|
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
|
+
description: Pretty simple really. It posts to slack fer ya.
|
56
|
+
email:
|
57
|
+
- remotezygote@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/slack/post.rb
|
68
|
+
- lib/slack/post/version.rb
|
69
|
+
- slack-post.gemspec
|
70
|
+
homepage: ''
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.0.3
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: It's for posting messages to your slack.
|
94
|
+
test_files: []
|