Class: SelfSDK::Messages::Base
- Inherits:
-
Object
- Object
- SelfSDK::Messages::Base
- Defined in:
- lib/messages/base.rb
Direct Known Subclasses
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, recipient, recipient_device) ⇒ 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
permalink #initialize(messaging) ⇒ Base
Returns a new instance of Base.
12 13 14 15 16 17 |
# File 'lib/messages/base.rb', line 12 def initialize(messaging) @client = messaging.client @jwt = @client.jwt @messaging = messaging @device_id = "1" end |
Instance Attribute Details
permalink #description ⇒ Object
Returns the value of attribute description.
8 9 10 |
# File 'lib/messages/base.rb', line 8 def description @description end |
permalink #exp_timeout ⇒ Object
Returns the value of attribute exp_timeout.
8 9 10 |
# File 'lib/messages/base.rb', line 8 def exp_timeout @exp_timeout end |
permalink #expires ⇒ Object
Returns the value of attribute expires.
8 9 10 |
# File 'lib/messages/base.rb', line 8 def expires @expires end |
permalink #fields ⇒ Object
Returns the value of attribute fields.
8 9 10 |
# File 'lib/messages/base.rb', line 8 def fields @fields end |
permalink #from ⇒ Object
Returns the value of attribute from.
8 9 10 |
# File 'lib/messages/base.rb', line 8 def from @from end |
permalink #from_device ⇒ Object
Returns the value of attribute from_device.
8 9 10 |
# File 'lib/messages/base.rb', line 8 def from_device @from_device end |
permalink #id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/messages/base.rb', line 8 def id @id end |
permalink #input ⇒ Object
Returns the value of attribute input.
8 9 10 |
# File 'lib/messages/base.rb', line 8 def input @input end |
permalink #intermediary ⇒ Object
Returns the value of attribute intermediary.
8 9 10 |
# File 'lib/messages/base.rb', line 8 def intermediary @intermediary end |
permalink #payload ⇒ Object
Returns the value of attribute payload.
8 9 10 |
# File 'lib/messages/base.rb', line 8 def payload @payload end |
permalink #status ⇒ Object
Returns the value of attribute status.
8 9 10 |
# File 'lib/messages/base.rb', line 8 def status @status end |
permalink #sub ⇒ Object
Returns the value of attribute sub.
8 9 10 |
# File 'lib/messages/base.rb', line 8 def sub @sub end |
permalink #to ⇒ Object
Returns the value of attribute to.
8 9 10 |
# File 'lib/messages/base.rb', line 8 def to @to end |
permalink #to_device ⇒ Object
Returns the value of attribute to_device.
8 9 10 |
# File 'lib/messages/base.rb', line 8 def to_device @to_device end |
permalink #typ ⇒ Object
Returns the value of attribute typ.
8 9 10 |
# File 'lib/messages/base.rb', line 8 def typ @typ end |
Instance Method Details
permalink #accepted? ⇒ Boolean
59 60 61 |
# File 'lib/messages/base.rb', line 59 def accepted? status == "accepted" end |
permalink #encrypt_message(message, recipient, recipient_device) ⇒ Object
[View source]
47 48 49 |
# File 'lib/messages/base.rb', line 47 def (, recipient, recipient_device) @messaging.encryption_client.encrypt(, recipient, recipient_device) end |
permalink #errored? ⇒ Boolean
63 64 65 |
# File 'lib/messages/base.rb', line 63 def errored? status == "errored" end |
permalink #rejected? ⇒ Boolean
55 56 57 |
# File 'lib/messages/base.rb', line 55 def rejected? status == "rejected" end |
permalink #request ⇒ Object
[View source]
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/messages/base.rb', line 19 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 |
permalink #send_message(device_id = nil) ⇒ Object
[View source]
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/messages/base.rb', line 35 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 |
permalink #unauthorized? ⇒ Boolean
51 52 53 |
# File 'lib/messages/base.rb', line 51 def status == "unauthorized" end |
permalink #validate!(original) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/messages/base.rb', line 67 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 > SelfSDK::Time.now end |