igni 0.0.6 → 0.0.7
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 +4 -4
- data/lib/igni/bot.rb +29 -20
- data/lib/igni/version.rb +1 -1
- 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: 7329ee527ec39d70a3fabdfb288865bdd17e60a5
|
4
|
+
data.tar.gz: e3459319fa520cb9ee3b9853485e27ef4fc83fce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4f6a812af237e58c098952e364c6f1bb66e6438a97214d37d99330393e681f97f0445ed9e5aa07b04dbace912585eb10a09dca25e9324b5d47df1d98779c580
|
7
|
+
data.tar.gz: bd9e01d53448d1eabb0e2353ecc31aca70d6f51378d600459347e1f4af3b8dd85409115ff549264d5accb11519ffe08b49191f1fa6af318b90d685e0ef6c9ce8
|
data/lib/igni/bot.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
|
-
require 'sinatra'
|
1
|
+
require 'sinatra/base'
|
2
2
|
require 'json'
|
3
3
|
require 'igni/api'
|
4
|
+
require 'igni/version'
|
4
5
|
|
5
6
|
module Igni
|
6
|
-
class Bot
|
7
|
+
class Bot
|
7
8
|
include Igni::API
|
8
9
|
|
9
10
|
attr_reader :token
|
10
11
|
attr_reader :hook
|
11
|
-
attr_reader :API
|
12
12
|
|
13
13
|
def initialize(hash)
|
14
|
+
puts "Igni version " + Igni::VERSION
|
15
|
+
|
14
16
|
abort 'No token specified' if hash[:token] == nil
|
15
17
|
abort 'No domain specified' if hash[:domain] == nil
|
16
18
|
|
@@ -25,33 +27,40 @@ module Igni
|
|
25
27
|
abort 'Error while registering webhook!'
|
26
28
|
end
|
27
29
|
|
28
|
-
abort 'Wrong token' if
|
29
|
-
end
|
30
|
+
abort 'Wrong token' if self.getMe['ok'] != true
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
app = Sinatra.new do
|
33
|
+
get '/' do
|
34
|
+
"Hello from Igni on #{@hook}!"
|
35
|
+
end
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
post "/webhook/#{ENV['IGNI_TOKEN']}" do
|
38
|
+
raw = request.env["rack.input"].read
|
39
|
+
|
40
|
+
data = JSON.parse(raw)
|
41
|
+
data["raw"] = raw
|
38
42
|
|
39
|
-
|
40
|
-
|
43
|
+
Thread.new { @handler.call(data) } if @handler != nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
app.run!
|
41
48
|
end
|
42
49
|
|
43
|
-
|
44
|
-
|
50
|
+
def on(&block)
|
51
|
+
@handler = proc { |message| block.call(message) }
|
52
|
+
end
|
45
53
|
|
46
|
-
|
47
|
-
|
54
|
+
def greet
|
55
|
+
puts "hello"
|
56
|
+
end
|
48
57
|
|
49
|
-
|
58
|
+
def handler
|
59
|
+
@handler
|
50
60
|
end
|
51
61
|
|
52
62
|
def register_webhook
|
53
|
-
|
54
|
-
@API.setWebhook(@hook)
|
63
|
+
self.setWebhook(@hook)
|
55
64
|
end
|
56
65
|
end
|
57
66
|
end
|
data/lib/igni/version.rb
CHANGED