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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.env +1 -0
  3. data/.gitignore +0 -1
  4. data/.rubocop.yml +16 -0
  5. data/.travis.yml +1 -1
  6. data/Gemfile +0 -2
  7. data/LICENSE.txt +21 -0
  8. data/README.md +5 -4
  9. data/bin/console +8 -4
  10. data/bin/mob +4 -0
  11. data/bot_mob.gemspec +8 -14
  12. data/examples/fizz_buzz_bot.rb +30 -0
  13. data/examples/hello_bot.rb +14 -0
  14. data/examples/server.rb +7 -0
  15. data/lib/bot_mob.rb +46 -32
  16. data/lib/bot_mob/bot.rb +146 -29
  17. data/lib/bot_mob/command.rb +38 -0
  18. data/lib/bot_mob/connection.rb +18 -50
  19. data/lib/bot_mob/core_ext/hash.rb +148 -0
  20. data/lib/bot_mob/core_ext/string.rb +8 -0
  21. data/lib/bot_mob/environment.rb +25 -0
  22. data/lib/bot_mob/inbound_message.rb +13 -32
  23. data/lib/bot_mob/networks/roaming.rb +12 -0
  24. data/lib/bot_mob/networks/roaming/connection.rb +34 -0
  25. data/lib/bot_mob/networks/roaming/outbound_message.rb +15 -0
  26. data/lib/bot_mob/networks/slack.rb +11 -0
  27. data/lib/bot_mob/networks/slack/connection.rb +37 -0
  28. data/lib/bot_mob/networks/slack/outbound_message.rb +18 -0
  29. data/lib/bot_mob/outbound_message.rb +23 -10
  30. data/lib/bot_mob/public/console.js +10 -0
  31. data/lib/bot_mob/roster.rb +8 -80
  32. data/lib/bot_mob/server.rb +47 -0
  33. data/lib/bot_mob/version.rb +1 -1
  34. data/lib/bot_mob/views/authorize.erb +1 -0
  35. data/lib/bot_mob/views/console.erb +6 -0
  36. data/lib/bot_mob/views/index.erb +1 -0
  37. data/lib/bot_mob/views/layout.erb +11 -0
  38. metadata +50 -110
  39. data/lib/bot_mob/ambassador.rb +0 -34
  40. data/lib/bot_mob/application.rb +0 -43
  41. data/lib/bot_mob/authority.rb +0 -41
  42. data/lib/bot_mob/development/ambassador.rb +0 -21
  43. data/lib/bot_mob/development/connection.rb +0 -34
  44. data/lib/bot_mob/development/inbound_message.rb +0 -17
  45. data/lib/bot_mob/errors.rb +0 -12
  46. data/lib/bot_mob/install.rb +0 -16
  47. data/lib/bot_mob/nil_connection.rb +0 -29
  48. data/lib/bot_mob/slack.rb +0 -10
  49. data/lib/bot_mob/slack/ambassador.rb +0 -58
  50. data/lib/bot_mob/slack/connection.rb +0 -87
  51. data/lib/bot_mob/slack/inbound_message.rb +0 -52
  52. data/lib/bot_mob/wire.rb +0 -69
@@ -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