slackbot 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in slackbot.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,18 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ addressable (2.3.2)
5
+ crack (0.3.1)
6
+ json (1.8.0)
7
+ minitest (5.0.8)
8
+ webmock (1.8.7)
9
+ addressable (>= 2.2.7)
10
+ crack (>= 0.1.7)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ json (~> 1.8.0)
17
+ minitest (~> 5.0.8)
18
+ webmock (~> 1.8.7)
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 ecin
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 ADDED
@@ -0,0 +1 @@
1
+ Slackbot, the laziest bot of them all.
data/lib/slackbot.rb ADDED
@@ -0,0 +1,31 @@
1
+ require "json"
2
+ require "net/https"
3
+ require "uri"
4
+
5
+ class Slackbot
6
+
7
+ REMOTE_ENDPOINT = "https://%s.slack.com"
8
+ REMOTE_PATH = "/services/hooks/slackbot?token=%s&channel=%s"
9
+
10
+ def initialize(subdomain, token)
11
+ @endpoint = URI(REMOTE_ENDPOINT % URI.encode(subdomain))
12
+ @token = token
13
+ end
14
+
15
+ def send(channel, message)
16
+ http = Net::HTTP.new(@endpoint.host, @endpoint.port)
17
+ http.use_ssl = true
18
+
19
+ request = Net::HTTP::Post.new(path(channel))
20
+ request.body = message
21
+
22
+ http.request(request)
23
+ end
24
+
25
+ protected
26
+
27
+ def path(channel)
28
+ REMOTE_PATH % [@token, channel].map { |param| URI.encode(param) }
29
+ end
30
+
31
+ end
data/slackbot.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "slackbot"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["ecin"]
9
+ spec.email = ["ecin@copypastel.com"]
10
+ spec.description = "Tiny library to send messages to the Slack platform."
11
+ spec.summary = "The laziest bot around."
12
+ spec.homepage = "https://github.com/typekit/slackbot"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "json", "~> 1.8.0"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "minitest", "~> 5.0.8"
24
+ spec.add_development_dependency "webmock", "~> 1.8.7"
25
+ end
@@ -0,0 +1,30 @@
1
+ require "minitest/autorun"
2
+ require "minitest/pride"
3
+ require "webmock/minitest"
4
+
5
+ require "slackbot"
6
+
7
+ describe Slackbot do
8
+
9
+ include WebMock::API
10
+
11
+ before do
12
+ @subdomain = "typekit"
13
+ @token = "hippopotamus"
14
+
15
+ @slack = Slackbot.new(@subdomain, @token)
16
+ end
17
+
18
+ it "posts a message to the correct channel" do
19
+ channel = "#dev"
20
+ message = "Hello from slack.rb"
21
+ endpoint = (Slackbot::REMOTE_ENDPOINT % @subdomain) + (Slackbot::REMOTE_PATH % [@token, channel])
22
+
23
+ stub_request(:post, URI.encode(endpoint)).
24
+ with(:body => "Hello from slack.rb", :headers => {'Accept'=>'*/*'}).
25
+ to_return(:body => "ok")
26
+
27
+ @slack.send channel, message
28
+ end
29
+
30
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slackbot
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - ecin
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-10-10 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: json
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 55
29
+ segments:
30
+ - 1
31
+ - 8
32
+ - 0
33
+ version: 1.8.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 9
45
+ segments:
46
+ - 1
47
+ - 3
48
+ version: "1.3"
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: minitest
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 39
60
+ segments:
61
+ - 5
62
+ - 0
63
+ - 8
64
+ version: 5.0.8
65
+ type: :development
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: webmock
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ hash: 57
76
+ segments:
77
+ - 1
78
+ - 8
79
+ - 7
80
+ version: 1.8.7
81
+ type: :development
82
+ version_requirements: *id004
83
+ description: Tiny library to send messages to the Slack platform.
84
+ email:
85
+ - ecin@copypastel.com
86
+ executables: []
87
+
88
+ extensions: []
89
+
90
+ extra_rdoc_files: []
91
+
92
+ files:
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - README
97
+ - lib/slackbot.rb
98
+ - slackbot.gemspec
99
+ - test/slackbot_test.rb
100
+ homepage: https://github.com/typekit/slackbot
101
+ licenses:
102
+ - MIT
103
+ post_install_message:
104
+ rdoc_options: []
105
+
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ hash: 3
114
+ segments:
115
+ - 0
116
+ version: "0"
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 3
123
+ segments:
124
+ - 0
125
+ version: "0"
126
+ requirements: []
127
+
128
+ rubyforge_project:
129
+ rubygems_version: 1.8.25
130
+ signing_key:
131
+ specification_version: 3
132
+ summary: The laziest bot around.
133
+ test_files:
134
+ - test/slackbot_test.rb