/** * Resolve Track URI using the SoundCloud API. * * @return string rawurlencoded * * @throws \October\Rain\Exception\ApplicationException */ public function uri() { $url = $this->property('url'); $cacheKey = 'krisawzm_embed_soundcloud_' . md5($url); if (Cache::has($cacheKey)) { return Cache::get($cacheKey); } $http = Http::get('http://api.soundcloud.com/resolve.json', function ($http) use($url) { $http->data(['url' => $url, 'client_id' => Settings::get('soundcloud_client_id', '')]); }); if ($http->code != 200) { throw new ApplicationException(sprintf('Embed Plugin: SoundCloud API error. Is your Client ID key set? %s', $http->body)); } $response = json_decode($http->body, true); if (!is_array($response)) { throw new ApplicationException('Krisawzm.Embed: SoundCloud API error. Invalid response.'); } if (isset($response['error'])) { throw new ApplicationException(sprintf('Embed Plugin: SoundCloud API error: %s', $response['error'])); } if (!isset($response['uri']) || !is_string($response['uri'])) { throw new ApplicationException('Embed Plugin: SoundCloud API did not respond with a proper URI.'); } Cache::put($cacheKey, $uri = rawurlencode($response['uri']), 4320); return $uri; }
/** * Get list from Settings as array. * * @return array */ protected function getSettingsList() { return array_map('trim', explode(',', Settings::get('list', ''))); }
/** * Returns the full src. * * @return string */ public function src() { return 'https://www.google.com/maps/embed/v1/place?key=' . Settings::get('googlemaps_api_key', '') . '&q=' . rawurlencode($this->property('q')) . '&maptype=' . $this->property('mapType'); }
public function testGoogleMaps() { $this->assertEquals('foo', Settings::get('googlemaps_api_key')); $this->assertEquals('https://www.google.com/maps/embed/v1/place?key=foo&q=Oslo%2C%20Norway&maptype=satellite', (new GoogleMaps(null, ['q' => 'Oslo, Norway', 'mapType' => 'satellite']))->src()); }