Module: CineSync::Commands

Defined in:
lib/cinesync/commands.rb

Constant Summary collapse

IllegalFileChars =
/[^\w ~!@#\$%&\(\)_\-\+=\[\]\{\}',\.]/

Class Method Summary collapse

Class Method Details

.create_session(username = nil, password = nil) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/cinesync/commands.rb', line 22

def self.create_session(username = nil, password = nil)
  "cinesync://session/new" + if username
    "?username=#{CGI.escape(username)}" + if password
      "&password=#{CGI.escape(password)}"
    else '' end
  else '' end
end

.join_session(session_key) ⇒ Object



30
31
32
# File 'lib/cinesync/commands.rb', line 30

def self.join_session(session_key)
  "cinesync://session/#{URI.escape(session_key)}"
end

.open_session(session, name = nil, merge_with_existing = true) ⇒ Object



43
44
45
46
47
48
# File 'lib/cinesync/commands.rb', line 43

def self.open_session(session, name = nil, merge_with_existing = true)
  name ||= "untitled session"
  path = File.join(Dir.tmpdir, name.gsub(IllegalFileChars, '_') + ".csc")
  File.open(path, "w") {|f| f.puts session.to_xml }
  open_session_file(path, merge_with_existing)
end

.open_session_file(path, merge_with_existing = true) ⇒ Object



17
18
19
20
# File 'lib/cinesync/commands.rb', line 17

def self.open_session_file(path, merge_with_existing = true)
  op = merge_with_existing ? 'merge' : 'replace'
  "cinesync://file/#{op}?path=#{CGI.escape(path)}"
end

.opens_url(*syms) ⇒ Object



8
9
10
11
12
# File 'lib/cinesync/commands.rb', line 8

def opens_url(*syms)
  syms.each do |sym|
    self.class.send(:define_method, :"#{sym}!") {|*args| CineSync::UI.open_url(send(sym, *args)) }
  end
end

.run_script(script_name, query = nil) ⇒ Object



34
35
36
# File 'lib/cinesync/commands.rb', line 34

def self.run_script(script_name, query = nil)
  "cinesync://script/#{URI.escape(script_name)}#{query ? "?#{query}" : ''}"
end