Class: Pushkin::Subscription

Inherits:
Object
  • Object
show all
Defined in:
lib/pushkin/subscription.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  @timestamp    = options[:timestamp]
  @host         = options[:host]
  @endpoint     = options[:endpoint]
  @channel      = options[:channel]
end

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



3
4
5
# File 'lib/pushkin/subscription.rb', line 3

def channel
  @channel
end

#endpointObject

Returns the value of attribute endpoint.



3
4
5
# File 'lib/pushkin/subscription.rb', line 3

def endpoint
  @endpoint
end

#hostObject

Returns the value of attribute host.



3
4
5
# File 'lib/pushkin/subscription.rb', line 3

def host
  @host
end

#timestampObject

Returns the value of attribute timestamp.



3
4
5
# File 'lib/pushkin/subscription.rb', line 3

def timestamp
  @timestamp
end

Instance Method Details

#expirationObject



21
22
23
# File 'lib/pushkin/subscription.rb', line 21

def expiration
  Pushkin.signature_expiration
end

#secret_tokenObject



25
26
27
# File 'lib/pushkin/subscription.rb', line 25

def secret_token
  Pushkin.secret_token
end

#serverObject



37
38
39
# File 'lib/pushkin/subscription.rb', line 37

def server
  host + endpoint
end

#signatureObject



12
13
14
# File 'lib/pushkin/subscription.rb', line 12

def signature
  @signature ||= Digest::SHA1.hexdigest([secret_token, channel, timestamp].join)
end

#signature_expired?Boolean

Returns:

  • (Boolean)


16
17
18
19
# File 'lib/pushkin/subscription.rb', line 16

def signature_expired?
  return false unless expiration
  timestamp < ((Time.now.to_f - expiration)*1000).round
end

#to_hashObject



45
46
47
48
49
50
51
52
# File 'lib/pushkin/subscription.rb', line 45

def to_hash
  {
    server: server,
    timestamp: timestamp,
    channel: channel,
    signature: signature
  }
end