Class: SelfSDK::Services::Messaging
- Inherits:
-
Object
- Object
- SelfSDK::Services::Messaging
- Defined in:
- lib/services/messaging.rb
Overview
Input class to interact with self network messaging.
Instance Attribute Summary collapse
-
#client ⇒ Object
TODO : we should try to remove this accessor.
Instance Method Summary collapse
-
#device_id ⇒ String
Gets the device id for the authenticated app.
-
#initialize(client) ⇒ SelfSDK::Services::Messaging
constructor
Creates a new messaging service.
- #notify(recipient, message) ⇒ Object
-
#observer(cid) ⇒ Object
Get the observer by uuid.
-
#send(recipients, request) ⇒ Object
Send custom mmessage.
-
#subscribe(type) {|SelfSDK::Messages::Message| ... } ⇒ Object
Subscribes to a specific message type and attaches the given observer which will be executed when a meeting criteria message is received.
Constructor Details
#initialize(client) ⇒ SelfSDK::Services::Messaging
Creates a new messaging service. Messaging service basically allows you to subscribe to certain types of messages, and manage who can send you messages or not.
22 23 24 |
# File 'lib/services/messaging.rb', line 22 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object
TODO : we should try to remove this accessor.
13 14 15 |
# File 'lib/services/messaging.rb', line 13 def client @client end |
Instance Method Details
#device_id ⇒ String
Gets the device id for the authenticated app.
38 39 40 |
# File 'lib/services/messaging.rb', line 38 def device_id @client.device_id end |
#notify(recipient, message) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/services/messaging.rb', line 65 def notify(recipient, ) send recipient, { typ: 'identities.notify', description: } end |
#observer(cid) ⇒ Object
Get the observer by uuid
45 46 47 |
# File 'lib/services/messaging.rb', line 45 def observer(cid) @client.uuid_observer[cid] end |
#send(recipients, request) ⇒ Object
Send custom mmessage
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/services/messaging.rb', line 54 def send(recipients, request) request[:jti] = SecureRandom.uuid unless request.include?(:jti) request[:iss] = @client.jwt.id request[:iat] = SelfSDK::Time.now.strftime('%FT%TZ') request[:exp] = (SelfSDK::Time.now + 300).strftime('%FT%TZ') request[:cid] = SecureRandom.uuid unless request.include?(:cid) @client.send_custom(recipients, request) request end |
#subscribe(type) {|SelfSDK::Messages::Message| ... } ⇒ Object
Subscribes to a specific message type and attaches the given observer which will be executed when a meeting criteria message is received.
31 32 33 |
# File 'lib/services/messaging.rb', line 31 def subscribe(type, &block) @client.subscribe(type, &block) end |