Class: FayeShard::Shard
- Inherits:
-
Object
- Object
- FayeShard::Shard
- Defined in:
- lib/faye_shard/shard.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
Returns the value of attribute configuration.
Instance Method Summary collapse
-
#initialize(config) ⇒ Shard
constructor
Creates a shard instance and assigns the config to it.
-
#js_url(https = false) ⇒ Object
Returns default client JS url.
-
#local_url ⇒ Object
Local url, needed for RoR <-> Faye communication.
-
#push(channel, data, ext = {}) ⇒ Object
Pushes data to a Faye shard.
-
#url(https = false) ⇒ Object
Returns URL for client.
Constructor Details
#initialize(config) ⇒ Shard
Creates a shard instance and assigns the config to it.
- * config
Config to use.
11 12 13 |
# File 'lib/faye_shard/shard.rb', line 11 def initialize(config) self.configuration = config.with_indifferent_access end |
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
5 6 7 |
# File 'lib/faye_shard/shard.rb', line 5 def configuration @configuration end |
Instance Method Details
#js_url(https = false) ⇒ Object
Returns default client JS url
- * https
Specifies whether to use SSL connection or not
29 30 31 |
# File 'lib/faye_shard/shard.rb', line 29 def js_url(https = false) url(https) + '.js' end |
#local_url ⇒ Object
Local url, needed for RoR <-> Faye communication
35 36 37 38 |
# File 'lib/faye_shard/shard.rb', line 35 def local_url host = configuration["local_host"] || configuration["host"] "http://#{host}:#{configuration["port"]}/faye" end |
#push(channel, data, ext = {}) ⇒ Object
Pushes data to a Faye shard
- * channel
User's channel
- * data
Data to push
- * ext
Faye extensions, eg. auth_token
46 47 48 49 50 51 52 |
# File 'lib/faye_shard/shard.rb', line 46 def push(channel, data, ext = {}) uri = URI.parse(self.local_url) http = Net::HTTP.new(uri.host, uri.port) req = Net::HTTP::Post.new uri.path req.set_form_data('message' => {'channel' => channel, 'data' => data, 'ext' => ext}.to_json) http.request req end |
#url(https = false) ⇒ Object
Returns URL for client.
- * https
Specifies whether to use SSL connection or not
19 20 21 22 23 |
# File 'lib/faye_shard/shard.rb', line 19 def url(https = false) secured = (configuration['secured'] || false) & https port = secured ? configuration["secured_port"] : configuration["port"] "http#{secured ? 's' : ''}://#{configuration["host"]}:#{port}/faye" end |