Class: Pusher::Client
- Inherits:
-
Object
- Object
- Pusher::Client
- Defined in:
- lib/pusher/client.rb
Instance Attribute Summary collapse
-
#app_id ⇒ Object
Returns the value of attribute app_id.
-
#host ⇒ Object
Returns the value of attribute host.
-
#key ⇒ Object
Returns the value of attribute key.
-
#port ⇒ Object
Returns the value of attribute port.
-
#scheme ⇒ Object
Returns the value of attribute scheme.
-
#secret ⇒ Object
Returns the value of attribute secret.
Instance Method Summary collapse
-
#[](channel_name) ⇒ Channel
Return a channel by name.
- #authentication_token ⇒ Object
-
#encrypted=(boolean) ⇒ Object
Configure whether Pusher API calls should be made over SSL (default false).
-
#initialize(options = {}) ⇒ Client
constructor
Initializes the client object.
- #url ⇒ Object
-
#url=(url) ⇒ Object
Configure Pusher connection by providing a url rather than specifying scheme, key, secret, and app_id separately.
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( = {}) = { :scheme => 'http', :host => 'api.pusherapp.com', :port => 80, }.merge() @scheme, @host, @port, @app_id, @key, @secret = .values_at( :scheme, :host, :port, :app_id, :key, :secret ) end |
Instance Attribute Details
#app_id ⇒ Object
Returns the value of attribute app_id.
5 6 7 |
# File 'lib/pusher/client.rb', line 5 def app_id @app_id end |
#host ⇒ Object
Returns the value of attribute host.
5 6 7 |
# File 'lib/pusher/client.rb', line 5 def host @host end |
#key ⇒ Object
Returns the value of attribute key.
5 6 7 |
# File 'lib/pusher/client.rb', line 5 def key @key end |
#port ⇒ Object
Returns the value of attribute port.
5 6 7 |
# File 'lib/pusher/client.rb', line 5 def port @port end |
#scheme ⇒ Object
Returns the value of attribute scheme.
5 6 7 |
# File 'lib/pusher/client.rb', line 5 def scheme @scheme end |
#secret ⇒ Object
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
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_token ⇒ Object
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)
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 |
#url ⇒ Object
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.
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 |