public function fetch_presets() { return self::cache_for('podlove_auphonic_presets', function () { $curl = new Http\Curl(); $curl->request('https://auphonic.com/api/presets.json', array('headers' => array('Content-type' => 'application/json', 'Authorization' => 'Bearer ' . API_Wrapper::$auth_key))); $response = $curl->get_response(); if ($curl->isSuccessful()) { return json_decode($response['body']); } else { return array(); } }); }
public function fetch_broadcast_channels() { return self::cache_for("podlove_adn_broadcast_channels", function () { $curl = new Http\Curl(); $curl->request('https://alpha-api.app.net/stream/0/channels?include_annotations=1&access_token=' . API_Wrapper::$auth_key, array('headers' => array('Content-type' => 'application/json'))); $response = $curl->get_response(); if (!$curl->isSuccessful()) { return array(); } $broadcast_channels = array(); foreach (json_decode($response['body'])->data as $channel) { if ($channel->type == "net.app.core.broadcast" && $channel->you_can_edit == 1) { $title = ''; foreach ($channel->annotations as $annotation) { if ($annotation->type == "net.app.core.broadcast.metadata") { $title = $annotation->value->title; } } $broadcast_channels[$channel->id] = $title; } } return $broadcast_channels; }); }
/** * Fetch list of presets via Auphonic APU. * * Cached in transient "podlove_auphonic_presets". * * @return string */ public function fetch_presets() { $cache_key = 'podlove_auphonic_presets'; if (($presets = get_transient($cache_key)) !== FALSE) { return $presets; } else { if (!($token = $this->get_module_option('auphonic_api_key'))) { return ""; } $curl = new Http\Curl(); $curl->request('https://auphonic.com/api/presets.json', array('headers' => array('Content-type' => 'application/json', 'Authorization' => 'Bearer ' . $this->get_module_option('auphonic_api_key')))); $response = $curl->get_response(); if ($curl->isSuccessful()) { $presets = json_decode($response['body']); set_transient($cache_key, $presets, 60 * 60 * 24 * 365); // 1 year, we devalidate manually return $presets; } else { return array(); } } }