本文整理汇总了PHP中HttpClient::response方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpClient::response方法的具体用法?PHP HttpClient::response怎么用?PHP HttpClient::response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpClient
的用法示例。
在下文中一共展示了HttpClient::response方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleWebhook
/**
* Handles the actual webhook, happens in two steps:
*
* - Retrieves the $webhook_id and $event_id
*
* - Uses the key and secret provided to fetch the event object and casts it to an array
*
* - Calls the callable function with the Event object
*/
private function handleWebhook()
{
$identifier = $this->field('identifier');
if ($identifier !== $this->identifier) {
return;
}
$event_id = $this->field('event_id');
$webhook_id = $this->field('webhook_id');
if (!$event_id || !$webhook_id) {
Log::info($this->patrol, 'Webhook ' . $this->identifier . ' has no event_id or webhook_id');
return;
}
$httpClient = new HttpClient($this->patrol, 'GET', 'webhooks/' . $webhook_id . '/events/' . $event_id);
$response = $httpClient->response();
if (!$response) {
Log::info($this->patrol, 'Retrieving webhook from ' . $httpClient->getUrl() . ' failed');
return;
}
$data = $this->field($response, 'data');
if (!$data) {
Log::info($this->patrol, 'Event has invalid format to be processed: ' . print_r($response, true));
}
$callable = $this->callback;
if (is_callable($callable)) {
$callable($data);
}
}
示例2: _post
/**
* Perform a POST request based on this model
*
* @param string $url
* @param array $data
* @param string $class The class type where the result should be casted to
*
* @return PatrolSdk\Model
*/
protected function _post($url, $data = [], $class = null)
{
$client = new HttpClient($this->patrol, 'post', $url, $data);
$data = $client->response();
if (isset($data['error'])) {
$this->_error($data);
}
if (!isset($data['data'])) {
return $data;
}
$data = $data['data'];
$callee = $class ? $class : get_called_class();
return Util::parseResponseToPatrolObject($this->patrol, $data, $callee, $this->defaults);
}