class Ellen::Adapters::Idobata
Public Instance Methods
auth_payload()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 101 def auth_payload { socket_id: socket_id, channel_name: channel_name } end
bot()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 91 def bot records["bot"] end
channel()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 148 def channel socket.channels.add(channel_name) end
channel_name()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 96 def channel_name bot["channel_name"] end
connect()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 133 def connect socket.connect end
connected?()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 138 def connected? socket.connected end
headers()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 68 def headers { 'X-API-Token' => idobata_api_token, 'User-Agent' => "ellen-idobata / v#{Ellen::Idobata::VERSION}" } end
idobata_api_token()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 48 def idobata_api_token ENV["IDOBATA_API_TOKEN"] end
idobata_messages_url()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 63 def idobata_messages_url URI.join(idobata_url, '/api/messages') end
idobata_pusher_auth_url()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 58 def idobata_pusher_auth_url URI.join(idobata_url, '/pusher/auth') end
idobata_pusher_key()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 43 def idobata_pusher_key ENV["IDOBATA_PUSHER_KEY"] || "44ffe67af1c7035be764" end
idobata_seed_url()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 53 def idobata_seed_url URI.join(idobata_url, '/api/seed') end
idobata_url()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 38 def idobata_url URI.parse(ENV["IDOBATA_URL"] || "https://idobata.io/") end
join_channel()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 153 def join_channel socket.authorize_callback(channel, pusher_auth["auth"], pusher_auth["channel_data"]) end
listen()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 158 def listen channel.bind('message_created') do |message_json| message = JSON.parse(message_json)['message'] @last_room_id = message['room_id'] robot.receive(body: message['body_plain']) end end
log_message()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 167 def log_message channel.bind('message_created') do |message_json| pp JSON.parse message_json end end
on_connection_established(&block)
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 33 def on_connection_established(&block) socket.bind('pusher:connection_established', &block) end
pusher_auth()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 123 def pusher_auth JSON.parse pusher_auth_json end
pusher_auth_json()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 118 def pusher_auth_json authorize.body end
records()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 86 def records seed["records"] end
run()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 16 def run on_connection_established do join_channel log_message listen end connect end
say(source)
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 25 def say(source) req = Net::HTTP::Post.new(idobata_messages_url.path, headers) req.form_data = { 'message[room_id]' => @last_room_id, 'message[source]' => source } https = Net::HTTP.new(idobata_messages_url.host, idobata_messages_url.port) https.use_ssl = true https.start {|https| https.request(req) } end
seed()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 81 def seed JSON.parse(seed_json) end
seed_json()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 76 def seed_json idobata_seed_url.read(headers) end
socket()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 128 def socket PusherClient::Socket.new(idobata_pusher_key, encrypted: true) end
socket_id()
click to toggle source
# File lib/ellen/adapters/idobata.rb, line 143 def socket_id socket.socket_id end