Kid Crafts Top 10 Ambassadors for [insert_php] echo date(‘F’); [/insert_php]

[insert_php]

$username = ‘greenkidcrafts’;
$api_key = ‘88771a75161f504eb81b0a0bc9ea7f3e’;
$response_type = ‘json’;

// Build and make API call
$data = array(‘min_referrals’ => ‘1’,’is_active’ => ‘1’);
$data = http_build_query($data);
$url = ‘https://getambassador.com/api/v2/greenkidcrafts/88771a75161f504eb81b0a0bc9ea7f3e/json/ambassador/all’;
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $url);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($curl_handle, CURLOPT_POST, TRUE);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl_handle, CURLOPT_FAILONERROR, FALSE);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, FALSE);
$response = curl_exec($curl_handle);
curl_close($curl_handle);

// Example parsing of JSON response
$data = json_decode($response);
$reference = array();
$total_reference = array();
if(strtolower($response_type) == ‘json’)
{
$response = json_decode($response, TRUE);
if(isset($response[‘response’]) && $response[‘response’][‘code’] == ‘200’)
{
if(isset($response[‘response’][‘data’][‘ambassadors’]))
{
foreach($response[‘response’][‘data’][‘ambassadors’] as $ary => $response_row)
{
$name = $response_row[‘first_name’].” “.substr($response_row[‘first_name’],0,1).”.”;
$total_reference [$name] = $response_row[‘total_money_earned’];

$data = array(’email’ => $response_row[’email’],’start_date’ => date(‘Y-m-01’));
$data = http_build_query($data);
$url = ‘https://getambassador.com/api/v2/’.$username.’/’.$api_key.’/’.$response_type.’/ambassador/stats/’;
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $url);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($curl_handle, CURLOPT_POST, TRUE);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl_handle, CURLOPT_FAILONERROR, FALSE);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, FALSE);
$new_response = curl_exec($curl_handle);
curl_close($curl_handle);

// Example parsing of JSON response
if(strtolower($response_type) == ‘json’)
{
// Decode response to array
$new_response = json_decode($new_response, TRUE);

if(isset($new_response[‘response’]) && $new_response[‘response’][‘code’] == ‘200’)
{
// Loop through and output share links
if(isset($new_response[‘response’][‘data’][‘ambassador’][‘stats_summary’]))
{
$reference[$name] = $new_response[‘response’][‘data’][‘ambassador’][‘stats_summary’][‘revenue’][‘approved_sum’];
// print_r($new_response[‘response’][‘data’][‘ambassador’][‘stats_summary’][‘revenue’]);
}
} else {
echo ‘Error, see response dump above.’;
}
}
}
}
} else {
echo ‘Error, see response dump above.’;
}
}
arsort($reference);
echo “

“;
$i=1;
foreach($reference as $key=>$val)
{
if($val==0)
$display = “none”;
echo “

“;
if($i==10)
break;
$i++;
}
echo “
Rank Name Commission Earned
“.$i.” “.$key.” $”.$val.”

“;

echo “

Green Kid Crafts Top Ambassadors of All Time

“;
arsort($total_reference);
echo “

“;
$i=1;
foreach($total_reference as $key=>$val)
{
echo “

“;
if($i==10)
break;
$i++;
}
echo “
Rank Name Commission Earned
“.$i.” “.$key.” $”.$val.”

“;

[/insert_php]

Leave a Reply

Your email address will not be published. Required fields are marked *