Class: Pushkin::Subscription
- Inherits:
-
Object
- Object
- Pushkin::Subscription
- Defined in:
- lib/pushkin/subscription.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
Returns the value of attribute channel.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#host ⇒ Object
Returns the value of attribute host.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
Instance Method Summary collapse
- #expiration ⇒ Object
-
#initialize(options = {}) ⇒ Subscription
constructor
A new instance of Subscription.
- #secret_token ⇒ Object
- #server ⇒ Object
- #signature ⇒ Object
- #signature_expired? ⇒ Boolean
- #to_hash ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Subscription
Returns a new instance of Subscription.
5 6 7 8 9 10 |
# File 'lib/pushkin/subscription.rb', line 5 def initialize( = {}) @timestamp = [:timestamp] @host = [:host] @endpoint = [:endpoint] @channel = [:channel] end |
Instance Attribute Details
#channel ⇒ Object
Returns the value of attribute channel.
3 4 5 |
# File 'lib/pushkin/subscription.rb', line 3 def channel @channel end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
3 4 5 |
# File 'lib/pushkin/subscription.rb', line 3 def endpoint @endpoint end |
#host ⇒ Object
Returns the value of attribute host.
3 4 5 |
# File 'lib/pushkin/subscription.rb', line 3 def host @host end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
3 4 5 |
# File 'lib/pushkin/subscription.rb', line 3 def @timestamp end |
Instance Method Details
#expiration ⇒ Object
21 22 23 |
# File 'lib/pushkin/subscription.rb', line 21 def expiration Pushkin.signature_expiration end |
#secret_token ⇒ Object
25 26 27 |
# File 'lib/pushkin/subscription.rb', line 25 def secret_token Pushkin.secret_token end |
#server ⇒ Object
37 38 39 |
# File 'lib/pushkin/subscription.rb', line 37 def server host + endpoint end |
#signature ⇒ Object
12 13 14 |
# File 'lib/pushkin/subscription.rb', line 12 def signature @signature ||= Digest::SHA1.hexdigest([secret_token, channel, ].join) end |
#signature_expired? ⇒ Boolean
16 17 18 19 |
# File 'lib/pushkin/subscription.rb', line 16 def signature_expired? return false unless expiration < ((Time.now.to_f - expiration)*1000).round end |
#to_hash ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/pushkin/subscription.rb', line 45 def to_hash { server: server, timestamp: , channel: channel, signature: signature } end |