public function sendRawMessage($message) { $this->curlWrapper->addHeader('Content-Type', 'application/json'); $url = $this->baseUrl . 'post'; $payload = array('bot_id' => $this->botId, 'text' => $message); try { $response = $this->curlWrapper->rawPost($url, json_encode($payload)); } catch (\Exception $e) { die($e->getMessage()); } return $response; }
public function getInfoFromFD($fd_url, $access_token) { $curlWrapper = new CurlWrapper(); $curlWrapper->addHeader("Authorization", "Bearer {$access_token}"); $result = $curlWrapper->get($fd_url); return json_decode($result, true); }
/** * To create an API key/secret pair, go to your account adminstation panel * in your phraseanet application. * * @param string $instanceUrl * @param string $apiKey * @param string $apiSecret * @param CurlWrapper $curl */ public function __construct($instanceUrl, $apiKey, $apiSecret, CurlWrapper $curl) { if (!$this->isValidUrl($instanceUrl)) { throw new InvalidArgumentException(sprintf('%s is not a valid url', $instanceUrl)); } $url = rtrim($instanceUrl, '/'); $this->apiEndpointUrl = sprintf('%s%s', $url, self::API_ENDPOINT); $this->oauthAuthorizeEndpointUrl = sprintf('%s%s', $url, self::AUTH_ENDPOINT); $this->oauthTokenEndpointUrl = sprintf('%s%s', $url, self::TOKEN_ENDPOINT); $this->url = $url; $this->apiAccess['key'] = $apiKey; $this->apiAccess['secret'] = $apiSecret; $curl->addOption(CURLOPT_VERBOSE, $this->debug); $this->curl = $curl; }
/** *After the CSR has been uploaded to the Comodo certificate apply API, it * must be authorized by the user. * Call the authorize endpoint in the API and update the respective DB entry. */ private function capiAuthorizeCSR() { $authorize_endpoint = ConfusaConstants::$CAPI_AUTH_ENDPOINT; $postfields_auth = $this->bs_pf(); $postfields_auth["orderNumber"] = $this->order_number; $data = CurlWrapper::curlContact($authorize_endpoint, "post", $postfields_auth); Logger::log_event(LOG_DEBUG, "Authorizing CSR " . $this->order_number . " for signing."); /* the only formal restriction we have is if the API returns 0 for the query */ if (substr($data, 0, 1) == "0") { /* update the database-entry to reflect the autorization-state */ MDB2Wrapper::update("UPDATE order_store SET authorized='authorized' WHERE order_number=?", array('text'), array($this->order_number)); Logger::log_event(LOG_NOTICE, "Authorized certificate with order number " . $this->order_number . ". " . $this->owner_string); } else { Logger::log_event(LOG_WARNING, "Error authorizing CSR " . $this->order_number . " " . "Server said " . $error_parts[0] . " (" . $error_parts[1] . ")"); $msg = "Received an error when authorizing the CSR with orderNumber " . $this->order_number . $data . "\n"; $error_parts = explode("\n", $data, 2); $msg .= $this->capiErrorMessage($error_parts[0], $error_parts[1]); throw new CGE_ComodoAPIException($msg); } }
/** * @param \Kdyby\Curl\CurlWrapper $curl * @param Request $request */ public function __construct(CurlWrapper $curl, Request $request = NULL) { parent::__construct($curl->error . ' ' . $curl->getUrl()->getAuthority(), $request); $this->code = $curl->errorNumber; $this->info = $curl->info; }
public function run() { if (null === $this->_command) { throw new \RuntimeException(self::COMMAND_NOT_SET_ERROR); } $realStartPage = CurlWrapper::getEffectiveUrl($this->_startPage); if ($realStartPage) { echo sprintf(self::START_MESSAGE . PHP_EOL, $realStartPage, memory_get_usage()); $this->_command->crawl($realStartPage, $this->_htmlPage, $this->_parsedPages); $this->_parsedPages->sortByImageCount(); $report = new HtmlReport($this->_parsedPages); echo self::SAVE_REPORT_MESSAGE; $report->create(); echo self::DONE_MESSAGE . PHP_EOL; } else { throw new \HttpException(self::ADDRESS_UNREACHABLE_ERROR); } }
function testCurlWrapper_contactEndpoint() { $url = 'https://10.0.0.3/index.php'; $res = CurlWrapper::curlContactCert($this->defurl, $this->defkey, $this->defcert, $this->defpw, $this->defdata); $this->assertNotNull($res); }
/** * Provision the whole CA chain (the signing CA cert plus the intermediate * CA cert, plus the root CA). * * @see makeCRLAvailabe */ private function makeChainAvailable() { if (Config::get_config('ca_mode') == CA_COMODO) { $root_ca_content = CurlWrapper::curlContact(ConfusaConstants::$CAPI_ROOT_CA); $interm_ca_content = CurlWrapper::curlContact(ConfusaConstants::$CAPI_INTERMEDIATE_CA); $actual_ca_cert = CurlWrapper::curlContact($this->cert_url); /* convert from DER to PEM */ $cert = new Certificate($actual_ca_cert); $ca_chain = $root_ca_content . $interm_ca_content . $cert->getPEMContent(true); file_put_contents($this->cert_path, $ca_chain); } }