Skip to content

Instantly share code, notes, and snippets.

@Rajesh-jai
Last active March 29, 2016 13:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rajesh-jai/f98476576b0af594885a to your computer and use it in GitHub Desktop.
Save Rajesh-jai/f98476576b0af594885a to your computer and use it in GitHub Desktop.
Cricket API PHP sample code
<?php
// use ElephantIO\Client,
// ElephantIO\Engine\SocketIO\Version0X;
// require __DIR__ . '/vendor/autoload.php';
// use Ytake\WebSocket\Io;
require_once 'lzconfig.php';
require_once 'lz.php';
$authData = auth();
if (! $authData) {
echo "Error Auth, Please verify your access details on lzconfig.php \n";
return;
}
print_r($authData);
$token = $authData['access_token'];
/* get Match API data. Allowed card types are micro_card, summary_card and full_card. For more info https://developers.litzscore.com/docs/match_api/ */
print_r(getMatch($token, 'iplt20_2013_g30', 'micro_card'));
/* get RecentMatch API data. Allowed card types are micro_card and summary_card. For more info https://developers.litzscore.com/docs/recent_match_api/ */
// print_r(getRecentMatch($token, 'micro_card'));
/* get RecentSeasonMatch API data. Allowed card types are micro_card and summary_card. For more info https://developers.litzscore.com/docs/recent_match_api/ */
// print_r(getRecentSeasonMatch($token, 'dev_season_2014', 'micro_card'));
/* get RecentSeason API data. For more info https://developers.litzscore.com/docs/recent_season_api/ */
// print_r(getRecentSeason($token));
/* get Schedule API data. Allowed formates are YYYY-MM-DD and YYYY-MM. For more info https://developers.litzscore.com/docs/schedule_api/ */
// print_r(getSchedule($token, 'YYYY-MM-DD'));
/* get Season Schedule API data. Allowed formates are YYYY-MM-DD and YYYY-MM. For more info https://developers.litzscore.com/docs/schedule_api/ */
// print_r(getSeasonSchedule($token, 'dev_season_2014', 'YYYY-MM'));
/* get Season API data. Allowed card type micro_card and summary_card. For more info https://developers.litzscore.com/docs/season_api/ */
// print_r(getSeason($token, 'dev_season_2014', 'micro_card' ));
/* get Season Stats API data. For more info https://developers.litzscore.com/docs/season_stats_api/ */
// print_r(getSeasonStats($token, 'dev_season_2014'));
/* get Season Points API data. For more info https://developers.litzscore.com/docs/season_points_api/ */
// print_r(getSeasonPoints($token, 'dev_season_2014'));
/* get Season Player Stats API data. player_x1 is player key. For more info https://developers.litzscore.com/docs/season_player_stats_api/ */
// print_r(getSeasonPlayerStats($token, 'dev_season_2014', 'player_x1'));
/* get Match Over Summary API data. For more info https://developers.litzscore.com/docs/over_summary_api/ */
// print_r(getMatchSummary($token, 'iplt20_2013_g30'));
/* get News Aaggregation API data. For more info https://developers.litzscore.com/docs/news_aggregation_api/ */
// print_r(getNewsAaggregation($token));
/* get Ball by Ball API data. b_1_1 is over key. For more info https://developers.litzscore.com/docs/ball_by_ball_api/ */
// print_r(getBallByBall($token, 'iplt20_2013_g30', 'b_1_1'));
<?php
require_once 'lzconfig.php';
function auth() {
$fields = array(
'access_key' => LZ_access_key,
'secret_key' => LZ_secret_key,
'app_id' => LZ_app_id,
'device_id' => LZ_device_id
);
$fields_string = '';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
$fields_string=rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, LZ_url.'auth/');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$response = json_decode($response, true);
curl_close($ch);
return $response['auth'];
}
function getData($req_url, $fields){
$url = LZ_url. $req_url. '/?' . http_build_query($fields);
echo "URL: $url \n";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$response = json_decode($response, true);
curl_close($ch);
return $response['data'];
}
function getMatch($access_token, $match_key, $card_type){
$fields = array(
'access_token' => $access_token,
'card_type' => $card_type,
);
echo "Card Type: $card_type \n";
$url = 'match/' .$match_key;
$response = getData($url, $fields);
return $response;
}
function getRecentMatch($access_token, $card_type){
$fields = array(
'access_token' => $access_token,
'card_type' => $card_type,
);
echo "Card Type: $card_type \n";
$url = 'recent_matches';
$response = getData($url, $fields);
return $response;
}
function getRecentSeasonMatch($access_token, $season_key, $card_type){
$fields = array(
'access_token' => $access_token,
'card_type' => $card_type,
);
echo "Card Type: $card_type \n";
$url = 'season/' .$season_key .'/recent_matches';
$response = getData($url, $fields);
return $response;
}
function getRecentSeason($access_token){
$fields = array(
'access_token' => $access_token,
);
$url = 'recent_seasons';
$response = getData($url, $fields);
return $response;
}
function getSchedule($access_token, $formate){
$fields = array(
'access_token' => $access_token,
'formate' => $formate,
);
$url = 'schedule';
$response = getData($url, $fields);
return $response;
}
function getSeasonSchedule($access_token, $season_key, $formate){
$fields = array(
'access_token' => $access_token,
'formate' => $formate
);
$url = 'season/' .$season_key. '/schedule';
$response = getData($url, $fields);
return $response;
}
function getSeason($access_token, $season_key, $card_type){
$fields = array(
'access_token' => $access_token,
'card_type' => $card_type,
);
$url = 'season/' .$season_key;
$response = getData($url, $fields);
return $response;
}
function getSeasonStats($access_token, $season_key){
$fields = array(
'access_token' => $access_token,
);
$url = 'season/' .$season_key. '/stats';
$response = getData($url, $fields);
return $response;
}
function getSeasonPoints($access_token, $season_key){
$fields = array(
'access_token' => $access_token,
);
$url = 'season/' .$season_key. '/points';
$response = getData($url, $fields);
return $response;
}
function getSeasonPlayerStats($access_token, $season_key, $player_key){
$fields = array(
'access_token' => $access_token,
);
$url = 'season/' .$season_key. '/player/'.$player_key .'/stats';
$response = getData($url, $fields);
return $response;
}
function getMatchSummary($access_token, $match_key){
$fields = array(
'access_token' => $access_token,
);
$url = 'match/' .$match_key. '/overs_summary';
$response = getData($url, $fields);
return $response;
}
function getNewsAaggregation($access_token){
$fields = array(
'access_token' => $access_token,
);
$url = 'news_aggregation';
$response = getData($url, $fields);
return $response;
}
function getBallByBall($access_token, $match_key, $over_key){
$fields = array(
'access_token' => $access_token,
);
$url = 'match/' .$match_key. '/balls/' .$over_key;
$response = getData($url, $fields);
return $response;
}
?>
<?php
define('LZ_url', 'https://rest.cricketapi.com/rest/v2/');
define('LZ_access_key', 'you access key');
define('LZ_secret_key', 'you secret key');
define('LZ_app_id', 'your app id');
define('LZ_device_id', 'your device id');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment