/** * @param string $username * @param string $apiToken * @param string $packageUrl * * @return bool * * @throws PackagistServiceHookException */ public static function serviceHook($username, $apiToken, $packageUrl) { $url = static::$_apiUrl . '/api/update-package?username='******'&apiToken=' . $apiToken; $data = json_encode(['repository' => ['url' => $packageUrl]]); $json = Curl::post($url, $data)->setContentType(ContentTypeEnum::JSON)->run()->getJson(); if ($json['status'] == 'error') { throw new PackagistServiceHookException($json['message']); } return true; }
/** * @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; } }
/** * Each code can only be used once * * @param string $code * * @return array * * @throws CurlException * @throws CurlInvalidJsonException */ public function getAccessToken($code) { $url = 'https://' . $this->_serverLocation . '.battle.net/oauth/token'; $data = ['redirect_uri' => $this->_redirectUrl, 'scope' => $this->_getScopes(), 'grant_type' => 'authorization_code', 'code' => $code]; return Curl::post($url, $data)->setBasicAuth($this->_apiKey, $this->_apiSecret)->run()->getJson(); }
/** * @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 array $data * * @return array * * @throws BadRequestException */ protected function post($path, $data = []) { $response = Curl::post(Instagram::API_URL . $path, $data)->run(); return self::_handleResponse($response); }