Class: Pusher::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/pusher/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Initializes the client object.



8
9
10
11
12
13
14
15
16
17
# File 'lib/pusher/client.rb', line 8

def initialize(options = {})
  options = {
    :scheme => 'http',
    :host => 'api.pusherapp.com',
    :port => 80,
  }.merge(options)
  @scheme, @host, @port, @app_id, @key, @secret = options.values_at(
    :scheme, :host, :port, :app_id, :key, :secret
  )
end

Instance Attribute Details

#app_idObject

Returns the value of attribute app_id.



5
6
7
# File 'lib/pusher/client.rb', line 5

def app_id
  @app_id
end

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/pusher/client.rb', line 5

def host
  @host
end

#keyObject

Returns the value of attribute key.



5
6
7
# File 'lib/pusher/client.rb', line 5

def key
  @key
end

#portObject

Returns the value of attribute port.



5
6
7
# File 'lib/pusher/client.rb', line 5

def port
  @port
end

#schemeObject

Returns the value of attribute scheme.



5
6
7
# File 'lib/pusher/client.rb', line 5

def scheme
  @scheme
end

#secretObject

Returns the value of attribute secret.



5
6
7
# File 'lib/pusher/client.rb', line 5

def secret
  @secret
end

Instance Method Details

#[](channel_name) ⇒ Channel

Return a channel by name

Examples:

Pusher['my-channel']

Returns:

Raises:



69
70
71
72
73
# File 'lib/pusher/client.rb', line 69

def [](channel_name)
  raise ConfigurationError, 'Missing client configuration: please check that key, secret and app_id are configured.' unless configured?
  @channels ||= {}
  @channels[channel_name.to_s] ||= Channel.new(url, channel_name, self)
end

#authentication_tokenObject



20
21
22
# File 'lib/pusher/client.rb', line 20

def authentication_token
  Signature::Token.new(@key, @secret)
end

#encrypted=(boolean) ⇒ Object

Configure whether Pusher API calls should be made over SSL (default false)

Examples:

Pusher.encrypted = true


56
57
58
59
60
# File 'lib/pusher/client.rb', line 56

def encrypted=(boolean)
  @scheme = boolean ? 'https' : 'http'
  # Configure port if it hasn't already been configured
  @port = boolean ? 443 : 80
end

#urlObject



25
26
27
28
29
30
31
32
# File 'lib/pusher/client.rb', line 25

def url
  URI::Generic.build({
    :scheme => @scheme,
    :host => @host,
    :port => @port,
    :path => "/apps/#{@app_id}"
  })
end

#url=(url) ⇒ Object

Configure Pusher connection by providing a url rather than specifying scheme, key, secret, and app_id separately.

Examples:

Pusher.url = http://KEY:[email protected]/apps/APP_ID


40
41
42
43
44
45
46
47
48
# File 'lib/pusher/client.rb', line 40

def url=(url)
  uri = URI.parse(url)
  @scheme = uri.scheme
  @app_id = uri.path.split('/').last
  @key    = uri.user
  @secret = uri.password
  @host   = uri.host
  @port   = uri.port
end