slack.rb 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 +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +20 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +8 -0
- data/lib/slack.rb +8 -0
- data/lib/slack/client.rb +49 -0
- data/lib/slack/connection.rb +45 -0
- data/lib/slack/error.rb +4 -0
- data/lib/slack/payload.rb +27 -0
- data/lib/slack/version.rb +3 -0
- data/script/bootstrap +5 -0
- data/script/cibuild +5 -0
- data/script/console +11 -0
- data/script/package +7 -0
- data/script/release +16 -0
- data/script/test +18 -0
- data/slack.rb.gemspec +23 -0
- data/spec/cassettes/Slack_Client/_channels/returns_all_channels.json +1 -0
- data/spec/cassettes/Slack_Client/_post_message/posts_a_message_to_one_channel.json +1 -0
- data/spec/cassettes/Slack_Client/_post_message/returns_channel_not_found_error.json +1 -0
- data/spec/slack/client_spec.rb +55 -0
- data/spec/spec_helper.rb +56 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: de59f6921fad561db1ecf951939344f0294fc875
|
4
|
+
data.tar.gz: b6f916b22010aa40bb315c39168ba241a70a5883
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 73e7f3ef1ec8b53d30cd8176aa04e9519e8e439ca27103d13e03a40b846ea4f14f3ea0f53cc21e78ee644ad5d105311368302bdf76d62f0333df5b824a8965a9
|
7
|
+
data.tar.gz: 4f5d870a6e18692cb61dbdc15e5f78b74248324abd4b7138249b26ca24cb22a55ccb0f7ba7c998fb31e5c3d5d919ea5fa61ab2b1fbd9a4aedc6f5fb658a16acc
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rake'
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem 'awesome_print', :require => 'ap'
|
7
|
+
gem 'hirb-unicode'
|
8
|
+
gem 'pry'
|
9
|
+
end
|
10
|
+
|
11
|
+
group :test do
|
12
|
+
gem 'coveralls', :require => false
|
13
|
+
gem 'json', '~> 1.8.1'
|
14
|
+
gem 'rspec', '~> 3.0.0.beta2'
|
15
|
+
gem 'simplecov', :require => false
|
16
|
+
gem 'vcr', '~> 2.4.0'
|
17
|
+
gem 'webmock', '>= 1.9.3'
|
18
|
+
end
|
19
|
+
|
20
|
+
gemspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Netflower Ltd. & Co. KG
|
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,38 @@
|
|
1
|
+
# Slack.rb
|
2
|
+
|
3
|
+
Ruby toolkit for working with the Slack API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'slack'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install slack
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Making requests
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# Provide authentication credentials
|
25
|
+
client = Slack::Client.new('team', 'api_token')
|
26
|
+
# Post a message
|
27
|
+
client.post_message("May the force be with you", "yoda-quotes")
|
28
|
+
# List all channels
|
29
|
+
client.channels
|
30
|
+
```
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it ( http://github.com/<my-github-username>/slack/fork )
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/slack.rb
ADDED
data/lib/slack/client.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require "json"
|
2
|
+
require "faraday"
|
3
|
+
|
4
|
+
module Slack
|
5
|
+
class Client
|
6
|
+
include Slack::Connection
|
7
|
+
|
8
|
+
def initialize(team, token, options = {})
|
9
|
+
@team = team
|
10
|
+
@token = token
|
11
|
+
@username = options[:username]
|
12
|
+
@channel = options[:channel]
|
13
|
+
|
14
|
+
validate_arguments
|
15
|
+
end
|
16
|
+
|
17
|
+
def post_message(text, channel)
|
18
|
+
payload = Slack::Payload.new(
|
19
|
+
text: text,
|
20
|
+
channel: channel,
|
21
|
+
username: @username,
|
22
|
+
token: @token
|
23
|
+
)
|
24
|
+
|
25
|
+
post('chat.postMessage', payload)
|
26
|
+
end
|
27
|
+
|
28
|
+
def channels
|
29
|
+
@channels ||= _channels
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def validate_arguments
|
35
|
+
raise ArgumentError, "Team name required" if @team.nil?
|
36
|
+
raise ArgumentError, "Token required" if @token.nil?
|
37
|
+
raise ArgumentError, "Invalid team name" unless valid_team_name?
|
38
|
+
end
|
39
|
+
|
40
|
+
def valid_team_name?
|
41
|
+
@team =~ /^[a-z\d\-]+$/ ? true : false
|
42
|
+
end
|
43
|
+
|
44
|
+
def _channels
|
45
|
+
response = get('channels.list')
|
46
|
+
response['channels']
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Slack
|
2
|
+
module Connection
|
3
|
+
def get(method)
|
4
|
+
response = connection.get method, { token: @token }
|
5
|
+
|
6
|
+
if response.success?
|
7
|
+
JSON.parse(response.body)
|
8
|
+
else
|
9
|
+
raise UnknownResponseCode, "Unexpected #{response.code}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def post(method, payload)
|
14
|
+
response = connection.post do |req|
|
15
|
+
req.url method, payload.to_hash
|
16
|
+
req.headers['Content-Type'] = 'application/json'
|
17
|
+
#req.body = JSON.dump(payload.to_hash)
|
18
|
+
end
|
19
|
+
|
20
|
+
handle_response(response)
|
21
|
+
end
|
22
|
+
|
23
|
+
def base_url
|
24
|
+
#"https://#{@team}.slack.com/api/"
|
25
|
+
"https://slack.com/api/"
|
26
|
+
end
|
27
|
+
|
28
|
+
def connection
|
29
|
+
Faraday.new(base_url) do |c|
|
30
|
+
c.use(Faraday::Request::UrlEncoded)
|
31
|
+
c.adapter(Faraday.default_adapter)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def handle_response(response)
|
36
|
+
body = JSON.parse(response.body)
|
37
|
+
|
38
|
+
if ["true", 1].include? body['ok']
|
39
|
+
true
|
40
|
+
else
|
41
|
+
raise Slack::Error.new(response.body)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/slack/error.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Slack
|
2
|
+
class Payload
|
3
|
+
attr_accessor :username, :channel, :text, :token
|
4
|
+
|
5
|
+
def initialize(options = {})
|
6
|
+
@username = options[:username]
|
7
|
+
@channel = options[:channel]
|
8
|
+
@text = options[:text]
|
9
|
+
@token = options[:token]
|
10
|
+
|
11
|
+
unless channel[0] =~ /^(#|@)/
|
12
|
+
@channel = "##{@channel}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_hash
|
17
|
+
hash = {
|
18
|
+
text: text,
|
19
|
+
username: username,
|
20
|
+
channel: channel,
|
21
|
+
token: token
|
22
|
+
}
|
23
|
+
|
24
|
+
hash.delete_if { |_,v| v.nil? }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/script/bootstrap
ADDED
data/script/console
ADDED
data/script/package
ADDED
data/script/release
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
# Usage: script/release
|
3
|
+
# Build the package, tag a commit, push it to origin, and then release the
|
4
|
+
# package publicly.
|
5
|
+
|
6
|
+
set -e
|
7
|
+
|
8
|
+
version="$(script/package | grep Version: | awk '{print $2}')"
|
9
|
+
[ -n "$version" ] || exit 1
|
10
|
+
|
11
|
+
echo $version
|
12
|
+
git commit --allow-empty -a -m "Release $version"
|
13
|
+
git tag "v$version"
|
14
|
+
git push origin
|
15
|
+
git push origin "v$version"
|
16
|
+
gem push pkg/*-${version}.gem
|
data/script/test
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
|
5
|
+
echo "===> Bundling..."
|
6
|
+
script/bootstrap --quiet
|
7
|
+
|
8
|
+
for testvar in TOKEN TEAM
|
9
|
+
do
|
10
|
+
slackvar="SLACK_TEST_${testvar}"
|
11
|
+
if [[ -z "${!slackvar}" ]]; then
|
12
|
+
echo "Please export ${slackvar}";
|
13
|
+
exit 1;
|
14
|
+
fi
|
15
|
+
done
|
16
|
+
|
17
|
+
echo "===> Running specs..."
|
18
|
+
bundle exec rake spec
|
data/slack.rb.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'slack/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "slack.rb"
|
8
|
+
spec.version = Slack::VERSION
|
9
|
+
spec.authors = ["Bastian Bartmann", "Mathias Bartmann"]
|
10
|
+
spec.email = ["bastian.bartmann@netflower.de", "mathias.bartmann@netflower.de"]
|
11
|
+
spec.summary = %q{Simple wrapper for the Slack API}
|
12
|
+
spec.description = %q{Ruby toolkit for working with the Slack API}
|
13
|
+
spec.homepage = "https://github.com/netflower/slack"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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_dependency "faraday", "~> 0.9.0"
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
23
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"http_interactions":[{"request":{"method":"get","uri":"https://slack.com/api/channels.list?token=<SLACK_TOKEN>","body":{"encoding":"US-ASCII","string":""},"headers":{"User-Agent":["Faraday v0.9.0"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"],"Accept":["*/*"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Access-Control-Allow-Origin":["*"],"Cache-Control":["private, no-cache, no-store, must-revalidate"],"Content-Type":["application/json; charset=utf-8"],"Date":["Thu, 01 May 2014 10:53:36 GMT"],"Expires":["Mon, 26 Jul 1997 05:00:00 GMT"],"Pragma":["no-cache"],"Server":["Apache"],"Vary":["Accept-Encoding"],"X-Accepted-Oauth-Scopes":["read"],"X-Oauth-Scopes":["identify,read,post,client"],"X-Xss-Protection":["0"],"Content-Length":["638"],"Connection":["keep-alive"]},"body":{"encoding":"UTF-8","string":"{\"ok\":true,\"channels\":[{\"id\":\"C028YP7A7\",\"name\":\"the-cashfloor-room\",\"created\":\"1397727847\",\"creator\":\"U028ZB8CG\",\"is_archived\":false,\"is_member\":true,\"num_members\":4,\"is_general\":false,\"topic\":{\"value\":\"\",\"creator\":\"\",\"last_set\":\"0\"},\"purpose\":{\"value\":\"\",\"creator\":\"\",\"last_set\":\"0\"}},{\"id\":\"C02979RU8\",\"name\":\"the-cat-room\",\"created\":\"1398335768\",\"creator\":\"U028ZCM22\",\"is_archived\":false,\"is_member\":true,\"num_members\":3,\"is_general\":false,\"topic\":{\"value\":\"\",\"creator\":\"\",\"last_set\":\"0\"},\"purpose\":{\"value\":\"\",\"creator\":\"\",\"last_set\":\"0\"}},{\"id\":\"C028ZB8CN\",\"name\":\"the-danger-room\",\"created\":\"1397727226\",\"creator\":\"U028ZB8CG\",\"is_archived\":false,\"is_member\":true,\"num_members\":6,\"is_general\":false,\"topic\":{\"value\":\"\",\"creator\":\"\",\"last_set\":\"0\"},\"purpose\":{\"value\":\"A place for non-work banter, links, articles of interest, humor or anything else which you'd like concentrated in some place other than work-related channels.\",\"creator\":\"\",\"last_set\":\"0\"}},{\"id\":\"C028ZBLNN\",\"name\":\"the-github-channel\",\"created\":\"1397728177\",\"creator\":\"U028YNXGR\",\"is_archived\":false,\"is_member\":false,\"num_members\":2,\"is_general\":false,\"topic\":{\"value\":\"\",\"creator\":\"\",\"last_set\":\"0\"},\"purpose\":{\"value\":\"\",\"creator\":\"\",\"last_set\":\"0\"}},{\"id\":\"C029DP011\",\"name\":\"the-hubot-room\",\"created\":\"1398843936\",\"creator\":\"U028ZB8CG\",\"is_archived\":false,\"is_member\":true,\"num_members\":2,\"is_general\":false,\"topic\":{\"value\":\"\",\"creator\":\"\",\"last_set\":\"0\"},\"purpose\":{\"value\":\"\",\"creator\":\"\",\"last_set\":\"0\"}},{\"id\":\"C028ZBJBJ\",\"name\":\"the-<SLACK_TEAM>-room\",\"created\":\"1397727940\",\"creator\":\"U028ZB8CG\",\"is_archived\":false,\"is_member\":true,\"num_members\":4,\"is_general\":false,\"topic\":{\"value\":\"\",\"creator\":\"\",\"last_set\":\"0\"},\"purpose\":{\"value\":\"\",\"creator\":\"\",\"last_set\":\"0\"}},{\"id\":\"C028YQ38F\",\"name\":\"the-papertrail-room\",\"created\":\"1397729261\",\"creator\":\"U028ZB8CG\",\"is_archived\":false,\"is_member\":true,\"num_members\":2,\"is_general\":false,\"topic\":{\"value\":\"\",\"creator\":\"\",\"last_set\":\"0\"},\"purpose\":{\"value\":\"\",\"creator\":\"\",\"last_set\":\"0\"}},{\"id\":\"C028ZB8CL\",\"name\":\"the-serious-room\",\"created\":\"1397727226\",\"creator\":\"U028ZB8CG\",\"is_archived\":false,\"is_member\":true,\"num_members\":6,\"is_general\":true,\"topic\":{\"value\":\"\",\"creator\":\"\",\"last_set\":\"0\"},\"purpose\":{\"value\":\"This channel is for team-wide communication and announcements. All team members are in this channel.\",\"creator\":\"\",\"last_set\":\"0\"}},{\"id\":\"C0296KR2Z\",\"name\":\"the-sharepoint-room\",\"created\":\"1398341726\",\"creator\":\"U0296FHNR\",\"is_archived\":false,\"is_member\":true,\"num_members\":3,\"is_general\":false,\"topic\":{\"value\":\"\",\"creator\":\"\",\"last_set\":\"0\"},\"purpose\":{\"value\":\"\",\"creator\":\"\",\"last_set\":\"0\"}},{\"id\":\"C0297DTL6\",\"name\":\"website-redesign-room\",\"created\":\"1398344050\",\"creator\":\"U028ZCM22\",\"is_archived\":false,\"is_member\":true,\"num_members\":6,\"is_general\":false,\"topic\":{\"value\":\"\",\"creator\":\"\",\"last_set\":\"0\"},\"purpose\":{\"value\":\"\",\"creator\":\"\",\"last_set\":\"0\"}},{\"id\":\"C029G8WDA\",\"name\":\"yoda-quotes\",\"created\":\"1398939627\",\"creator\":\"U028ZB8CG\",\"is_archived\":false,\"is_member\":true,\"num_members\":1,\"is_general\":false,\"topic\":{\"value\":\"\",\"creator\":\"\",\"last_set\":\"0\"},\"purpose\":{\"value\":\"\",\"creator\":\"\",\"last_set\":\"0\"}}]}"},"http_version":null},"recorded_at":"Thu, 01 May 2014 10:53:37 GMT"}],"recorded_with":"VCR 2.4.0"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"http_interactions":[{"request":{"method":"post","uri":"https://slack.com/api/chat.postMessage?channel=%23yoda-quotes&text=May%20the%20force%20be%20with%20you&token=<SLACK_TOKEN>","body":{"encoding":"UTF-8","string":""},"headers":{"User-Agent":["Faraday v0.9.0"],"Content-Type":["application/json"],"Content-Length":["0"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"],"Accept":["*/*"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Access-Control-Allow-Origin":["*"],"Cache-Control":["private, no-cache, no-store, must-revalidate"],"Content-Type":["application/json; charset=utf-8"],"Date":["Thu, 01 May 2014 10:53:36 GMT"],"Expires":["Mon, 26 Jul 1997 05:00:00 GMT"],"Pragma":["no-cache"],"Server":["Apache"],"Vary":["Accept-Encoding"],"X-Accepted-Oauth-Scopes":["post"],"X-Oauth-Scopes":["identify,read,post,client"],"X-Xss-Protection":["0"],"Content-Length":["56"],"Connection":["keep-alive"]},"body":{"encoding":"UTF-8","string":"{\"ok\":1,\"timestamp\":\"1398941616000006\"}"},"http_version":null},"recorded_at":"Thu, 01 May 2014 10:53:38 GMT"}],"recorded_with":"VCR 2.4.0"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"http_interactions":[{"request":{"method":"post","uri":"https://slack.com/api/chat.postMessage?channel=%23channel-name&text=May%20the%20force%20be%20with%20you&token=<SLACK_TOKEN>","body":{"encoding":"UTF-8","string":""},"headers":{"User-Agent":["Faraday v0.9.0"],"Content-Type":["application/json"],"Content-Length":["0"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"],"Accept":["*/*"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Access-Control-Allow-Origin":["*"],"Cache-Control":["private, no-cache, no-store, must-revalidate"],"Content-Type":["application/json; charset=utf-8"],"Date":["Thu, 01 May 2014 10:57:52 GMT"],"Expires":["Mon, 26 Jul 1997 05:00:00 GMT"],"Pragma":["no-cache"],"Server":["Apache"],"Vary":["Accept-Encoding"],"X-Accepted-Oauth-Scopes":["post"],"X-Oauth-Scopes":["identify,read,post,client"],"X-Xss-Protection":["0"],"Content-Length":["60"],"Connection":["keep-alive"]},"body":{"encoding":"UTF-8","string":"{\"ok\":false,\"error\":\"channel_not_found\"}"},"http_version":null},"recorded_at":"Thu, 01 May 2014 10:57:53 GMT"}],"recorded_with":"VCR 2.4.0"}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Slack::Client do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = auth_client
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#initialize" do
|
10
|
+
it "requires team name" do
|
11
|
+
expect { described_class.new(nil, nil) }.
|
12
|
+
to raise_error ArgumentError, "Team name required"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "requires token" do
|
16
|
+
expect { described_class.new("foobar", nil) }.
|
17
|
+
to raise_error ArgumentError, "Token required"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "raises error on invalid team name" do
|
21
|
+
names = ["foo bar", "foo $bar", "foo.bar"]
|
22
|
+
|
23
|
+
names.each do |name|
|
24
|
+
expect { described_class.new(name, "token") }.
|
25
|
+
to raise_error "Invalid team name"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#post_message", :vcr do
|
31
|
+
it "posts a message to one channel" do
|
32
|
+
result = @client.post_message("May the force be with you", "yoda-quotes")
|
33
|
+
expect(result).to be true
|
34
|
+
params = {text: "May the force be with you", channel: "#yoda-quotes", token: test_slack_token}
|
35
|
+
assert_requested :post, slack_url_with_params("/chat.postMessage", params)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns channel not found error" do
|
39
|
+
expect{
|
40
|
+
@client.post_message("May the force be with you", "channel-name")
|
41
|
+
}.to raise_error(Slack::Error)
|
42
|
+
|
43
|
+
params = {text: "May the force be with you", channel: "#channel-name", token: test_slack_token}
|
44
|
+
assert_requested :post, slack_url_with_params("/chat.postMessage", params)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#channels", :vcr do
|
49
|
+
it "returns all channels" do
|
50
|
+
channels = @client.channels
|
51
|
+
expect(channels).to be_kind_of Array
|
52
|
+
assert_requested :get, auth_slack_url("/channels.list")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'slack'
|
2
|
+
require 'rspec'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
|
5
|
+
WebMock.disable_net_connect!(:allow => 'coveralls.io')
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.raise_errors_for_deprecations!
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'vcr'
|
12
|
+
VCR.configure do |c|
|
13
|
+
c.configure_rspec_metadata!
|
14
|
+
c.filter_sensitive_data("<SLACK_TEAM>") do
|
15
|
+
ENV['SLACK_TEST_TEAM']
|
16
|
+
end
|
17
|
+
c.filter_sensitive_data("<SLACK_TOKEN>") do
|
18
|
+
ENV['SLACK_TEST_TOKEN']
|
19
|
+
end
|
20
|
+
c.default_cassette_options = {
|
21
|
+
:serialize_with => :json,
|
22
|
+
:preserve_exact_body_bytes => false,
|
23
|
+
:decode_compressed_response => true,
|
24
|
+
:record => ENV['TRAVIS'] ? :none : :once
|
25
|
+
}
|
26
|
+
c.cassette_library_dir = 'spec/cassettes'
|
27
|
+
c.hook_into :webmock
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_slack_team
|
31
|
+
ENV.fetch 'SLACK_TEST_TEAM', 'x' * 12
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_slack_token
|
35
|
+
ENV.fetch 'SLACK_TEST_TOKEN', 'x' * 45
|
36
|
+
end
|
37
|
+
|
38
|
+
def slack_url(path)
|
39
|
+
"https://slack.com/api#{path}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def slack_url_with_params(path, params=nil)
|
43
|
+
"https://slack.com/api#{path}?#{parameterize(params)}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def auth_slack_url(path)
|
47
|
+
"https://slack.com/api#{path}?token=#{test_slack_token}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def auth_client
|
51
|
+
Slack::Client.new(ENV.fetch('SLACK_TEST_TEAM'), ENV.fetch('SLACK_TEST_TOKEN'))
|
52
|
+
end
|
53
|
+
|
54
|
+
def parameterize(params)
|
55
|
+
URI.escape(params.collect{|k,v| "#{k}=#{v}"}.join('&'))
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slack.rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bastian Bartmann
|
8
|
+
- Mathias Bartmann
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-05-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 0.9.0
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 0.9.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.5'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.5'
|
42
|
+
description: Ruby toolkit for working with the Slack API
|
43
|
+
email:
|
44
|
+
- bastian.bartmann@netflower.de
|
45
|
+
- mathias.bartmann@netflower.de
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- .gitignore
|
51
|
+
- .rspec
|
52
|
+
- Gemfile
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- lib/slack.rb
|
57
|
+
- lib/slack/client.rb
|
58
|
+
- lib/slack/connection.rb
|
59
|
+
- lib/slack/error.rb
|
60
|
+
- lib/slack/payload.rb
|
61
|
+
- lib/slack/version.rb
|
62
|
+
- script/bootstrap
|
63
|
+
- script/cibuild
|
64
|
+
- script/console
|
65
|
+
- script/package
|
66
|
+
- script/release
|
67
|
+
- script/test
|
68
|
+
- slack.rb.gemspec
|
69
|
+
- spec/cassettes/Slack_Client/_channels/returns_all_channels.json
|
70
|
+
- spec/cassettes/Slack_Client/_post_message/posts_a_message_to_one_channel.json
|
71
|
+
- spec/cassettes/Slack_Client/_post_message/returns_channel_not_found_error.json
|
72
|
+
- spec/slack/client_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
homepage: https://github.com/netflower/slack
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.0.14
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Simple wrapper for the Slack API
|
98
|
+
test_files:
|
99
|
+
- spec/cassettes/Slack_Client/_channels/returns_all_channels.json
|
100
|
+
- spec/cassettes/Slack_Client/_post_message/posts_a_message_to_one_channel.json
|
101
|
+
- spec/cassettes/Slack_Client/_post_message/returns_channel_not_found_error.json
|
102
|
+
- spec/slack/client_spec.rb
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
has_rdoc:
|