Module: Pair::Api
Instance Method Summary collapse
- #api_token ⇒ Object
- #config ⇒ Object
- #config_file ⇒ Object
- #create_session(session) ⇒ Object
- #join_session(session) ⇒ Object
- #setup_config ⇒ Object
Instance Method Details
#api_token ⇒ Object
25 26 27 |
# File 'lib/pair/api.rb', line 25 def api_token config[:api_token] end |
#config ⇒ Object
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_file ⇒ Object
37 38 39 |
# File 'lib/pair/api.rb', line 37 def config_file File.("~/.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.host_login } } } }) end |
#join_session(session) ⇒ Object
20 21 22 23 |
# File 'lib/pair/api.rb', line 20 def join_session(session) = { :query => { :name => session.name, :host => session.host, :format => "json" } } get("/v1/sessions/search.json", ) end |
#setup_config ⇒ Object
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 |