Module: Breakout

Defined in:
lib/breakout/api.rb,
lib/breakout/app.rb,
lib/breakout/config.rb,
lib/breakout/socket.rb,
lib/breakout/worker.rb,
lib/breakout/version.rb

Defined Under Namespace

Modules: Worker Classes: Socket

Constant Summary collapse

CONFIG =
{}
VERSION =
"0.0.3"

Class Method Summary collapse

Class Method Details

.browser_url(route, opts = {}) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/breakout/config.rb', line 34

def self.browser_url(route, opts={})
  bid = opts[:bid] || random_bid
  e = opts[:e] || (Time.now + 3).to_i
  notify = opts[:notify] || false
  gat = grid_access_token(route, bid, e, notify)
  host = opts[:host] || CONFIG[:breakout_host]
  "ws://#{host}:#{CONFIG[:browser_port]}/#{CONFIG[:grid]}?route=#{route}&bid=#{bid}&e=#{e}&notify=#{notify}&gat=#{gat}"
end

.config(opts = {}) ⇒ Object



21
22
23
# File 'lib/breakout/config.rb', line 21

def self.config(opts={})
  CONFIG.merge!(opts)
end

.grid_access_token(route, bid, e, notify, grid_key = nil) ⇒ Object



25
26
27
28
# File 'lib/breakout/config.rb', line 25

def self.grid_access_token(route, bid, e, notify, grid_key=nil)
  grid_key ||= CONFIG[:grid_key]
  (Digest::SHA2.new << "#{grid_key}#{route}#{bid}#{e}#{notify}").to_s
end

.load_or_create_config_file(config_filename) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/breakout/config.rb', line 43

def self.load_or_create_config_file(config_filename)
  unless File.exist?(config_filename)
    File.open(config_filename, 'w') do |f|
      f.write random_config.to_yaml
    end
  end
  config(YAML.load(File.open(config_filename, 'r')))
end

.random_bidObject



17
18
19
# File 'lib/breakout/config.rb', line 17

def self.random_bid
  (Digest::SHA2.new << rand.to_s).to_s[0..10]
end

.random_configObject



7
8
9
10
11
12
13
14
15
# File 'lib/breakout/config.rb', line 7

def self.random_config
  { 
    :breakout_host => 'localhost',
    :worker_port => 9001,
    :browser_port => 9002,
    :grid => (Digest::SHA2.new << rand.to_s).to_s[0..4],
    :grid_key => (Digest::SHA2.new << rand.to_s).to_s[0..30]
  }
end

.worker_urlObject



30
31
32
# File 'lib/breakout/config.rb', line 30

def self.worker_url()
  "ws://#{CONFIG[:breakout_host]}:#{CONFIG[:worker_port]}/#{CONFIG[:grid]}?grid_key=#{CONFIG[:grid_key]}"
end