Class: Turbo::Train::AnycableServer
- Inherits:
-
BaseServer
- Object
- BaseServer
- Turbo::Train::AnycableServer
- Defined in:
- lib/turbo/train/anycable_server.rb
Instance Attribute Summary
Attributes inherited from BaseServer
Instance Method Summary collapse
Methods inherited from BaseServer
#initialize, #listen_url, #publish_url
Constructor Details
This class inherits a constructor from Turbo::Train::BaseServer
Instance Method Details
#publish(topics:, data:) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/turbo/train/anycable_server.rb', line 4 def publish(topics:, data:) uri = URI(server_config.publish_url) req = Net::HTTP::Post.new(uri) req['Content-Type'] = 'application/json' req['Authorization'] = "Bearer #{server_config.broadcast_key}" = data[:data].gsub("\n", '') opts = { use_ssl: uri.scheme == 'https' } payload = [] Array(topics).each do |topic| payload << { stream: topic, data: } end req.body = payload.to_json opts[:verify_mode] = OpenSSL::SSL::VERIFY_NONE if configuration.skip_ssl_verification Net::HTTP.start(uri.host, uri.port, opts) do |http| http.request(req) end end |
#server_config ⇒ Object
31 32 33 |
# File 'lib/turbo/train/anycable_server.rb', line 31 def server_config configuration.anycable end |