/**
  * 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;
 }
Exemple #2
0
 protected function loadChangelog()
 {
     $uri = 'https://raw.githubusercontent.com/octobercms/october/master/CHANGELOG.md';
     $log = Http::get($uri);
     if ($log == '' || $log->code !== 200) {
         throw new SystemException(sprintf(Lang::get('feegleweb.changelog::lang.log.load_error'), $uri));
     }
     $this->changelog = ['precise' => $this->slicePrecise($log), 'recent' => $this->sliceRecent($log)];
 }
Exemple #3
0
 /**
  * Makes a request to the plugin authors message service
  */
 public function request($last_id)
 {
     $last_id = $last_id ? $last_id : 0;
     //echo $this->url . $this->plugin . '/' . $last_id . '<br />';
     //return;
     $response = Http::get($this->url . $this->plugin . '/' . $last_id, function ($http) {
         $http->setOption(CURLOPT_FORBID_REUSE, true);
         $http->header('User-Agent', 'KurtJensen-AuthNotice/V1');
         $http->noRedirect();
         $http->timeout(3600);
     });
     return $this->processResponse($response);
 }
 /**
  * Load vCalendar from URL and parse into an array.
  *
  * @param   string  $url
  * @param   bool    $skipCache
  * @return  array
  * @throws  SystemException
  */
 public static function getFromUrl($url, $skipCache = false)
 {
     $url = str_replace('webcal://', 'https://', $url);
     $cacheKey = 'VCalendar::' . md5($url);
     $vcalendar = $skipCache ? null : Cache::get($cacheKey);
     if (!$vcalendar) {
         $response = Http::get($url, function (Http $http) {
             $http->setOption(CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.0 Safari/537.36');
         });
         if ($response->code != 200) {
             throw new SystemException('Could not load vcalendar from URL', $response->code);
         }
         $vcalendar = $response->body;
         Cache::put($cacheKey, $vcalendar, 60);
     }
     // Glue multiple line values and split for parsing
     $lines = explode("\r\n", str_replace(['\\,', "\r\n "], [',', ''], $vcalendar));
     $events = [];
     $event = false;
     foreach ($lines as $line) {
         if ($line == 'BEGIN:VEVENT') {
             // Start parsing new event
             $event = [];
             continue;
         } else {
             if ($event === false) {
                 // Skip line if we're not parsing an event
                 continue;
             } else {
                 if ($line == 'END:VEVENT') {
                     // Event parsed
                     $events[] = $event;
                     $event = false;
                     continue;
                 }
             }
         }
         list($property, $value) = explode(':', $line, 2);
         $propertyParts = explode(';', $property);
         $property = array_shift($propertyParts);
         // Parse data
         switch ($property) {
             case 'CREATED':
             case 'DTEND':
             case 'DTSTAMP':
             case 'DTSTART':
             case 'LAST-MODIFIED':
                 $value = self::parseDate($value);
                 break;
             case 'UID':
                 $event['ID'] = self::parseId($value);
                 break;
             case 'DESCRIPTION':
                 $value = str_replace('\\n', "\n", $value);
                 break;
         }
         if (count($propertyParts)) {
             $properties = [];
             foreach ($propertyParts as $part) {
                 list($partName, $partValue) = explode('=', $part);
                 $properties[$partName] = $partValue;
             }
             $event[$property] = ['properties' => $properties, 'value' => $value];
         } else {
             $event[$property] = $value;
         }
     }
     return $events;
 }
 /**
  * Communicate with the paypal endpoint
  */
 private function postData($endpoint, $fields)
 {
     return Http::post('https://' . $endpoint, function ($http) use($fields) {
         $http->noRedirect();
         $http->timeout(30);
         $http->data($fields);
     });
 }
Exemple #6
0
 /**
  * Add a single option to the request.
  *
  * @param string $option
  * @param string $value
  * @static 
  */
 public static function setOption($option, $value = null)
 {
     return \October\Rain\Network\Http::setOption($option, $value);
 }