Exemple #1
0
 /**
  * @param array $params
  *
  * @return array
  *
  * @throws ImdbException
  */
 protected static function _get($params)
 {
     $params = array_filter($params);
     $params['r'] = 'json';
     $params['v'] = '1';
     try {
         $response = Curl::get('http://www.omdbapi.com/', $params)->run()->getJson();
     } catch (CurlException $e) {
         throw new ImdbException($e->getResponse()->getErrorMessage());
     }
     if (isset($response['Response']) && $response['Response'] == 'False') {
         throw new ImdbException($response['Error']);
     }
     return $response;
 }
 /**
  * @param string $path
  * @param array  $data
  *
  * @return array
  * @throws BattleNetException
  */
 protected function _get($path, $data = [])
 {
     if ($this->_responseLocale) {
         $data['locale'] = $this->_responseLocale;
     }
     if ($this->_jsonP) {
         $data['jsonp'] = $this->_jsonP;
     }
     $data['apikey'] = $this->_apiKey;
     try {
         return Curl::get($this->_makeApiUrl($path), $data)->run()->getJson();
     } catch (CurlException $e) {
         $json = $e->getResponse()->getJson();
         $message = isset($json['reason']) ? $json['reason'] : $e->getMessage();
         throw new BattleNetException($message);
     }
 }
 /**
  * @param string $path
  * @param array  $query
  * @param bool   $apiKey
  *
  * @return array
  *
  * @throws SteamException
  */
 protected function _get($path = null, $query = [], $apiKey = true)
 {
     if ($path) {
         $query['format'] = $this->_format;
         if ($apiKey && $this->_apiKey) {
             $query['key'] = $this->_apiKey;
         }
         $service = $this->_getService();
         $path = 'http://api.steampowered.com/' . $service . '/' . $path;
     } else {
         $path = 'http://store.steampowered.com/api/appdetails';
     }
     $curl = Curl::get($path, $query)->run();
     if ($curl->getErrorNumber()) {
         throw new SteamException($curl->getErrorMessage(), $curl->getHttpCode());
     } else {
         return json_decode($curl->getOutput(), true);
     }
 }
 /**
  * @param array $params
  *
  * @return array
  *
  * @throws SickBeardException
  */
 protected function _request($params)
 {
     if ($this->_debug) {
         $params['debug'] = 1;
     }
     if ($this->_profile) {
         $params['profile'] = 1;
     }
     if ($this->_help) {
         $params['help'] = 1;
     }
     if ($this->_callback) {
         $params['callback'] = $this->_callback;
     }
     $url = $this->_url . '/api/' . $this->_apiKey;
     $response = Curl::get($url, $params)->run();
     if ($response->getHttpCode() != 200) {
         throw new SickBeardException('Invalid response');
     }
     $contentType = $response->getContentType();
     if (Strings::contains($contentType, 'json', false)) {
         $array = $response->getJson();
         if (isset($array['result']) && $array['result'] != 'success') {
             throw new SickBeardException($array['message']);
         }
         return $array['data'];
     } else {
         header('Content-Type: ' . $contentType);
         return $response->getOutput();
     }
 }
 /**
  * @param string $path
  *
  * @return array
  *
  * @throws PackagistException
  */
 protected static function _get($path)
 {
     $exception = new PackagistException('Packagist did not respond correctly.');
     try {
         $response = Curl::get(static::$_apiUrl . '/' . $path)->run();
     } catch (CurlException $e) {
         throw $exception;
     }
     if ($response->getHttpCode() != 200) {
         throw $exception;
     }
     return $response->getJson();
 }
 /**
  * @param array $params
  *
  * @return mixed
  *
  * @throws GazelleApiFailureException
  * @throws CurlException
  * @throws CurlInvalidJsonException
  */
 protected function _get($params = [])
 {
     // Go and get a session cookie
     if (!$this->_cookieJar instanceof CookieJar) {
         $login = Curl::post($this->_url . '/login.php', ['username' => $this->_username, 'password' => $this->_password])->run();
         $this->_cookieJar = $login->getCookies();
     }
     // Make the request
     $response = Curl::get($this->_url . '/ajax.php', $params)->setCookies($this->_cookieJar)->run()->getJson();
     if (isset($response['status'])) {
         if ($response['status'] != GazelleApiStatus::SUCCESS) {
             throw new GazelleApiFailureException();
         }
         return $response['response'];
     } else {
         return $response;
     }
 }
Exemple #7
0
 /**
  * @param string $response
  *
  * @return true
  *
  * @throws InvalidInputResponseException
  * @throws InvalidInputSecretException
  * @throws MissingInputResponseException
  * @throws MissingInputSecretException
  * @throws RecaptchaException
  */
 public function check($response)
 {
     $url = self::API . 'api/siteverify';
     $data = ['secret' => $this->_secretKey, 'response' => $response, 'remoteip' => $this->_clientIp];
     try {
         $response = Curl::get($url, $data)->run()->getJson();
     } catch (CurlException $e) {
         throw new RecaptchaException($e->getMessage());
     }
     // Pass
     if (isset($response['success']) && $response['success']) {
         return true;
     }
     // Fail
     $error = isset($response['error-codes'][0]) ? $response['error-codes'][0] : null;
     switch ($error) {
         case 'missing-input-secret':
             throw new MissingInputSecretException('The secret parameter is missing.');
         case 'invalid-input-secret':
             throw new InvalidInputSecretException('The secret parameter is invalid or malformed.');
         case 'missing-input-response':
             throw new MissingInputResponseException('The response parameter is missing.');
         case 'invalid-input-response':
             throw new InvalidInputResponseException('The response parameter is invalid or malformed.');
         default:
             throw new RecaptchaException('Recaptcha error');
     }
 }
Exemple #8
0
 /**
  * @param string $type
  * @param string $path
  * @param array  $data
  * @param array  $auth
  * @param bool   $accessToken
  *
  * @return Response
  *
  * @throws BitlyApiException
  */
 protected function _request($type = 'get', $path = '', $data = [], $auth = [], $accessToken = true)
 {
     $data = array_filter($data);
     $data['format'] = 'json';
     if ($accessToken) {
         $data['access_token'] = $this->_accessToken;
     }
     if ($type == 'get') {
         $curl = Curl::get(self::API . $path, $data);
     } else {
         $curl = Curl::post(self::API . $path, $data);
     }
     if ($auth && count($auth) == 2) {
         $curl->setBasicAuth($auth[0], $auth[1]);
     }
     $response = $curl->run();
     $code = $response->getHttpCode();
     if ($code != 200) {
         throw new BitlyApiException('Something went wrong when talking to Bitly', $code);
     }
     return $response;
 }
 /**
  * @param string $path
  * @param string $accessToken
  *
  * @return array
  * @throws BattleNetException
  */
 protected function _get($path, $accessToken)
 {
     $data = ['access_token' => $accessToken];
     try {
         return Curl::get($this->_makeApiUrl($path), $data)->run()->getJson();
     } catch (CurlException $e) {
         $json = $e->getResponse()->getJson();
         $message = isset($json['reason']) ? $json['reason'] : $e->getMessage();
         throw new BattleNetException($message);
     }
 }
 /**
  * @param string $path
  * @param array  $data
  *
  * @return array
  *
  * @throws BadRequestException
  */
 protected function delete($path, $data = [])
 {
     $response = Curl::delete(Instagram::API_URL . $path, $data)->run();
     return self::_handleResponse($response);
 }