module Thunderer

Constants

VERSION

Attributes

config[R]

Public Class Methods

configure() { |config| ... } click to toggle source
# File lib/thunderer.rb, line 26
def configure
  yield config if block_given?
end
faye_app(options = {}) click to toggle source
# File lib/thunderer.rb, line 61
def faye_app(options = {})
  options = {mount: '/faye', timeout: 45, extensions: [FayeExtension.new]}.merge(options)
  Faye::RackAdapter.new(options)
end
message(channel, data) click to toggle source
# File lib/thunderer.rb, line 43
def message(channel, data)
  {channel: channel,
   data: {
       channel: channel,
       data: data},
   ext: {thunderer_secret_token: config.secret_token}}
end
publish_message(message) click to toggle source
# File lib/thunderer.rb, line 34
def publish_message(message)
  raise Error, 'No server specified, ensure thunderer.yml was loaded properly.' unless config.server
  if config.async
    Thunderer::Messages::AsyncMessage.new(message)
  else
    Thunderer::Messages::Base.new(message)
  end.deliver
end
publish_to(channel, data) click to toggle source
# File lib/thunderer.rb, line 30
def publish_to channel, data
  publish_message(message(channel, data))
end
reset_config() click to toggle source
# File lib/thunderer.rb, line 18
def reset_config
  @config = Thunderer::Configuration.new
end
signature_expired?(timestamp) click to toggle source
# File lib/thunderer.rb, line 57
def signature_expired?(timestamp)
  timestamp < ((Time.now.to_f - config.signature_expiration)*1000).round if config.signature_expiration
end
subscription(options = {}) click to toggle source
# File lib/thunderer.rb, line 51
def subscription(options = {})
  sub = {server: config.server, timestamp: (Time.now.to_f * 1000).round}.merge(options)
  sub[:signature] = Digest::SHA1.hexdigest([config.secret_token, sub[:channel], sub[:timestamp]].join)
  sub
end