Commits

Patric Harglin  committed b2c9e7e

added leaderboard error handling

  • Participants
  • Parent commits 1c3f45b

Comments (0)

Files changed (3)

File classes/leaderboard.php

 		
 			$max_display_items_val = intval($max_display_items);
 				
-			$apiKey =  cs_get_single_option("api-key", "75965ed0-9d11-11e2-9e96-0800200c9a66");
+			$apiKey =  cs_get_single_option("api-key", "");
 				
 			$baseUrl = 'http://csps1.cubeia.com/operator-api';
 			$globalPath = '';
 						'headers' => array('Authorization' => 'Basic ' . base64_encode("poker:pokerdemo"))
 				)
 				);
+				
+				if( is_wp_error( $response ) ) {
+					$error_message = $response->get_error_message();
+					return "Unable to fetch leaderboard from $baseUrl: $error_message";
+				} 
+				
 		
 				$json = $response["body"];
 				$leaderboard = json_decode($json, false);

File cubeia-social.php

-<?php
-
-/*
- Plugin Name: Cubeia Social
- Description: Plugin for integrating Cubeia Social poker into a WP installation.
- Plugin URI: http://www.cubeiasocial.com/
- License: GPLv2
- Version: 0.6
-*/
-
-/*
- Copyright (C) 2013 Cubeia Ltd  <info@cubeia.com>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License, version 2, as
- published by the Free Software Foundation.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-*/
-
-/*ini_set("display_errors", "On");
-error_reporting(E_ALL);*/
-
-// include logger first
-@include_once dirname(__FILE__) . "/lib/KLogger.php";
-
-// include all classes
-@include_once dirname(__FILE__) . "/classes/api.php";
-@include_once dirname(__FILE__) . "/classes/break.php";
-@include_once dirname(__FILE__) . "/classes/auth.php";
-@include_once dirname(__FILE__) . "/classes/admin.php";
-@include_once dirname(__FILE__) . "/classes/log.php";
-@include_once dirname(__FILE__) . "/classes/mtt-ui.php";
-@include_once dirname(__FILE__) . "/classes/leaderboard.php";
-
-// include global functions
-@include_once dirname(__FILE__) . "/functions.php";
-
-
-/*
- * Make the API globalk and initiate the admin and
- * API classes which sets up further hooks. 
- */
-add_action("init", function() {
-	global $cs_api;
-	$cs_mtt_ui = new CS_MTT_UI();
-	$cs_leaderboard_ui = new CS_LEADERBOARD_UI();
-	$cs_admin = new CS_Admin();
-	$cs_api = new CS_Api();
-	
-});
-
-
-/*
- * Hook into authentication on the "auth cookie" instead of login, 
- * other plugins may bypass login, but probably not the cookie. Call
- * login on the API to create poker auth token.
- */
-add_action("set_auth_cookie", function($auth_cookie, $expire, $expiration, $user_id, $scheme) {
-	global $cs_api;
-	$cs_api->user_login($user_id);
-}, 10, 5);
-
-
-/*
- * Hook into the logout by listening to the clearing of the cookie. Thid way
- * we can still determine what user is acting (as opposed on logout where we don't
- * have a user ID). 
- */
-add_action("clear_auth_cookie", function() {
-	global $cs_api;
-	$cs_api->user_logout();
-});
-
-
-/*
- * Add hook for JS files to be included in the frontend.
- */
-add_action("wp_enqueue_scripts", function() {
-	wp_enqueue_script("momentjs", plugins_url("/js/moment-2.0.0.js", __FILE__ ));
-	wp_enqueue_script("cs-tournaments", plugins_url("/js/cs-tournaments.js", __FILE__ ));
-});
-
-
-/*
- * When we're activeted we'll use global methods to create 
- * our database table and default plugin options.
- */
-register_activation_hook(__FILE__, function() {
-	cs_create_cookie_table();
-	cs_add_default_options();
-});
-
-
-/*
- * Cleanup on deactivation. Delete dtabase table and 
- * remove all options.
- */
-register_deactivation_hook(__FILE__, function() {
-	cs_destroy_cookie_table();
-	cs_remove_default_options();
-});
+<?php
+
+/*
+ Plugin Name: Cubeia Social
+ Description: Plugin for integrating Cubeia Social poker into a WP installation.
+ Plugin URI: http://www.cubeiasocial.com/
+ License: GPLv2
+ Version: 0.7
+*/
+
+/*
+ Copyright (C) 2013 Cubeia Ltd  <info@cubeia.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License, version 2, as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+/*ini_set("display_errors", "On");
+error_reporting(E_ALL);*/
+
+// include logger first
+@include_once dirname(__FILE__) . "/lib/KLogger.php";
+
+// include all classes
+@include_once dirname(__FILE__) . "/classes/api.php";
+@include_once dirname(__FILE__) . "/classes/break.php";
+@include_once dirname(__FILE__) . "/classes/auth.php";
+@include_once dirname(__FILE__) . "/classes/admin.php";
+@include_once dirname(__FILE__) . "/classes/log.php";
+@include_once dirname(__FILE__) . "/classes/mtt-ui.php";
+@include_once dirname(__FILE__) . "/classes/leaderboard.php";
+
+// include global functions
+@include_once dirname(__FILE__) . "/functions.php";
+
+
+/*
+ * Make the API globalk and initiate the admin and
+ * API classes which sets up further hooks. 
+ */
+add_action("init", function() {
+	global $cs_api;
+	$cs_mtt_ui = new CS_MTT_UI();
+	$cs_leaderboard_ui = new CS_LEADERBOARD_UI();
+	$cs_admin = new CS_Admin();
+	$cs_api = new CS_Api();
+	
+});
+
+
+/*
+ * Hook into authentication on the "auth cookie" instead of login, 
+ * other plugins may bypass login, but probably not the cookie. Call
+ * login on the API to create poker auth token.
+ */
+add_action("set_auth_cookie", function($auth_cookie, $expire, $expiration, $user_id, $scheme) {
+	global $cs_api;
+	$cs_api->user_login($user_id);
+}, 10, 5);
+
+
+/*
+ * Hook into the logout by listening to the clearing of the cookie. Thid way
+ * we can still determine what user is acting (as opposed on logout where we don't
+ * have a user ID). 
+ */
+add_action("clear_auth_cookie", function() {
+	global $cs_api;
+	$cs_api->user_logout();
+});
+
+
+/*
+ * Add hook for JS files to be included in the frontend.
+ */
+add_action("wp_enqueue_scripts", function() {
+	wp_enqueue_script("momentjs", plugins_url("/js/moment-2.0.0.js", __FILE__ ));
+	wp_enqueue_script("cs-tournaments", plugins_url("/js/cs-tournaments.js", __FILE__ ));
+});
+
+
+/*
+ * When we're activeted we'll use global methods to create 
+ * our database table and default plugin options.
+ */
+register_activation_hook(__FILE__, function() {
+	cs_create_cookie_table();
+	cs_add_default_options();
+});
+
+
+/*
+ * Cleanup on deactivation. Delete dtabase table and 
+ * remove all options.
+ */
+register_deactivation_hook(__FILE__, function() {
+	cs_destroy_cookie_table();
+	cs_remove_default_options();
+});
 is valid from the first login or authentication of the user.   
 
 == Changelog ==
+= 0.7 =
+* added error handling when fetching leaderboard 
 
 = 0.6 =
 * Added avatar url to login response