Class: SelfSDK::Messages::Base
- Inherits:
 - 
      Object
      
        
- Object
 - SelfSDK::Messages::Base
 
 
- Defined in:
 - lib/messages/base.rb
 
Direct Known Subclasses
Chat, ConnectionRequest, ConnectionResponse, DocumentSignResponse, FactIssue, FactRequest, FactResponse
Instance Attribute Summary collapse
- 
  
    
      #description  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute description.
 - 
  
    
      #exp_timeout  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute exp_timeout.
 - 
  
    
      #expires  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute expires.
 - 
  
    
      #fields  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute fields.
 - 
  
    
      #from  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute from.
 - 
  
    
      #from_device  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute from_device.
 - 
  
    
      #id  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute id.
 - 
  
    
      #input  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute input.
 - 
  
    
      #intermediary  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute intermediary.
 - 
  
    
      #payload  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute payload.
 - 
  
    
      #status  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute status.
 - 
  
    
      #sub  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute sub.
 - 
  
    
      #to  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute to.
 - 
  
    
      #to_device  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute to_device.
 - 
  
    
      #typ  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute typ.
 
Instance Method Summary collapse
- #accepted? ⇒ Boolean
 - #encrypt_message(message, recipients) ⇒ Object
 - #errored? ⇒ Boolean
 - 
  
    
      #initialize(messaging)  ⇒ Base 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Base.
 - #rejected? ⇒ Boolean
 - #request ⇒ Object
 - #send_message(device_id = nil) ⇒ Object
 - #unauthorized? ⇒ Boolean
 - #validate!(original) ⇒ Object
 
Constructor Details
#initialize(messaging) ⇒ Base
Returns a new instance of Base.
      16 17 18 19 20 21 22  | 
    
      # File 'lib/messages/base.rb', line 16 def initialize(messaging) @intermediary = nil @client = messaging.client @jwt = @client.jwt @messaging = messaging @device_id = "1" end  | 
  
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
      12 13 14  | 
    
      # File 'lib/messages/base.rb', line 12 def description @description end  | 
  
#exp_timeout ⇒ Object
Returns the value of attribute exp_timeout.
      12 13 14  | 
    
      # File 'lib/messages/base.rb', line 12 def exp_timeout @exp_timeout end  | 
  
#expires ⇒ Object
Returns the value of attribute expires.
      12 13 14  | 
    
      # File 'lib/messages/base.rb', line 12 def expires @expires end  | 
  
#fields ⇒ Object
Returns the value of attribute fields.
      12 13 14  | 
    
      # File 'lib/messages/base.rb', line 12 def fields @fields end  | 
  
#from ⇒ Object
Returns the value of attribute from.
      12 13 14  | 
    
      # File 'lib/messages/base.rb', line 12 def from @from end  | 
  
#from_device ⇒ Object
Returns the value of attribute from_device.
      12 13 14  | 
    
      # File 'lib/messages/base.rb', line 12 def from_device @from_device end  | 
  
#id ⇒ Object
Returns the value of attribute id.
      12 13 14  | 
    
      # File 'lib/messages/base.rb', line 12 def id @id end  | 
  
#input ⇒ Object
Returns the value of attribute input.
      12 13 14  | 
    
      # File 'lib/messages/base.rb', line 12 def input @input end  | 
  
#intermediary ⇒ Object
Returns the value of attribute intermediary.
      12 13 14  | 
    
      # File 'lib/messages/base.rb', line 12 def intermediary @intermediary end  | 
  
#payload ⇒ Object
Returns the value of attribute payload.
      12 13 14  | 
    
      # File 'lib/messages/base.rb', line 12 def payload @payload end  | 
  
#status ⇒ Object
Returns the value of attribute status.
      12 13 14  | 
    
      # File 'lib/messages/base.rb', line 12 def status @status end  | 
  
#sub ⇒ Object
Returns the value of attribute sub.
      12 13 14  | 
    
      # File 'lib/messages/base.rb', line 12 def sub @sub end  | 
  
#to ⇒ Object
Returns the value of attribute to.
      12 13 14  | 
    
      # File 'lib/messages/base.rb', line 12 def to @to end  | 
  
#to_device ⇒ Object
Returns the value of attribute to_device.
      12 13 14  | 
    
      # File 'lib/messages/base.rb', line 12 def to_device @to_device end  | 
  
#typ ⇒ Object
Returns the value of attribute typ.
      12 13 14  | 
    
      # File 'lib/messages/base.rb', line 12 def typ @typ end  | 
  
Instance Method Details
#accepted? ⇒ Boolean
      64 65 66  | 
    
      # File 'lib/messages/base.rb', line 64 def accepted? status == "accepted" end  | 
  
#encrypt_message(message, recipients) ⇒ Object
      52 53 54  | 
    
      # File 'lib/messages/base.rb', line 52 def (, recipients) @messaging.encryption_client.encrypt(, recipients) end  | 
  
#errored? ⇒ Boolean
      68 69 70  | 
    
      # File 'lib/messages/base.rb', line 68 def errored? status == "errored" end  | 
  
#rejected? ⇒ Boolean
      60 61 62  | 
    
      # File 'lib/messages/base.rb', line 60 def rejected? status == "rejected" end  | 
  
#request ⇒ Object
      24 25 26 27 28 29 30 31 32 33 34 35 36 37 38  | 
    
      # File 'lib/messages/base.rb', line 24 def request check_credits! msgs = [] devices.each do |d| msgs << proto(d) end current_devices.each do |d| if d != @messaging.device_id msgs << proto(d) end end SelfSDK.logger.info "synchronously messaging to #{@to}" res = @messaging.send_and_wait_for_response(msgs, self) res end  | 
  
#send_message(device_id = nil) ⇒ Object
      40 41 42 43 44 45 46 47 48 49 50  | 
    
      # File 'lib/messages/base.rb', line 40 def (device_id = nil) check_credits! dds = devices dds = [device_id] if device_id res = [] dds.each do |d| res << @messaging.(proto(d)) SelfSDK.logger.info "asynchronously requested information to #{@to}:#{d}" end res.first end  | 
  
#unauthorized? ⇒ Boolean
      56 57 58  | 
    
      # File 'lib/messages/base.rb', line 56 def status == "unauthorized" end  | 
  
#validate!(original) ⇒ Object
      72 73 74 75 76 77 78 79 80 81 82 83  | 
    
      # File 'lib/messages/base.rb', line 72 def validate!(original) unless original.nil? raise ::StandardError.new("bad response audience") if @audience != original.from if original.intermediary.nil? raise ::StandardError.new("bad issuer") if @from != original.to else raise ::StandardError.new("bad issuer") if @from != original.intermediary end end raise ::StandardError.new("expired message") if @expires < SelfSDK::Time.now raise ::StandardError.new("issued too soon") if @issued.round > (SelfSDK::Time.now + 1).round end  |