예제 #1
0
 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $username = Token::get(self::name, $userid);
     $request = new HTTP_Request2('http://open.dapper.net/transform.php?dappName=CodeChefProblemsSolved&transformer=JSON&v_username=' . $username);
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $score = json_decode($response)->fields->solved[32]->value;
     Score::update(self::name, $userid, $score);
 }
예제 #2
0
 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $username = Token::get(self::name, $userid);
     $request = new HTTP_Request2('https://hacker-news.firebaseio.com/v0/user/' . $username . '.json');
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $karma = json_decode($response)->karma;
     Score::update(self::name, $userid, $karma);
 }
예제 #3
0
 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $lastFMUsername = Token::get(self::name, $userid);
     $request = new HTTP_Request2('http://ws.audioscrobbler.com/2.0/?method=user.getinfo&user='******'&api_key=' . LASTFM_APP_ID . '&format=json');
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $playcount = trim(json_decode($response)->user->playcount);
     Score::update(self::name, $userid, $playcount);
     //Update in database
 }
예제 #4
0
 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $id = Token::get(self::name, $userid);
     $request = new HTTP_Request2('https://api.stackexchange.com/2.1/users/' . $id . '?site=askubuntu&key=' . STACKEXCHANGE_KEY);
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $reputation = json_decode($response)->items[0]->reputation;
     Score::update(self::name, $userid, $reputation);
     //Update in database
 }
예제 #5
0
 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $token = Token::get(self::name, $userid);
     //we don't actually need this
     $request = new HTTP_Request2('https://api.github.com/users/' . $userid);
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $score = json_decode($response)->followers;
     Score::update(self::name, $userid, $score);
 }
예제 #6
0
 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $access_token = Token::get(self::name, $userid);
     $request = new HTTP_Request2("https://graph.facebook.com/me/subscribers?access_token={$access_token}");
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $subscribersCount = json_decode($response)->summary->total_count;
     Score::update(self::name, $userid, $subscribersCount);
     //Update in database
 }
예제 #7
0
 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $twitterScreenName = Token::get(self::name, $userid);
     $request = new HTTP_Request2('https://api.twitter.com/1/users/show.json?screen_name=' . $twitterScreenName);
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $followers_count = json_decode($response)->followers_count;
     Score::update(self::name, $userid, $followers_count);
     //Update in database
 }
예제 #8
0
 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $username = Token::get(self::name, $userid);
     //More information at http://geekraj.com/wordpress/?p=278
     //see http://geekraj.com/euler/euler.js
     $request = new HTTP_Request2('http://www.geekraj.com/euler/getscore.php?id=' . $username);
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $score = json_decode(str_replace("'", '"', substr($response, 12, -2)))->score;
     $score = substr($score, 7);
     Score::update(self::name, $userid, $score);
 }
예제 #9
0
 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $request = new HTTP_Request2('http://gitscore.com/user/' . $userid . '/calculate');
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $score = json_decode($response)->scores->total;
     if (!$score) {
         echo "User not in gitscore, try a little later\n";
         return false;
     }
     Score::update(self::name, $userid, $score);
     //Update in database
 }
예제 #10
0
 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $id = Token::get(self::name, $userid);
     $request = new HTTP_Request2('http://api.klout.com/v2/identity.json/twitter?screenName=' . $id . '&key=' . KLOUT_APP_KEY);
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $id = json_decode($response)->id;
     $request = new HTTP_Request2('http://api.klout.com/v2/user.json/' . $id . '/score?key=' . KLOUT_APP_KEY);
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $score = (int) json_decode($response)->score;
     Score::update(self::name, $userid, $score);
     //Update in database
 }
예제 #11
0
 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $username = Token::get(self::name, $userid);
     $request = new HTTP_Request2('http://open.dapper.net/transform.php?dappName=ScoreFromSpoj&transformer=JSON&v_username='******' ');
     $score = substr($score, 1, $spacePosition - 1);
     Score::update(self::name, $userid, $score);
 }
예제 #12
0
 /**
  * Checks if round is ready to be saved. If not, displays round edit page with information already inputted. If yes, attempts to update selected round and related scores.
  *
  * @param int $id Id of selected round.
  */
 public static function update($id)
 {
     $player = self::get_user_logged_in();
     if (!$player) {
         View::make('player/login.html', array('error' => 'Vain kirjautuneet käyttäjät voivat muokata ratoja.'));
     }
     $params = $_POST;
     $players = Player::all();
     $course = Course::find($params['course']);
     $courses = Course::all();
     $played = $params['played'];
     $round = Round::find($id);
     $holes = Hole::find_by_course($course->id);
     $scores = Score::find_by_round($id);
     $numberOfPlayers = sizeof($scores);
     if ($params['course'] != $params['course_orig']) {
         // If course selection has changed we need to display edit page again with new information.
         $playerScores = array();
         $numberOfHoles = Hole::count_holes($params['course_orig']);
         for ($i = 1; $i <= $numberOfPlayers; $i++) {
             $holeScores = array();
             for ($j = 1; $j <= $numberOfHoles; $j++) {
                 $holeScores[] = $params['p' . $i . '_h' . $j];
             }
             $playerScores[] = array('player' => Player::find($params['player_' . $i]), 'holes' => $holeScores);
         }
         View::make('round/edit.html', array('numberOfPlayers' => $numberOfPlayers, 'players' => $players, 'course' => $course, 'holes' => $holes, 'courses' => $courses, 'playerScores' => $playerScores, 'round' => $round, 'scores' => $scores, 'played' => $played));
     } else {
         $attributes = array('courseId' => $params['course'], 'played' => $params['played']);
         $playerScores = array();
         $numberOfHoles = Hole::count_holes($params['course_orig']);
         $round = new Round(array_merge(array("id" => $round->id), $attributes));
         $errors = $round->errors();
         if (count($errors) == 0) {
             $round->update();
             for ($i = 1; $i <= $numberOfPlayers; $i++) {
                 $holeScores = array();
                 $scoreId = $params['score_' . $i];
                 for ($j = 1; $j <= $numberOfHoles; $j++) {
                     $hole = Hole::find_by_course_and_holenumber($params['course_orig'], $j);
                     $holeScores[] = array('throws' => $params['p' . $i . '_h' . $j], 'holeId' => $hole->id, 'holenumber' => $j);
                 }
                 $score = new Score(array('id' => $scoreId, 'playerId' => $params['player_' . $i], 'roundId' => $round->id, 'scores' => $holeScores));
                 $score->update();
             }
             Redirect::to('/round/' . $round->id, array('message' => 'Kierrosta muokattu.'));
         } else {
             View::make('round/new.html', array('errors' => $errors, 'attributes' => $attributes));
         }
     }
 }