class SelfSDK::Services::Messaging
Input class to interact with self network messaging.
Attributes
TODO : we should try to remove this accessor. @attr_accessor [SelfSDK::Messaging] internal messaging client.
Public Class Methods
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.
@param client [SelfSDK::Messaging] messaging object.
@return [SelfSDK::Services::Messaging] authentication service.
# File lib/services/messaging.rb, line 22 def initialize(client) @client = client end
Public Instance Methods
Lists app allowed connections. @return [Array] array of self ids allowed to connect to your app.
# File lib/services/messaging.rb, line 45 def allowed_connections acl.list end
Gets the device id for the authenticated app.
@return [String] device_id
of the running app.
# File lib/services/messaging.rb, line 69 def device_id @client.device_id end
Checks if you're permitting messages from a specific self identifier @return [Boolean] yes|no
# 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
# File lib/services/messaging.rb, line 97 def notify(recipient, message) send recipient, { typ: 'identities.notify', description: message } end
Get the observer by uuid
@param [String] cid conversation id
# File lib/services/messaging.rb, line 76 def observer(cid) @client.uuid_observer[cid] end
Permits incoming messages from the a identity.
@param [String] selfid to be allowed. @return [Boolean] success / failure
# File lib/services/messaging.rb, line 39 def permit_connection(selfid) acl.allow selfid end
Revokes incoming messages from the given identity.
@param [String] selfid to be denied @return [Boolean] success / failure
# File lib/services/messaging.rb, line 62 def revoke_connection(selfid) acl.deny selfid end
Send custom mmessage
@param recipient [string] recipient for the message @param type [string] message type @param request [hash] message to be sent
# 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
Subscribes to a specific message type and attaches the given observer which will be executed when a meeting criteria message is received.
@param [String] type message type (ex: SelfSDK::Messages::AuthenticationResp
.MSG_TYPE @yield [SelfSDK::Messages::Message] receives incoming message.
# File lib/services/messaging.rb, line 31 def subscribe(type, &block) @client.subscribe(type, &block) end
Private Instance Methods
# File lib/services/messaging.rb, line 106 def acl @acl ||= ACL.new(@client) end