SlickText API – PHP REST API

I recently had the opportunity to work with Capital Records to create a one-month promotion for Luke Bryan’s new album. The concept was national sororities can send in a text message to a number and the sorority with the most votes has the opportunity to be selected for a trip to Panama City Beach.

SlickText stores a set of text messages codes, called textwords inside the campaign of your choosing. For this project I took the API key and did a cURL with PHP to the API to get all of the contacts, which is a list of all the voters, with their vote inside the JSON object. Most of the basic cURL code is below to get all of these contacts.


$authorization = base64_encode($username .':'. $password);

$ch = curl_init();
$headers = array(
'Authorization: Basic '.$authorization,
'Content-Type: '.$contentType
);

$version = '1';
$id = $textwords_array_id[$a];
$contentType = 'application/x-www-form-urlencoded';
$url = 'https://api.slicktext.com/v'.$version.'/contacts';
$authorization = base64_encode($username .':'. $password);
$ch = curl_init();

$headers = array(
'Authorization: Basic '.$authorization,
'Content-Type: '.$contentType
);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0);
curl_setopt($ch, CURLOPT_TIMEOUT, 400);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_URL, "https://api.slicktext.com/v1/contacts?limit=99999");
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");

$result = curl_exec($ch);
$ch_error = curl_error($ch);

if ($ch_error) {
echo "cURL Error: $ch_error";
} else {
$json = json_decode($result, true);

foreach ($json['contacts'] as $key => $contacts) {
$contacts_array[] = $contacts;
}
}

curl_close($ch);

After this, I looped through all of the textwords and built the image below. You’ll probably notice some code that’s not being used because 3-4 changes were made to the scope, but the idea is to pick out each value needed to make the table and handle sorting.

luke


$final_array = array();
for($a=0; $a<count($code_greek); $a++){
$id = $code_greek[$a]['id'];
$counter = "0";
for($x=0; $x<count($contacts_array); $x++){ $textwordnmber = $contacts_array[$x]['textword']; if($textwordnmber == $id){ $counter++; } } $b = 'name'; $final_array[$a][$b] = $code_greek[$a]['name']; $b = 'value'; $final_array[$a][$b] = $counter; $b = 'greekletter'; $final_array[$a][$b] = $code_greek[$a]['greekletter']; } function subval_sort($a, $subkey, $reverse = true){ if (!$a){ return array(); } $b = array(); foreach ($a as $k => $v){
$b[$k] = strtolower($v[$subkey]);
}
if ($reverse){
arsort($b);
} else {
asort($b);
}
$c = array();
foreach ($b as $key => $val){
$c[] = $a[$key];
}
return $c;
}

$final_array = subval_sort($final_array, 'value');

$vote = 0;

for($f=0; $f<count($final_array); $f++){
$vote += $final_array[$f]['value'];
}

$rank = 1;

for($f=0; $f<count($final_array); $f++){ $single_value = $final_array[$f]['value']; $single_name = $final_array[$f]['name']; $single_greekletter = $final_array[$f]['greekletter']; ?>

// begin table




 $rank++;
}

suggested dose by doctors healthy people, and 5mg of aging adults and malnourished patients, together with those with liver failure. The drug is usually recommended to be taken http://www.theirishmanwhiskey.com/tour/ right before going to bed.