class FayeShard::Shard
Attributes
configuration[RW]
Public Class Methods
new(config)
click to toggle source
Creates a shard instance and assigns the config to it.
config
-
Config to use.
# File lib/faye_shard/shard.rb, line 11 def initialize(config) self.configuration = config.with_indifferent_access end
Public Instance Methods
js_url(https = false)
click to toggle source
Returns default client JS url
https
-
Specifies whether to use SSL connection or not
# File lib/faye_shard/shard.rb, line 29 def js_url(https = false) url(https) + '.js' end
local_url()
click to toggle source
Local url, needed for RoR <-> Faye communication
# 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 = {})
click to toggle source
Pushes data to a Faye shard
channel
-
User’s channel
data
-
Data to push
ext
-
Faye extensions, eg. auth_token
# 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)
click to toggle source
Returns URL for client.
https
-
Specifies whether to use SSL connection or not
# 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