Module: EM::Pusher::Client

Defined in:
lib/em/pusher/client.rb,
lib/em/pusher/client/connection.rb,
lib/em/pusher/client/msg_parser.rb

Defined Under Namespace

Classes: Connection, MsgParser

Constant Summary collapse

DEFAULT_OPTIONS =
{
  app_id: nil,
  app_secret: nil,
  scheme: 'ws',
  port: 80,
  encrypted: 'on',
  protocol: 4,
  version: '4.2',
  client_name: 'em-pusher-client',
}.freeze
REQUIRED_OPTIONS =
%i[key cluster].freeze

Class Method Summary collapse

Class Method Details

.connect(options) ⇒ Object



23
24
25
26
27
28
# File 'lib/em/pusher/client.rb', line 23

def self.connect(options)
  uri = url(options)
  Connection.connect(uri).tap do |conn|
    yield conn if block_given?
  end
end

.url(options) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/em/pusher/client.rb', line 30

def self.url(options)
  opts = DEFAULT_OPTIONS.merge(options)
  REQUIRED_OPTIONS.each { |opt| fail ArgumentError, "option #{opt} is required" unless opts[opt] }
  "#{opts[:scheme]}://ws-#{opts[:cluster]}.pusher.com:#{opts[:port]}/app/#{opts[:key]}" \
    "?protocol=#{opts[:protocol]}" \
    "&client=#{opts[:client_name]}" \
    "&version=#{opts[:version]}"
end