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 ⇒ Object
- #unauthorized? ⇒ Boolean
- #validate!(original) ⇒ Object
Constructor Details
#initialize(messaging) ⇒ Base
Returns a new instance of Base.
10 11 12 13 14 15 |
# File 'lib/messages/base.rb', line 10 def initialize(messaging) @client = messaging.client @jwt = @client.jwt @messaging = messaging @device_id = "1" end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'lib/messages/base.rb', line 6 def description @description end |
#exp_timeout ⇒ Object
Returns the value of attribute exp_timeout.
6 7 8 |
# File 'lib/messages/base.rb', line 6 def exp_timeout @exp_timeout end |
#expires ⇒ Object
Returns the value of attribute expires.
6 7 8 |
# File 'lib/messages/base.rb', line 6 def expires @expires end |
#fields ⇒ Object
Returns the value of attribute fields.
6 7 8 |
# File 'lib/messages/base.rb', line 6 def fields @fields end |
#from ⇒ Object
Returns the value of attribute from.
6 7 8 |
# File 'lib/messages/base.rb', line 6 def from @from end |
#from_device ⇒ Object
Returns the value of attribute from_device.
6 7 8 |
# File 'lib/messages/base.rb', line 6 def from_device @from_device end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/messages/base.rb', line 6 def id @id end |
#input ⇒ Object
Returns the value of attribute input.
6 7 8 |
# File 'lib/messages/base.rb', line 6 def input @input end |
#intermediary ⇒ Object
Returns the value of attribute intermediary.
6 7 8 |
# File 'lib/messages/base.rb', line 6 def intermediary @intermediary end |
#payload ⇒ Object
Returns the value of attribute payload.
6 7 8 |
# File 'lib/messages/base.rb', line 6 def payload @payload end |
#status ⇒ Object
Returns the value of attribute status.
6 7 8 |
# File 'lib/messages/base.rb', line 6 def status @status end |
#sub ⇒ Object
Returns the value of attribute sub.
6 7 8 |
# File 'lib/messages/base.rb', line 6 def sub @sub end |
#to ⇒ Object
Returns the value of attribute to.
6 7 8 |
# File 'lib/messages/base.rb', line 6 def to @to end |
#to_device ⇒ Object
Returns the value of attribute to_device.
6 7 8 |
# File 'lib/messages/base.rb', line 6 def to_device @to_device end |
#typ ⇒ Object
Returns the value of attribute typ.
6 7 8 |
# File 'lib/messages/base.rb', line 6 def typ @typ end |
Instance Method Details
#accepted? ⇒ Boolean
41 42 43 |
# File 'lib/messages/base.rb', line 41 def accepted? status == "accepted" end |
#encrypt_message(message, recipient, recipient_device) ⇒ Object
29 30 31 |
# File 'lib/messages/base.rb', line 29 def (, recipient, recipient_device) @messaging.encryption_client.encrypt(, recipient, recipient_device) end |
#errored? ⇒ Boolean
45 46 47 |
# File 'lib/messages/base.rb', line 45 def errored? status == "errored" end |
#rejected? ⇒ Boolean
37 38 39 |
# File 'lib/messages/base.rb', line 37 def rejected? status == "rejected" end |
#request ⇒ Object
17 18 19 20 21 |
# File 'lib/messages/base.rb', line 17 def request res = @messaging.send_and_wait_for_response(proto, self) SelfSDK.logger.info "synchronously messaging to #{@to}:#{@to_device}" res end |
#send_message ⇒ Object
23 24 25 26 27 |
# File 'lib/messages/base.rb', line 23 def res = @messaging. proto SelfSDK.logger.info "asynchronously requested information to #{@to}:#{@to_device}" res end |
#unauthorized? ⇒ Boolean
33 34 35 |
# File 'lib/messages/base.rb', line 33 def status == "unauthorized" end |
#validate!(original) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/messages/base.rb', line 49 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 |