本文整理汇总了PHP中Httpful\Request::put方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::put方法的具体用法?PHP Request::put怎么用?PHP Request::put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Httpful\Request
的用法示例。
在下文中一共展示了Request::put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getHttpServer
/**
* @param Request $request
*
* @return HttpServer
*/
public function getHttpServer(Request $request)
{
$url = $request->getUri();
switch ($request->getMethod()) {
case Request::METHOD_POST:
$httpServer = HttpServer::post($url);
break;
case Request::METHOD_PUT:
$httpServer = HttpServer::put($url);
break;
case Request::METHOD_DELETE:
$httpServer = HttpServer::delete($url);
break;
default:
$httpServer = HttpServer::get($url);
break;
}
if ($request->headers) {
$httpServer->addHeaders($request->headers->all());
}
if ($request->getUser()) {
$httpServer->authenticateWith($request->getUser(), $request->getPassword());
}
if ($request->getContent()) {
$httpServer->body($request->getContent());
}
return $httpServer;
}
示例2: put
/**
* {@inheritdoc}
*/
public function put($url, $content = '')
{
$response = Request::put($url)->addHeader("Accept", "application,json")->addHeader("X-TOKEN", $this->api)->body($content)->send();
if ($this->isResponseOk($response->code)) {
return $response->body;
}
}
示例3: put
public function put($endpoint, $data, $options = [])
{
$uri = Client::endpoint() . $endpoint . Client::getUriOptions($options);
$data = json_encode($data);
$response = \Httpful\Request::put($uri)->sendsJson()->authenticateWith(Client::key(), Client::secret())->addHeaders(Client::headers())->body($data)->send();
return $response;
}
示例4: makeRequest
private function makeRequest($url, $method, $parameters)
{
//http://phphttpclient.com/docs/class-Httpful.Request.html
$query = http_build_query($parameters);
$response = Httpful\Request::put($this->platform . $url . "?" . $query)->method($method)->authenticateWith($this->username, $this->password)->expects("plain")->send();
// and finally, fire that thing off!
$message = $response->body;
//$message = ($response->code != 200) ? json_decode($response->body)[0] : $response->body;
return array("url" => $response->request->uri, "code" => $response->code, "response" => $message);
}
示例5: PUT
/**
* PUT command
* @return bool true if ok
*/
public function PUT($url, $data)
{
try {
$this->response = Request::put($url, $data, 'xml')->authenticateWith($this->username, $this->password)->expectsType('xml')->send();
} catch (Exception $exc) {
\Yii::error($exc->getMessage() . "\n" . $exc->getTraceAsString());
return false;
}
if ($this->isOk()) {
return true;
}
return false;
}
示例6: _PUT
public static function _PUT($url, $body = '{}')
{
$real_url = \Marketcloud\Marketcloud::$apiBaseUrl . $url;
$response = \Httpful\Request::put($real_url)->sendsJson()->body($body)->addHeader('Authorization', \Marketcloud\Marketcloud::getAuthorizationHeader())->send();
// We check the response code
// If the code is 401, then the Token might be expired.
// If it is the case, we re-authenticate the client using the stored credentials.
//
if ($response->code == 401) {
// We have to re-authenticate
$auth_response = \Marketcloud\Marketcloud::authenticate();
return self::_PUT($url, $body);
} else {
return $response;
}
}
示例7: rest_core_put_connect
/**
* PUT connect to the Engager Core API
*
* @param string $uri (Uri to REST action)
* @param string $data (Data to send to server)
*/
public function rest_core_put_connect($uri, $data)
{
$response = \Httpful\Request::put($uri)->body($data)->sendsJson()->expectsJson()->apiKey($this->CI->config->item('core_api_key'))->send();
// Response error handling
switch ($response->code) {
case 500:
log_message('error', $response->body);
return $response;
break;
case 403:
log_message('error', $response->body);
return $response;
break;
default:
return $response;
break;
}
return $response;
}
示例8: CallAPI
public static function CallAPI($method, $url, $data = false)
{
$response = null;
switch ($method) {
case "GET":
$response = \Httpful\Request::get($url)->expects("json")->send();
break;
case "POST":
$response = \Httpful\Request::post($url)->body($data)->sendsAndExpects("json")->send();
break;
case "PUT":
$response = \Httpful\Request::put($url)->body($data)->sendsAndExpects("json")->send();
break;
case "DELETE":
$response = \Httpful\Request::delete($url)->body($data)->sendsAndExpects("json")->send();
break;
}
return is_null($response) ? null : $response->body;
}
示例9: callRestfulApi
public function callRestfulApi($method, $path, $data = null)
{
$uri = $this->url . $path;
switch ($method) {
case "POST":
$request = Request::post($uri, $data);
break;
case "PUT":
$request = Request::put($uri, $data);
break;
case "GET":
if ($data) {
$uri .= '?' . http_build_query($data);
}
$request = Request::get($uri);
break;
default:
throw new \Exception("Unsupported method {$method}");
}
$response = $request->send();
return $response->body;
}
示例10: processAction
public function processAction(CRM_Civirules_TriggerData_TriggerData $triggerData)
{
//do the http post process
$uri = $this->getFullUri($triggerData);
$method = $this->getHttpMethod();
$body = http_build_query($this->getBodyParams($triggerData));
switch (strtolower($method)) {
case 'post':
$request = \Httpful\Request::post($uri, $body);
break;
case 'put':
$request = \Httpful\Request::put($uri, $body);
break;
case 'delete':
$request = \Httpful\Request::delete($uri);
break;
case 'head':
$request = \Httpful\Request::head($uri);
break;
case 'patch':
$request = \Httpful\Request::patch($uri, $body);
break;
case 'options':
$request = \Httpful\Request::options($uri, $body);
break;
case 'get':
$request = $response = \Httpful\Request::get($uri);
break;
default:
throw new Exception('Invalid HTTP Method');
}
$request->neverSerializePayload();
$request = $this->alterHttpRequestObject($request, $triggerData);
$response = $request->send();
$this->handleResponse($response, $request, $triggerData);
}
示例11: update
/**
* Updates an existing entity.
* @param Entity $instance
* @return Entity
*/
public function update(Entity $instance)
{
if (!$instance->isAllowedMethod(__FUNCTION__)) {
throw new \DomainException(__FUNCTION__ . ' not allowed on this entity.');
}
$url = sprintf('%s/%s/%s', $this->getApiUrl(), $this->getNetworkId(), $this->getEndpointName($instance));
$response = \Httpful\Request::put($url)->authenticateWith($this->getLogin(), $this->getPassword())->sendsJson()->body($instance)->send();
if ($response->hasErrors()) {
$exception = json_decode($response->raw_body);
throw new \UnexpectedValueException(sprintf("API response raised a '%s' exception with a message: '%s'. Status code %s", $exception->name, $exception->message, $response->code));
}
return $instance;
}
示例12: loadConfig
$config = loadConfig();
$handle = fopen('ip.txt', 'c+');
if ($handle === false) {
return 1;
}
$currentIp = trim(stream_get_contents($handle));
$ip = trim(file_get_contents('https://i.ngx.cc'));
// If the IP checked different from the current IP logged (to file), update
// CloudFlare DNS record for and send and email notification
if ($currentIp !== $ip) {
ftruncate($handle, 0);
fwrite($handle, $ip);
if ($currentIp !== '') {
// Update CloudFlare DNS using API call
$cfPutData = ['content' => $ip, 'type' => 'A', 'name' => $config['cloudflare_domain_name']];
$response = Request::put("https://api.cloudflare.com/client/v4/zones/{$config['cloudflare_zone_id']}/dns_records/{$config['cloudflare_domain_id']}")->sendsJson()->addHeaders(array('X-Auth-Key' => $config['cloudflare_api_key'], 'X-Auth-Email' => $config['cloudflare_email']))->body(json_encode($cfPutData))->send();
if ($response->code !== 200) {
throw new Exception('Attempt to update CloudFlare DNS record failed!');
}
// Send email using Mailgun
$mg = new Mailgun($config['mailgun_api_key']);
$mg->sendMessage($config['mailgun_domain'], ['from' => $config['report_from_email'], 'to' => $config['report_to_email'], 'subject' => 'Home IP has changed', 'text' => 'Ngoc, your new IP is ' . $ip]);
}
}
} catch (Exception $e) {
echo $e->getMessage();
return 1;
} finally {
if ($handle !== null) {
fclose($handle);
}
示例13: changePassword
/**
* @param $params
* @param $token
* @param bool $secure
* @return mixed
* @throws ResponseClientError
* @throws ResponseRedirectionError
* @throws ResponseServerError
* @throws UnknownResponseCodeException
*/
public static function changePassword($params, $token, $secure = true)
{
$uri = static::genUrl(__FUNCTION__, $secure);
$headers = static::getHeaders($token);
$response = \Httpful\Request::put($uri)->sendsJson()->body($params)->addHeaders($headers)->send();
static::checkCode($response->meta_data['http_code'], $response->body);
return $response->body;
}
示例14: void
/**
* Void a payment
* @param GUID $paymentId
* @param int $amount
* @return mixed
*/
public function void($paymentId, $amount)
{
$uri = Braspag::$apiBase . "sales/{$paymentId}/void";
if ($amount != null) {
$uri = $uri . "?amount={$amount}";
}
$response = Request::put($uri)->sendsJson()->addHeaders($this->headers)->send();
if ($response->code == HttpStatus::Ok) {
$voidResponse = new VoidResponse();
$voidResponse->status = $response->body->Status;
$voidResponse->reasonCode = $response->body->ReasonCode;
$voidResponse->reasonMessage = $response->body->ReasonMessage;
$voidResponse->links = $this->parseLinks($response->body->Links);
return $voidResponse;
} elseif ($response->code == HttpStatus::BadRequest) {
Utils::handleApiError($response);
}
return $response->code;
}
示例15: edit
public function edit()
{
$subscriber = array("msisdn" => $this->msisdn, "name" => $this->name, "balance" => $this->balance, "authorized" => $this->authorized, "subscription_status" => $this->subscription_status, "location" => $this->location);
try {
$response = \Httpful\Request::put($this->path . "/" . $this->msisdn)->body($subscriber)->sendsJson()->send();
} catch (Httpful\Exception\ConnectionErrorException $e) {
throw new SubscriberException($e->getMessage());
}
$data = $response->body;
if ($data->status == 'failed') {
throw new SubscriberException($data->error);
}
}