Class: Turbo::Train::MercureConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/turbo/train/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMercureConfiguration

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_domainObject

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_keyObject

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_keyObject

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_urlObject



17
18
19
# File 'lib/turbo/train/config.rb', line 17

def publish_url
  "#{url}/mercure"
end

#urlObject



13
14
15
# File 'lib/turbo/train/config.rb', line 13

def url
  "https://#{mercure_domain}/.well-known"
end