public function post($endpoint, $data, $options = []) { $uri = Client::endpoint() . $endpoint . Client::getUriOptions($options); $data = json_encode($data); $response = \Httpful\Request::post($uri)->authenticateWith(Client::key(), Client::secret())->addHeaders(Client::headers())->body($data)->send(); return $response; }
private function sendRequest($url, $data, array $options = null, $auth = null, $apiKey = null) { array_merge($this->_headers, $options); if ($this->_method == GET) { $url = $url . http_build_query($data); $this->_result = Request::get($url)->send(); } else { if ($this->_method == POST) { if (isset($apiKey)) { $url .= array_keys($apiKey)[0] . "=" . array_values($apiKey)[0]; } $request = Request::post($url); foreach ($this->_headers as $key => $hdr) { $request = $request->addHeader($key, $hdr); } if ($this->headers["Content-Type"] = "application/x-www-form-urlencoded" and is_array($data)) { $request = $request->body(http_build_query($data)); } else { $request = $request->body($data); } if (isset($auth)) { $request = $request->authenticateWith(array_keys($auth)[0], array_values($auth)[0]); } $this->_result = $request->send(); } } }
function read($pgt_iou) { $response = Request::post(Config::get('pgtservice.endpoint'), array('Username' => Config::get('pgtservice.username'), 'Password' => Config::get('pgtservice.password'), 'PGTIOU' => $pgt_iou), Mime::FORM)->addHeader('Content-Type', 'application/x-www-form-urlencoded')->send(); $dom = new \DOMDocument(); $dom->loadXML($response->raw_body); return $dom->documentElement->textContent; }
/** * @param CreateOrderRequest $request * @return ApiError|CreateOrderResponse */ public function createOrder(CreateOrderRequest $request) { $payload = array('merchantId' => $this->merchantId, 'apiId' => $this->apiId, 'orderId' => $request->getOrderId(), 'payCurrency' => $request->getPayCurrency(), 'payAmount' => $request->getPayAmount(), 'receiveAmount' => $request->getReceiveAmount(), 'description' => $request->getDescription(), 'culture' => $request->getCulture(), 'callbackUrl' => $request->getCallbackUrl(), 'successUrl' => $request->getSuccessUrl(), 'failureUrl' => $request->getFailureUrl()); $formHandler = new \Httpful\Handlers\FormHandler(); $data = $formHandler->serialize($payload); $signature = $this->generateSignature($data); $payload['sign'] = $signature; if (!$this->debug) { $response = \Httpful\Request::post($this->merchantApiUrl . '/createOrder', $payload, \Httpful\Mime::FORM)->expects(\Httpful\Mime::JSON)->send(); if ($response != null) { $body = $response->body; if ($body != null) { if (is_array($body) && count($body) > 0 && isset($body[0]->code)) { return new ApiError($body[0]->code, $body[0]->message); } else { if (isset($body->depositAddress)) { return new CreateOrderResponse($body->orderRequestId, $body->orderId, $body->depositAddress, $body->payAmount, $body->payCurrency, $body->receiveAmount, $body->receiveCurrency, $body->validUntil, $body->redirectUrl); } } } } } else { $response = \Httpful\Request::post($this->merchantApiUrl . '/createOrder', $payload, \Httpful\Mime::FORM)->send(); exit('<pre>' . print_r($response, true) . '</pre>'); } }
/** * @param string $receiptData * @param string $sharedSecret * @return array * @throws IAPServerUnavailableException */ private function postExternal($receiptData, $sharedSecret) { if (!getenv('APPLE_IAP_VERIFY_URL')) { throw new IAPServerUnavailableException('An endpoint for polling apple was not found. Please ensure one is set.', 100021005); } $response = Request::post(getenv('APPLE_IAP_VERIFY_URL'))->body($this->buildFormattedArray($receiptData, $sharedSecret))->sendsType(Mime::JSON)->send(); return json_decode($response->body, true); }
public function publish($topic, $data) { $body = ['topic' => $topic, 'payload' => $data]; try { $request = \Httpful\Request::post('http://localhost:9999/mqtt/publish')->sendsJson()->body(json_encode($body))->send(); } catch (\Exception $e) { } }
/** * @param $login * @param $password * @return string|false */ public function auth($login, $password) { $resp = Request::post($this->config['host'] . $this->config['endpoints']['auth'])->sendsType(Mime::FORM)->body(http_build_query(['login' => $login, 'password' => $password]))->send(); if ($resp->hasErrors()) { return false; } return $resp->body[0]; }
/** * Send the HipChat message. * * @return mixed */ public function send() { $message = $this->message ?: ucwords($this->getSystemUser()) . ' ran the [' . $this->task . '] task.'; $format = $message != strip_tags($message) ? 'html' : 'text'; $query = ['auth_token' => $this->token]; $payload = ['from' => $this->from, 'message' => $message, 'message_format' => $format, 'notify' => true, 'color' => $this->color]; return Request::post('https://api.hipchat.com/v2/room/' . $this->room . '/notification?' . http_build_query($query))->sendsJson()->body(json_encode($payload))->send(); }
/** * 根据详细参数发送企业消息 * @Author Woldy * @DateTime 2016-05-12T09:15:39+0800 * @param [type] $touser [description] * @param [type] $toparty [description] * @param [type] $content [description] * @param [type] $AgentID [description] * @param [type] $ACCESS_TOKEN [description] * @param string $type [description] * @return [type] [description] */ public static function sendMessage($touser, $toparty, $content, $AgentID, $ACCESS_TOKEN, $type = 'text') { //$content=iconv('GB2312', 'UTF-8', $content); // if ($type == 'text') { if (mb_detect_encoding($content, 'UTF-8') != 'UTF-8') { $content = iconv('GB2312', 'UTF-8', $content); } $param = array('touser' => $touser, 'toparty' => $toparty, 'agentid' => $AgentID, "msgtype" => "text", "text" => array("content" => $content)); //var_dump(json_encode($param)); //exit; $response = Request::post('https://oapi.dingtalk.com/message/send?access_token=' . $ACCESS_TOKEN)->body(json_encode($param))->sends('application/json')->send(); if ($response->hasErrors()) { var_dump($response); exit; } if (!is_object($response->body)) { $response->body = json_decode($response->body); } if ($response->body->errcode != 0) { var_dump($response->body); exit; } echo 'send ok'; exit; } }
public function post($url, $data) { $request = \Httpful\Request::post($this->endpointUrl . $url)->expectsJson()->addHeader('Authorization', 'Bearer ' . $this->accessToken); if (!is_null($data)) { $request->sendsJson()->body(json_encode($data)); } $httpResponse = $request->send(); return $httpResponse->body; }
/** * @param string $message * * @return Response */ public function send($message = null) { if (!is_null($message)) { $this->setMessage($message); } /** @var Request $request */ $request = Request::post($this->endpoint, $this->message, 'application/xml'); return $request->withoutAutoParsing()->send(); }
function getToken($secret) { $headers = array("Authorization" => "Basic " . $secret, "Content-Type" => "application/x-www-form-urlencoded"); $response = Request::post($this->apiUrl . "/auth/token")->addHeaders($headers)->body("grant_type=client_credentials")->send(); $resArr = json_decode($response); if (array_key_exists('access_token', $resArr)) { return $resArr->access_token; } }
public function addPropertiesToUser($email, array $properties, array $attributes) { $payload = array('subscriber' => array("uid" => $email, "properties" => $properties, "attributes" => $attributes)); $response = Httpful\Request::post('https://api.boomtrain.net/201507/subscribers/identify')->sendsAndExpects('application/json')->basicAuth('api', $this->apiKey)->body($payload)->sendIt(); if ($response->code != 200) { throw new \Exception($response->body->error); } else { return $response->body; } }
public static function urlOpen($url, $data) { try { $request = \Httpful\Request::post($url); $request->body($data); return $request->sendsForm()->sendIt(); } catch (\Exception $e) { throw new \InvalidArgumentException("Invalid argument to request. [{$e}]"); } }
/** * @param SonGuncellenenIstek $sonGuncellenenIstek * * @return SonGuncellenenCevap; * @throws Exception */ public static function get($sonGuncellenenIstek) { /** @var Response $sonuc */ $sonuc = Request::post('http://www.etkinlik.com.tr/api/v1/etkinlik/son_guncellenenler', $sonGuncellenenIstek->getArray())->sendsType('form')->expectsType('json')->send(); if ($sonuc->body->sonuc == 0) { throw new Exception($sonuc->body->mesaj); } // kayıtları set edelim return new SonGuncellenenCevap($sonuc->body->kayitlar); }
/** * @param array $requestSettings * @return array * @throws \Sellsy\Exception\ServerException */ public function call(array $requestSettings) { try { /** @var Response $httpResponse */ $httpResponse = Request::post(TransportInterface::API_ENDPOINT)->addHeader('Authorization', $this->getAuthenticationHeader())->contentType(Mime::FORM)->body(array('request' => 1, 'io_mode' => 'json', 'do_in' => json_encode($requestSettings)))->send(); } catch (Exception\ConnectionErrorException $e) { throw new ServerException($e->getMessage(), $e->getCode(), $e); } return $this->convertResponseBody($httpResponse->raw_body, $httpResponse->code); }
/** * @return array associative array response * @param array $args array('time' => , 'type' => , 'data' => ) */ public function eventPut($args) { $args = \Cube\Command::prepPayload($args); $req = \Httpful\Request::post($this->collector_uri . '1.0/event/put')->sendsJson()->expectsJson()->body($args); $res = $req->send(); if (array_key_exists('error', $res->body)) { // optionally log error? maybe throw exception? return false; } return true; }
function execute($body, $endpoint = "") { if ($endpoint) { $endpoint = "/{$endpoint}"; } $response = \Httpful\Request::post(DB_HOST . '/' . DB_NAME . $endpoint)->authenticateWith(DB_USER, DB_PASSWORD)->body($body)->expectsJson()->send(); if ($response->body->error) { wp_die($response->body->error[0]->message); } return $response; }
public static function post($url, $data = [], $auth = true) { $api = self::$api; $response = \Httpful\Request::post($api->url . $url); // Will parse based on Content-Type if ($auth) { $response->authenticateWith($api->username, $api->password); } $response = $response->sendsJson()->body(json_encode($data))->send(); return (array) $response->body; }
public static function post($path, $params, $data) { $url = self::joinParams($path, $params); $response = \Httpful\Request::post($url)->body($data)->sendsJson()->send(); if ($response->hasErrors()) { var_dump($response); } if ($response->body->errcode != 0) { var_dump($response->body); } return $response->body; }
public static function execQuery($query) { try { $qEndPoint = self::sparqlEndpoint(); $uri = $qEndPoint . urlencode($query); $json = Request::post($uri)->addHeader("Accept", "application/sparql-results+json")->expectsType('json')->send(); return $json; } catch (Exception $e) { echo 'rdfConnctor.execQuery: ', $e->getMessage(), "\n"; throw new Exception('rdfConnctor.execQuery: ', 0, $e); } }
public function sendResults($success, $results, $errorReport) { $httpBody = array('success' => $success, 'results' => $results, 'errorReport' => $errorReport); try { $response = Request::post($this->base_url . '/experiment')->authenticateWith($this->username, $this->password)->addHeader('X-apikey', $this->apikey)->body(json_encode($httpBody))->send(); } catch (Exception $e) { return array('is_Exception' => true, 'error_message' => $e->getMessage()); } if ($response->code != 200) { return array('is_exception' => true, 'error_message' => "Request failed with HTTP Error " . $response->code); } return array('is_exception' => false, 'result' => (array) json_decode($response->body)); }
/** * Execute the command. * * @return void */ public function handle() { $payload = ['channel' => $this->notification->channel]; if (!empty($this->notification->icon)) { $icon_field = 'icon_url'; if (preg_match('/:(.*):/', $this->notification->icon)) { $icon_field = 'icon_emoji'; } $payload[$icon_field] = $this->notification->icon; } $payload = array_merge($payload, $this->payload); Request::post($this->notification->webhook)->sendsJson()->body($payload)->send(); }
public function postRequest($url, $data = null) { $access_token = $this->config['code']; $request_url = $this->config['endpoint'] . $url; error_log('postRequest ' . $request_url . ' data ' . $data); $response = \Httpful\Request::post($request_url)->addHeader('Authorization', "Bearer {$access_token}")->sendsJson()->body($data)->send(); error_log('postRequest response ' . $response); $response = json_decode($response); if (isset($response->error)) { throw new Exception('eenvoudcrm error : ' . json_encode($response)); } return $response; }
/** * POST command * @return bool true if ok */ public function POST($url, $data) { try { $this->response = Request::post($url, $data, 'xml')->authenticateWith($this->username, $this->password)->expectsType('xml')->send(); } catch (Exception $ex) { \Yii::error($exc->getMessage() . "\n" . $exc->getTraceAsString()); return false; } if ($this->isOk()) { return true; } return false; }
public function create() { $reseller = array("msisdn" => $this->msisdn, "pin" => $this->pin, "balance" => $this->balance); try { $response = \Httpful\Request::post($this->path . "/" . $this->msisdn)->body($reseller)->sendsJson()->send(); } catch (Httpful\Exception\ConnectionErrorException $e) { throw new ResellerException($e->getMessage()); } $data = $response->body; if ($data->status == 'failed') { throw new ResellerException($data->error); } }
public function send_broadcast($text, $btype) { $data = array("text" => $text, "btype" => $btype); try { $response = \Httpful\Request::post($this->path . "/send_broadcast")->body($data)->sendsJson()->send(); } catch (Httpful\Exception\ConnectionErrorException $e) { throw new SMSException($e->getMessage()); } $data = $response->body; if ($data->status == 'failed') { throw new SMSException($data->error); } }
public function add_to_reseller($msisdn, $amount) { $data = array("msisdn" => $msisdn, "amount" => $amount); try { $response = \Httpful\Request::post($this->path . "/reseller")->body($data)->sendsJson()->send(); } catch (Httpful\Exception\ConnectionErrorException $e) { throw new CreditException($e->getMessage()); } $data = $response->body; if ($data->status == 'failed') { throw new CreditException($data->error); } }
/** * @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; }
/** * Interface for performing requests to PromisePay endpoints * * @param string $method required One of the four supported requests methods (get, post, delete, patch) * @param string $entity required Endpoint name * @param string $payload optional URL encoded data query * @param string $mime optional Set specific MIME type. Supported list can be seen here: http://phphttpclient.com/docs/class-Httpful.Mime.html */ public static function RestClient($method, $entity, $payload = null, $mime = null) { // Check whether critical constants are defined. if (!defined(__NAMESPACE__ . '\\API_URL')) { die("Fatal error: API_URL constant missing. Check if environment has been set."); } if (!defined(__NAMESPACE__ . '\\API_LOGIN')) { die("Fatal error: API_LOGIN constant missing."); } if (!defined(__NAMESPACE__ . '\\API_PASSWORD')) { die("Fatal error: API_PASSWORD constant missing."); } if (!is_null($payload)) { if (is_array($payload) || is_object($payload)) { $payload = http_build_query($payload); } // if the payload isn't array or object, leave it intact } $url = constant(__NAMESPACE__ . '\\API_URL') . $entity . '?' . $payload; switch ($method) { case 'get': $response = Request::get($url)->authenticateWith(constant(__NAMESPACE__ . '\\API_LOGIN'), constant(__NAMESPACE__ . '\\API_PASSWORD'))->send(); break; case 'post': $response = Request::post($url)->body($payload, $mime)->authenticateWith(constant(__NAMESPACE__ . '\\API_LOGIN'), constant(__NAMESPACE__ . '\\API_PASSWORD'))->send(); break; case 'delete': $response = Request::delete($url)->authenticateWith(constant(__NAMESPACE__ . '\\API_LOGIN'), constant(__NAMESPACE__ . '\\API_PASSWORD'))->send(); break; case 'patch': $response = Request::patch($url)->body($payload, $mime)->authenticateWith(constant(__NAMESPACE__ . '\\API_LOGIN'), constant(__NAMESPACE__ . '\\API_PASSWORD'))->send(); break; default: throw new Exception\ApiUnsupportedRequestMethod("Unsupported request method {$method}."); } // check for errors if ($response->hasErrors()) { $errors = static::buildErrorMessage($response); switch ($response->code) { case 401: throw new Exception\Unauthorized($errors); break; case 404: throw new Exception\NotFound($errors); default: throw new Exception\Api($errors); break; } } return $response; }