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
-
#allowed_connections ⇒ Array
Lists app allowed connections.
-
#device_id ⇒ String
Gets the device id for the authenticated app.
-
#initialize(client) ⇒ SelfSDK::Services::Messaging
constructor
Creates a new messaging service.
-
#is_permitted?(id) ⇒ Boolean
Checks if you’re permitting messages from a specific self identifier.
- #notify(recipient, message) ⇒ Object
-
#observer(cid) ⇒ Object
Get the observer by uuid.
-
#permit_connection(selfid) ⇒ Boolean
Permits incoming messages from the a identity.
-
#revoke_connection(selfid) ⇒ Boolean
Revokes incoming messages from the given identity.
-
#send(recipient, 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.
20 21 22 |
# File 'lib/services/messaging.rb', line 20 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object
TODO : we should try to remove this accessor.
11 12 13 |
# File 'lib/services/messaging.rb', line 11 def client @client end |
Instance Method Details
#allowed_connections ⇒ Array
Lists app allowed connections.
43 44 45 |
# File 'lib/services/messaging.rb', line 43 def allowed_connections acl.list end |
#device_id ⇒ String
Gets the device id for the authenticated app.
67 68 69 |
# File 'lib/services/messaging.rb', line 67 def device_id @client.device_id end |
#is_permitted?(id) ⇒ Boolean
Checks if you’re permitting messages from a specific self identifier
49 50 51 52 53 54 |
# File 'lib/services/messaging.rb', line 49 def is_permitted?(id) conns = allowed_connections return true if conns.include? "*" return true if conns.include? id return false end |
#notify(recipient, message) ⇒ Object
95 96 97 98 99 100 |
# File 'lib/services/messaging.rb', line 95 def notify(recipient, ) send recipient, { typ: 'identities.notify', description: } end |
#observer(cid) ⇒ Object
Get the observer by uuid
74 75 76 |
# File 'lib/services/messaging.rb', line 74 def observer(cid) @client.uuid_observer[cid] end |
#permit_connection(selfid) ⇒ Boolean
Permits incoming messages from the a identity.
37 38 39 |
# File 'lib/services/messaging.rb', line 37 def permit_connection(selfid) acl.allow selfid end |
#revoke_connection(selfid) ⇒ Boolean
Revokes incoming messages from the given identity.
60 61 62 |
# File 'lib/services/messaging.rb', line 60 def revoke_connection(selfid) acl.deny selfid end |
#send(recipient, request) ⇒ Object
Send custom mmessage
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/services/messaging.rb', line 84 def send(recipient, request) request[:jti] = SecureRandom.uuid request[:iss] = @client.jwt.id request[:sub] = recipient 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(recipient, 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.
29 30 31 |
# File 'lib/services/messaging.rb', line 29 def subscribe(type, &block) @client.subscribe(type, &block) end |