Skip to content

Instantly share code, notes, and snippets.

@funkatron
Created October 13, 2011 22:45
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 funkatron/1285760 to your computer and use it in GitHub Desktop.
Save funkatron/1285760 to your computer and use it in GitHub Desktop.
<?php
// generate skip values
$skips = array();
for ($x=0; $x < 900; $x++) {
$skips[] = $x;
}
$skip = $skips[array_rand($skips)];
$assets_json = file_get_contents('https://gimmebar.com/api/v0/public/assets/funkatron/hilarious-adorable?limit=50&skip='.$skip);
$assets = json_decode($assets_json, true);
$imgs = array();
// because there's a bug in the api call (derp), we have to extract image assets
foreach($assets['records'] as $asset) {
if ($asset['asset_type'] === 'image') {
// shorten up the title to keep the message short-ish
if (strlen($asset['title']) > 95) {
$asset['title'] = substr($asset['title'], 0, 91).'...';
}
$imgs[] = array('title'=>$asset['title'], 'url'=>$asset['short_url']);
}
}
// get a random image from the array
$img = $imgs[array_rand($imgs)];
// make the SMS content
if ($img) {
$msg = "{$img['title']}\n{$img['url']}\n- Gimme Bar loves you";
} else {
die(); // oh shit
}
// ************ START OUTPUT ***************
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<Sms><?php echo $msg ?></Sms>
</Response>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment