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
permalink #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
permalink #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
permalink #allowed_connections ⇒ Array
Lists app allowed connections.
45 46 47 |
# File 'lib/services/messaging.rb', line 45 def allowed_connections acl.list end |
permalink #device_id ⇒ String
Gets the device id for the authenticated app.
69 70 71 |
# File 'lib/services/messaging.rb', line 69 def device_id @client.device_id end |
permalink #is_permitted?(id) ⇒ Boolean
Checks if you’re permitting messages from a specific self identifier
51 52 53 54 55 56 |
# File 'lib/services/messaging.rb', line 51 def is_permitted?(id) conns = allowed_connections return true if conns.include? "*" return true if conns.include? id return false end |
permalink #notify(recipient, message) ⇒ Object
[View source]
97 98 99 100 101 102 |
# File 'lib/services/messaging.rb', line 97 def notify(recipient, ) send recipient, { typ: 'identities.notify', description: } end |
permalink #observer(cid) ⇒ Object
Get the observer by uuid
76 77 78 |
# File 'lib/services/messaging.rb', line 76 def observer(cid) @client.uuid_observer[cid] end |
permalink #permit_connection(selfid) ⇒ Boolean
Permits incoming messages from the a identity.
39 40 41 |
# File 'lib/services/messaging.rb', line 39 def permit_connection(selfid) acl.allow selfid end |
permalink #revoke_connection(selfid) ⇒ Boolean
Revokes incoming messages from the given identity.
62 63 64 |
# File 'lib/services/messaging.rb', line 62 def revoke_connection(selfid) acl.deny selfid end |
permalink #send(recipient, request) ⇒ Object
Send custom mmessage
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/services/messaging.rb', line 86 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 |
permalink #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 |