lingr_bot 0.0.1 → 0.0.2
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/lingr_bot/version.rb +2 -2
- data/lib/lingr_bot.rb +41 -2
- metadata +1 -2
- data/lingr_bot.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82cfb655e4868fb244657a5eae784dd4d0d420db
|
4
|
+
data.tar.gz: 8d66d4370622dc06f979dfdcacb9499b0732d4b5
|
5
5
|
!binary "U0hBNTEy":
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afdcdcc3f2c1343a7603824b975005286b4ccf2128dcdadad13305cfb3a6d6ecc44b48c01ccbe44f006d7713165290c0b10fdaf97904229ec7bb07c91e39c841
|
7
|
+
data.tar.gz: 426239d68bd3b1f5f1eb70db5705be6aba7600b8a18fec1469fb248b2d62c6e632ed4be79a7e9c41ab76a24a657c5d85560df4dd8ad0e47438bd3c40320394c6
|
data/lib/lingr_bot/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.0.
|
1
|
+
class LingrBot
|
2
|
+
VERSION = "0.0.2"
|
3
3
|
end
|
data/lib/lingr_bot.rb
CHANGED
@@ -1,5 +1,44 @@
|
|
1
1
|
require "lingr_bot/version"
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require 'open-uri'
|
4
|
+
require 'digest/sha1'
|
5
|
+
require 'hashie'
|
6
|
+
require 'json'
|
7
|
+
require 'active_support'
|
8
|
+
require 'active_support/core_ext'
|
9
|
+
|
10
|
+
class LingrBot
|
11
|
+
cattr_accessor :config
|
12
|
+
attr_accessor :config
|
13
|
+
|
14
|
+
class Configure < HashWithIndifferentAccess
|
15
|
+
include Hashie::Extensions::MethodAccess
|
16
|
+
include Hashie::Extensions::SymbolizeKeys
|
17
|
+
end
|
18
|
+
|
19
|
+
self.config = Configure.new(id: ENV['LINGR_BOT_ID'], secret: ENV['LINGR_BOT_SECRET'])
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
self.config = self.class.config.merge options
|
23
|
+
end
|
24
|
+
|
25
|
+
module BotMethods
|
26
|
+
def configure
|
27
|
+
yield config if block_given?
|
28
|
+
end
|
29
|
+
|
30
|
+
def verifier
|
31
|
+
Digest::SHA1.hexdigest config.id + config.secret
|
32
|
+
end
|
33
|
+
|
34
|
+
def say(room_id, message)
|
35
|
+
message_encoded = URI.encode message
|
36
|
+
url = "http://lingr.com/api/room/say?room=#{room_id}&bot=#{config.id}&text=#{message_encoded}&bot_verifier=#{verifier}"
|
37
|
+
response_body = open(url).read
|
38
|
+
JSON.parse response_body
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
include BotMethods
|
43
|
+
extend BotMethods
|
5
44
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lingr_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seiei Higa
|
@@ -95,7 +95,6 @@ files:
|
|
95
95
|
- lib/lingr_bot.rb
|
96
96
|
- lib/lingr_bot/version.rb
|
97
97
|
- lingr_bot.gemspec
|
98
|
-
- lingr_bot.rb
|
99
98
|
homepage: ''
|
100
99
|
licenses:
|
101
100
|
- MIT
|
data/lingr_bot.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
require 'digest/sha1'
|
3
|
-
require 'hashie'
|
4
|
-
require 'json'
|
5
|
-
require 'active_support'
|
6
|
-
require 'active_support/core_ext'
|
7
|
-
|
8
|
-
class LingrBot
|
9
|
-
cattr_accessor :config
|
10
|
-
attr_accessor :config
|
11
|
-
|
12
|
-
class Configure < HashWithIndifferentAccess
|
13
|
-
include Hashie::Extensions::MethodAccess
|
14
|
-
include Hashie::Extensions::SymbolizeKeys
|
15
|
-
end
|
16
|
-
|
17
|
-
self.config = Configure.new(id: ENV['LINGR_BOT_ID'], secret: ENV['LINGR_BOT_SECRET'])
|
18
|
-
|
19
|
-
def initialize(options = {})
|
20
|
-
self.config = self.class.config.merge options
|
21
|
-
end
|
22
|
-
|
23
|
-
module BotMethods
|
24
|
-
def configure
|
25
|
-
yield config if block_given?
|
26
|
-
end
|
27
|
-
|
28
|
-
def verifier
|
29
|
-
Digest::SHA1.hexdigest config.id + config.secret
|
30
|
-
end
|
31
|
-
|
32
|
-
def say(room_id, message)
|
33
|
-
message_encoded = URI.encode message
|
34
|
-
url = "http://lingr.com/api/room/say?room=#{room_id}&bot=#{config.id}&text=#{message_encoded}&bot_verifier=#{verifier}"
|
35
|
-
response_body = open(url).read
|
36
|
-
JSON.parse response_body
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
include BotMethods
|
41
|
-
extend BotMethods
|
42
|
-
end
|