slackoff 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/slackoff.rb +30 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6ba9f291a91b80f9d48f8f56f125c3acd627177
|
4
|
+
data.tar.gz: dd154e8686662fba9e2e9275a76792ed7ed0258d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 338b4464ebc0ebf72b0d4036b9aa3172a7c941fa5aa3ac662d8b955390ddc31dc829e5778d4084e79fa210169ed319334f558c15adb51f67a14e9fcd88de3ece
|
7
|
+
data.tar.gz: a84caa7945cefaa0656c89c0d06f890c69d4052222cd372780095568d78283b7948864bbea6466979ca7fb956fb41e4cfdc937cfb17f2e5750b9e48149824035
|
data/lib/slackoff.rb
CHANGED
@@ -5,9 +5,18 @@ require 'json'
|
|
5
5
|
module Slackoff
|
6
6
|
class Slack
|
7
7
|
def incoming_webhook(url)
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
Slackoff::Webhook.new(URI(url))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Webhook
|
13
|
+
def initialize(uri)
|
14
|
+
@uri = URI(uri)
|
15
|
+
end
|
16
|
+
|
17
|
+
def send(message)
|
18
|
+
connection = Slackoff::HTTPS.new(@uri)
|
19
|
+
connection.send message
|
11
20
|
end
|
12
21
|
end
|
13
22
|
|
@@ -18,14 +27,29 @@ module Slackoff
|
|
18
27
|
end
|
19
28
|
|
20
29
|
# body is a hash of data
|
21
|
-
def send(
|
30
|
+
def send(post)
|
22
31
|
http = Net::HTTP.new(@uri.host, @uri.port)
|
23
32
|
http.use_ssl = true
|
24
33
|
|
25
34
|
request = Net::HTTP::Post.new(@uri.request_uri)
|
26
|
-
request.body =
|
35
|
+
request.body = post.to_json
|
36
|
+
|
27
37
|
response = http.request request
|
28
|
-
|
38
|
+
|
39
|
+
response
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Post
|
44
|
+
attr_accessor :text, :channel, :username
|
45
|
+
def to_json
|
46
|
+
body = {}
|
47
|
+
|
48
|
+
body[:text] = @text if @text
|
49
|
+
body[:channel] = @channel if @channel
|
50
|
+
body[:username] = @username if @username
|
51
|
+
|
52
|
+
body.to_json
|
29
53
|
end
|
30
54
|
end
|
31
55
|
end
|