class TedLinks
Public Instance Methods
action(url)
click to toggle source
# File lib/tedlinks.rb, line 8 def action(url) uri = URI(@@base + url) return Net::HTTP.get_response(uri).body end
closeSession(gid, pin)
click to toggle source
# File lib/tedlinks.rb, line 83 def closeSession(gid, pin) res = self.action("?f=close&gid="+gid.to_s+"&pin="+pin.to_s).split(",") if(res[0].strip() == "F") then puts "Unable to close the session: "+gid.to_s puts "Error: " + res[1].strip() else puts "Session sucessfully closed" end end
getCurrentState(gid)
click to toggle source
# File lib/tedlinks.rb, line 27 def getCurrentState(gid) res = self.action("?f=state&gid="+gid.to_s).to_i puts res end
getWinningLink(gid)
click to toggle source
# File lib/tedlinks.rb, line 50 def getWinningLink(gid) res = self.action("?f=winn&gid="+gid.to_s).split(",") if(res[0].strip() == "F") then puts "Unable to get last winning link in session: " + gid.to_s else puts res[1].strip() end end
hostSession(username)
click to toggle source
Admin functions
# File lib/tedlinks.rb, line 60 def hostSession(username) res = self.action("?f=gen").split(",") if(res[0].strip() == "F") then puts "Error occured while trying to generate session" return nil else puts "Successfully generated session" gid = res[1].strip() pin = res[2].strip().to_i res = self.action("?f=join&gid="+gid+"&pname="+username) if(res[0].strip() == "F") then puts "Session was created but was unable to join" return nil else puts "Successfully joined session: " + gid player = TedPlayer.new(res[1].strip().to_i, username, gid.to_i) player.setAdmin(pin) return player end end end
joinSession(gid, username)
click to toggle source
General functions
# File lib/tedlinks.rb, line 15 def joinSession(gid, username) res = self.action("?f=join&gid=" + gid.to_s + "&pname="+username).split(",") if (res[0].strip() == "F") then puts "Unable to join session: " + gid.to_s puts res[1].strip() return nil else puts "Successfully joins session: " + gid.to_s return TedPlayer.new(res[1].strip().to_i, username, gid) end end
newRound(gid, pin)
click to toggle source
# File lib/tedlinks.rb, line 103 def newRound(gid, pin) res = self.action("?f=nrnd&gid="+gid.to_s+"&pin="+pin.to_s).split(",") if(res[0].strip() == "F") then puts "Unable to start the session anew" puts "Error: " + res[1].strip() else puts "Session sucessfully restarted" end end
startSession(gid, pin)
click to toggle source
# File lib/tedlinks.rb, line 93 def startSession(gid, pin) res = self.action("?f=start&gid="+gid.to_s+"&pin="+pin.to_s).split(",") if(res[0].strip() == "F") then puts "Unable to start session: "+gid.to_s puts "Error: " + res[1].strip() else puts "Session sucessfully started" end end
submitLink(gid, pid, link)
click to toggle source
# File lib/tedlinks.rb, line 32 def submitLink(gid, pid, link) res = self.action("?f=link&gid="+gid.to_s+"&pid="+pid.to_s+"&pl="+link).split(",") if(res[0].strip() == "F") then puts "Unable to submit link to session: " + gid.to_s else puts "Submitted link sucessfully" end end
submitVote(gid, pid, vote)
click to toggle source
# File lib/tedlinks.rb, line 41 def submitVote(gid, pid, vote) res = self.action("?f=vote&gid="+gid.to_s+"&pid="+pid.to_s+"&v="+vote.to_s).split(",") if(res[0].strip() == "F") then puts "Unable to submit vote to session: " + gid.to_s else puts "Successfully submitted vote" end end