Class: Turbo::Train::MercureConfiguration
- Inherits:
-
Object
- Object
- Turbo::Train::MercureConfiguration
- Defined in:
- lib/turbo/train/config.rb
Instance Attribute Summary collapse
-
#mercure_domain ⇒ Object
Returns the value of attribute mercure_domain.
-
#publisher_key ⇒ Object
Returns the value of attribute publisher_key.
-
#subscriber_key ⇒ Object
Returns the value of attribute subscriber_key.
Instance Method Summary collapse
-
#initialize ⇒ MercureConfiguration
constructor
A new instance of MercureConfiguration.
- #jwt_auth_token(payload) ⇒ Object
- #listen_url(topic, platform: 'web') ⇒ Object
- #publish_url ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize ⇒ MercureConfiguration
Returns a new instance of MercureConfiguration.
6 7 8 9 10 11 |
# File 'lib/turbo/train/config.rb', line 6 def initialize super @mercure_domain = 'localhost' @publisher_key = 'test' @subscriber_key = 'testing' end |
Instance Attribute Details
#mercure_domain ⇒ Object
Returns the value of attribute mercure_domain.
4 5 6 |
# File 'lib/turbo/train/config.rb', line 4 def mercure_domain @mercure_domain end |
#publisher_key ⇒ Object
Returns the value of attribute publisher_key.
4 5 6 |
# File 'lib/turbo/train/config.rb', line 4 def publisher_key @publisher_key end |
#subscriber_key ⇒ Object
Returns the value of attribute subscriber_key.
4 5 6 |
# File 'lib/turbo/train/config.rb', line 4 def subscriber_key @subscriber_key end |
Instance Method Details
#jwt_auth_token(payload) ⇒ Object
25 26 27 28 |
# File 'lib/turbo/train/config.rb', line 25 def jwt_auth_token(payload) structured_payload = { mercure: { payload: payload } } JWT.encode structured_payload, subscriber_key, ALGORITHM end |
#listen_url(topic, platform: 'web') ⇒ Object
21 22 23 |
# File 'lib/turbo/train/config.rb', line 21 def listen_url(topic, platform: 'web') "#{url}/mercure?topic=#{Turbo::Train.signed_stream_name(topic)}&authorization=#{jwt_auth_token({ platform: platform })}" end |
#publish_url ⇒ Object
17 18 19 |
# File 'lib/turbo/train/config.rb', line 17 def publish_url "#{url}/mercure" end |
#url ⇒ Object
13 14 15 |
# File 'lib/turbo/train/config.rb', line 13 def url "https://#{mercure_domain}/.well-known" end |