slackoff 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/slackoff.rb +30 -6
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 277893768daaf7505125adf77cd51b79067aaa26
4
- data.tar.gz: 925669bb2c0f75fc37d1876ac0448dc3f276158c
3
+ metadata.gz: c6ba9f291a91b80f9d48f8f56f125c3acd627177
4
+ data.tar.gz: dd154e8686662fba9e2e9275a76792ed7ed0258d
5
5
  SHA512:
6
- metadata.gz: 4e5bed9094578efbc798dc1a64b072c5c5096928ad074437b005f98ac5bbf44166a475e4b577ccf00640d3902c99bd2c3d14040ccbcf0dcb65fa94d06392edc9
7
- data.tar.gz: 6c7997c23ada0e803ffc8ee3bfc2db26a6b4e7a1e5951e3b30fd5f0f8e972ac59ffec0c149ce18a9e481bb88790d020a5cad14999616e63be49748efaaa00409
6
+ metadata.gz: 338b4464ebc0ebf72b0d4036b9aa3172a7c941fa5aa3ac662d8b955390ddc31dc829e5778d4084e79fa210169ed319334f558c15adb51f67a14e9fcd88de3ece
7
+ data.tar.gz: a84caa7945cefaa0656c89c0d06f890c69d4052222cd372780095568d78283b7948864bbea6466979ca7fb956fb41e4cfdc937cfb17f2e5750b9e48149824035
@@ -5,9 +5,18 @@ require 'json'
5
5
  module Slackoff
6
6
  class Slack
7
7
  def incoming_webhook(url)
8
- uri = URI(url)
9
- connection = Slackoff::HTTPS.new(uri)
10
- connection
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(body)
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 = body.to_json
35
+ request.body = post.to_json
36
+
27
37
  response = http.request request
28
- return response
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slackoff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Poll