Module: Pusher

Defined in:
lib/pusher.rb,
lib/pusher/json.rb,
lib/pusher/channel.rb,
lib/pusher/request.rb

Defined Under Namespace

Modules: JSON Classes: AuthenticationError, Channel, ConfigurationError, Error, Request

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.app_idObject

Returns the value of attribute app_id.



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

def app_id
  @app_id
end

.hostObject

Returns the value of attribute host.



10
11
12
# File 'lib/pusher.rb', line 10

def host
  @host
end

.keyObject

Returns the value of attribute key.



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

def key
  @key
end

.loggerObject



14
15
16
17
18
19
20
# File 'lib/pusher.rb', line 14

def logger
  @logger ||= begin
    log = Logger.new(STDOUT)
    log.level = Logger::INFO
    log
  end
end

.portObject

Returns the value of attribute port.



10
11
12
# File 'lib/pusher.rb', line 10

def port
  @port
end

.schemeObject

Returns the value of attribute scheme.



10
11
12
# File 'lib/pusher.rb', line 10

def scheme
  @scheme
end

.secretObject

Returns the value of attribute secret.



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

def secret
  @secret
end

Class Method Details

.[](channel_name) ⇒ Object

Raises:



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

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

.authentication_tokenObject



22
23
24
# File 'lib/pusher.rb', line 22

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

.encrypted=(boolean) ⇒ Object

Configure ssl by setting Pusher.encrypted = true



47
48
49
50
51
# File 'lib/pusher.rb', line 47

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

.urlObject

Builds a connection url for Pusherapp



27
28
29
30
31
32
33
34
# File 'lib/pusher.rb', line 27

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

.url=(url) ⇒ Object

Allows configuration from a url



37
38
39
40
41
42
43
44
# File 'lib/pusher.rb', line 37

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