예제 #1
1
파일: client.php 프로젝트: vicioux/apisdk
 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;
 }
예제 #2
1
 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>');
     }
 }
예제 #5
1
 /**
  * @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) {
     }
 }
예제 #7
1
 /**
  * @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];
 }
예제 #8
1
파일: Hipchat.php 프로젝트: laravel/envoy
 /**
  * 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();
 }
예제 #9
0
파일: Message.php 프로젝트: woldy/ddsdk
 /**
  * 根据详细参数发送企业消息
  * @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;
     }
 }
예제 #10
0
 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;
 }
예제 #11
0
 /**
  * @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();
 }
예제 #12
0
 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;
     }
 }
예제 #13
0
 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}]");
     }
 }
예제 #15
0
 /**
  * @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);
 }
예제 #16
0
 /**
  * @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);
 }
예제 #17
0
 /**
  * @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;
 }
예제 #19
0
 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;
 }
예제 #20
0
 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;
 }
예제 #21
0
 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));
 }
예제 #23
0
 /**
  * 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;
 }
예제 #25
0
 /**
  * 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;
 }
예제 #26
0
파일: reseller.php 프로젝트: infercom2/rccn
 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);
     }
 }
예제 #27
0
파일: sms.php 프로젝트: infercom2/rccn
 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);
     }
 }
예제 #28
0
파일: credit.php 프로젝트: infercom2/rccn
 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);
     }
 }
예제 #29
-5
파일: Http.php 프로젝트: dongww/web-monitor
 /**
  * @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;
 }
예제 #30
-5
 /**
  * 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;
 }