Skip to content

Instantly share code, notes, and snippets.

@funkatron
Created November 5, 2011 20:32
Show Gist options
  • Save funkatron/1341981 to your computer and use it in GitHub Desktop.
Save funkatron/1341981 to your computer and use it in GitHub Desktop.
<?php
protected function getAssets(array $opts=null) {
$url = 'https://gimmebar.com/api/v0/public/assets/'.$this->gb_username;
if ($this->gb_collection) {
$url .= '/'.$this->gb_collection;
}
if (!isset($opts)) {
$opts = array();
}
$opts['limit'] = isset($opts['limit']) ? $opts['limit'] : 50;
$url .= '?'.http_build_query($opts);
$ck = $this->cache_prefix.$url;
// check cache
if ($cached = apc_fetch($ck)) {
return $cached;
}
$json = file_get_contents($url);
$assets = json_decode($json);
$assets->username = $this->gb_username;
if (!empty($this->gb_addthis_pubid)) {
$assets->addthis_pubid = $this->gb_addthis_pubid;
}
apc_store($ck, $assets, $this->gb_cache_ttl);
unset($json);
return $assets;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment