Module: Pair::Api

Extended by:
Api
Includes:
HTTParty
Included in:
Api
Defined in:
lib/pair/api.rb

Instance Method Summary collapse

Instance Method Details

#api_tokenObject



25
26
27
# File 'lib/pair/api.rb', line 25

def api_token
  config[:api_token]
end

#configObject



29
30
31
32
33
34
35
# File 'lib/pair/api.rb', line 29

def config
  @config ||= if File.exists?(config_file)
    YAML.load_file(config_file)[base_uri] || setup_config
  else
    setup_config
  end
end

#config_fileObject



37
38
39
# File 'lib/pair/api.rb', line 37

def config_file
  File.expand_path("~/.pair.yml")
end

#create_session(session) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/pair/api.rb', line 5

def create_session(session)
  post("/v1/sessions", {
    :body => {
      :session => {
        :name         => session.name,
        :viewers      => session.viewers,
        :participants => session.participants,
        :tunnel       => {
          :host_login => session.
        }
      }
    }
  })
end

#join_session(session) ⇒ Object



20
21
22
23
# File 'lib/pair/api.rb', line 20

def join_session(session)
  options = { :query => { :name => session.name, :host => session.host, :format => "json" } }
  get("/v1/sessions/search.json", options)
end

#setup_configObject



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/pair/api.rb', line 41

def setup_config
  config = YAML.load_file(config_file) rescue {}

  print "Please input your API token for #{base_uri}: "
  config[base_uri] = {:api_token => $stdin.gets.chomp}

  File.open(config_file, 'w') do |f|
    f.write(YAML.dump(config))
  end

  config[base_uri]
end