bot_mob 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env +1 -0
- data/.gitignore +0 -1
- data/.rubocop.yml +16 -0
- data/.travis.yml +1 -1
- data/Gemfile +0 -2
- data/LICENSE.txt +21 -0
- data/README.md +5 -4
- data/bin/console +8 -4
- data/bin/mob +4 -0
- data/bot_mob.gemspec +8 -14
- data/examples/fizz_buzz_bot.rb +30 -0
- data/examples/hello_bot.rb +14 -0
- data/examples/server.rb +7 -0
- data/lib/bot_mob.rb +46 -32
- data/lib/bot_mob/bot.rb +146 -29
- data/lib/bot_mob/command.rb +38 -0
- data/lib/bot_mob/connection.rb +18 -50
- data/lib/bot_mob/core_ext/hash.rb +148 -0
- data/lib/bot_mob/core_ext/string.rb +8 -0
- data/lib/bot_mob/environment.rb +25 -0
- data/lib/bot_mob/inbound_message.rb +13 -32
- data/lib/bot_mob/networks/roaming.rb +12 -0
- data/lib/bot_mob/networks/roaming/connection.rb +34 -0
- data/lib/bot_mob/networks/roaming/outbound_message.rb +15 -0
- data/lib/bot_mob/networks/slack.rb +11 -0
- data/lib/bot_mob/networks/slack/connection.rb +37 -0
- data/lib/bot_mob/networks/slack/outbound_message.rb +18 -0
- data/lib/bot_mob/outbound_message.rb +23 -10
- data/lib/bot_mob/public/console.js +10 -0
- data/lib/bot_mob/roster.rb +8 -80
- data/lib/bot_mob/server.rb +47 -0
- data/lib/bot_mob/version.rb +1 -1
- data/lib/bot_mob/views/authorize.erb +1 -0
- data/lib/bot_mob/views/console.erb +6 -0
- data/lib/bot_mob/views/index.erb +1 -0
- data/lib/bot_mob/views/layout.erb +11 -0
- metadata +50 -110
- data/lib/bot_mob/ambassador.rb +0 -34
- data/lib/bot_mob/application.rb +0 -43
- data/lib/bot_mob/authority.rb +0 -41
- data/lib/bot_mob/development/ambassador.rb +0 -21
- data/lib/bot_mob/development/connection.rb +0 -34
- data/lib/bot_mob/development/inbound_message.rb +0 -17
- data/lib/bot_mob/errors.rb +0 -12
- data/lib/bot_mob/install.rb +0 -16
- data/lib/bot_mob/nil_connection.rb +0 -29
- data/lib/bot_mob/slack.rb +0 -10
- data/lib/bot_mob/slack/ambassador.rb +0 -58
- data/lib/bot_mob/slack/connection.rb +0 -87
- data/lib/bot_mob/slack/inbound_message.rb +0 -52
- data/lib/bot_mob/wire.rb +0 -69
data/lib/bot_mob/wire.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'bunny'
|
2
|
-
|
3
|
-
module BotMob
|
4
|
-
# ## BotMob::Wire
|
5
|
-
#
|
6
|
-
# The Wire class is a connection to the Web Server. It
|
7
|
-
# receives notifications from authenticated installs
|
8
|
-
# over RabbitMQ
|
9
|
-
class Wire
|
10
|
-
def initialize
|
11
|
-
@available = nil
|
12
|
-
end
|
13
|
-
|
14
|
-
# ## wire.publish
|
15
|
-
#
|
16
|
-
# The `publish` method takes a given message, converts it to JSON
|
17
|
-
# and pushes the json over the wire on the `wire.notifications` channel.
|
18
|
-
# This is primarily used for passing successful authentication to the
|
19
|
-
# running BotMob Application.
|
20
|
-
def publish(message = {})
|
21
|
-
BotMob.logger.info "Publishing #{message} to wire.notifications"
|
22
|
-
queue.publish(message.to_json, routing_key: queue.name)
|
23
|
-
end
|
24
|
-
|
25
|
-
# ## wire.listen
|
26
|
-
#
|
27
|
-
# The `listen` method takes a block to perform when a
|
28
|
-
# message is received over the wire. The message published
|
29
|
-
# to the wire is parsed JSON provided to the calling block.
|
30
|
-
def listen
|
31
|
-
return if !block_given? || queue.nil?
|
32
|
-
|
33
|
-
queue.subscribe do |_info, _props, body|
|
34
|
-
yield(JSON.parse(body))
|
35
|
-
end
|
36
|
-
rescue Bunny::PreconditionFailed => e
|
37
|
-
BotMob.logger.info "#{e.channel_close.reply_code}, message: #{e.channel_close.reply_text}"
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
def available?
|
42
|
-
!!@available
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def channel
|
48
|
-
@channel ||= connection && connection.create_channel
|
49
|
-
end
|
50
|
-
|
51
|
-
def queue
|
52
|
-
@queue ||= channel && channel.queue('wire.notifications')
|
53
|
-
end
|
54
|
-
|
55
|
-
def connection
|
56
|
-
@connection ||= begin
|
57
|
-
Bunny.new.tap do |conn|
|
58
|
-
conn.start
|
59
|
-
@available = true
|
60
|
-
BotMob.logger.info('=> Wire connected')
|
61
|
-
end
|
62
|
-
rescue Bunny::TCPConnectionFailedForAllHosts => e
|
63
|
-
@available = false
|
64
|
-
BotMob.logger.info('=> RabbitMQ unavailable, skipping wire')
|
65
|
-
nil
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|