/** * Get the access token. * * @return string * @throws InvalidObjectException */ protected function getAccessToken() { $configParams = $this->getConfigParams(); $formParams = ['form_params' => [self::CONFIG_CLIENT_ID => $configParams[self::CONFIG_CLIENT_ID], self::CONFIG_CLIENT_SECRET => $configParams[self::CONFIG_CLIENT_SECRET], self::CONFIG_SCOPE => $configParams[self::CONFIG_SCOPE], self::CONFIG_GRANT_TYPE => $configParams[self::CONFIG_GRANT_TYPE]]]; $response = $this->guzzle->post($configParams[self::CONFIG_AUTH_URL], $formParams); if (false == $response instanceof ResponseInterface) { throw new InvalidObjectException('Incorrect Response'); } return json_decode($response->getBody())->access_token; }
private function getMoney($idTask) { $client = new GuzzleHttp\Client(); $post = ['ajax' => 1, 'id' => $idTask, 'page' => 'check', 'rand' => rand(1, 99999999999.0)]; $money = $client->post($this->config->item('url') . 'index.php?act=ajax', ['headers' => ['user-agent' => $this->config->item('agent'), 'cookie' => 'hash=' . $this->config->item('cookie')['hash'] . '; id=' . $this->config->item('cookie')['id'] . '; r=1; g=1466098105', 'X-Requested-With' => 'XMLHttpRequest'], 'form_params' => $post]); return $money->getBody(); }
public function handle($request, Closure $next) { // Проверяем есть ли ключ oauth $redis = \App::make('redis'); if ($redis->exists('docs_token')) { return $next($request); } try { // Если ключа нет, пробуем его получить $client = new \GuzzleHttp\Client(); $response = $client->post(\Config::get('docs-api.server') . 'api/oauth/access_token', ['body' => ['client_secret' => \Config::get('docs-api.secret'), 'client_id' => 'hotdocs']]); $json = $response->json(); if (isset($json['access_token']) && isset($json['expires_in'])) { // Сохраняем ключ и успешно завершаем фильтр $redis->set('docs_token', $json['access_token']); $redis->expire('docs_token', $json['expires_in'] - 1); return $next($request); } else { throw new \Exception("Response error"); } } catch (\Exception $e) { // Если что-то не так выбрасываем на страницу ошибки abort(503); } }
public function retrieveResponse(UriInterface $endpoint, $requestBody, array $extraHeaders = array(), $method = 'POST') { $client = new \GuzzleHttp\Client(); if ($method == "POST") { try { $res = $client->post($endpoint, ['config' => ['curl' => [CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false]], 'headers' => $extraHeaders, 'body' => $requestBody]); return (object) array("statusCode" => $res->getStatusCode(), "response" => $res->getBody()); } catch (\GuzzleHttp\Exception\BadResponseException $e) { if ($e->hasResponse()) { return (object) array("statusCode" => $e->getResponse()->getStatusCode(), "response" => $e->getResponse()->getBody()); } } catch (\GuzzleHttp\Exception\RequestException $e) { return (object) array("statusCode" => "", "response" => "Invalid URL"); } } else { try { $res = $client->get($endpoint, ['config' => ['curl' => [CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false]]]); return (object) array("statusCode" => $res->getStatusCode(), "response" => $res->getBody()); } catch (\GuzzleHttp\Exception\BadResponseException $e) { if ($e->hasResponse()) { return (object) array("statusCode" => $e->getResponse()->getStatusCode(), "response" => $e->getResponse()->getBody()); } } catch (\GuzzleHttp\Exception\RequestException $e) { return (object) array("statusCode" => "", "response" => "Invalid URL"); } } }
function getCost($origin, $destination, $weight, $courier) { $client = new \GuzzleHttp\Client(); $response = $client->post($this->base_url . 'cost', ['body' => ['key' => $this->apikey, 'origin' => $origin, 'destination' => $destination, 'weight' => $weight, 'courier' => $courier]]); $body = $response->json(); return $body; }
function post_guzzle($url, $params) { $data = json_encode($params); $client = new GuzzleHttp\Client(); $response = $client->post($url, ['body' => $data]); return $response->json(); }
public function request($method, $request_body) { $client = new GuzzleHttp\Client(); $response = $client->post($this->url, array('verify' => false, 'headers' => array('X-EBAY-API-COMPATIBILITY-LEVEL' => $this->compatability_level, 'X-EBAY-API-DEV-NAME' => $this->dev_id, 'X-EBAY-API-APP-NAME' => $this->app_id, 'X-EBAY-API-CERT-NAME' => $this->cert_id, 'X-EBAY-API-SITEID' => $this->site_id, 'X-EBAY-API-CALL-NAME' => $method), 'body' => $request_body)); $body = $response->xml(); return $body; }
public static function FormSubmit($form) { if (WEBHOOKS_URL != '') { $client = new GuzzleHttp\Client(); $client->post(WEBHOOKS_URL, ['headers' => ['X-Action' => 'Form.Submit'], 'json' => $form]); } }
public function searchDescription($description) { $URL = "http://sap.prefeitura.unicamp.br/sap/pesquisa_achados_perdidos.jsf?javax.faces.ViewState={$this->viewState}&javax.faces.partial.ajax=true&javax.faces.partial.execute=%40all&javax.faces.partial.render=mainForm%3AmainOutputPanel&javax.faces.source=mainForm%3Aj_idt44&mainForm=mainForm&mainForm%3AfilterDataFinal_input=&mainForm%3AfilterDataInicio_input=&mainForm%3AfilterIdentificacao={$description}&mainForm%3AfilterLocalEncontrado=&mainForm%3Aj_idt34_focus=&mainForm%3Aj_idt34_input=&mainForm%3Aj_idt44=mainForm%3Aj_idt44"; $client = new \GuzzleHttp\Client(['cookies' => True, 'headers' => ['Cookie' => $this->cookie]]); $response = $client->post($URL); return $response->getBody()->getContents(); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @throws App * * @return mixed */ public function handle($request, Closure $next) { if (Session::has('access_token') && Session::get('expired_at') <= Carbon::now()->format('Y-m-d H:i:s')) { $credentials['access_token'] = Session::get('access_token'); $credentials['refresh_token'] = Session::get('refresh_token'); $credentials['grant_type'] = 'refresh_token'; $credentials['HTTP_HOST'] = env('OAUTH_HOST', 'apimanager'); $api_url = env('API_URL', 'http://capcusapi'); $api = new \GuzzleHttp\Client(['base_url' => $api_url]); $api_result = $api->post($api_url . '/authorized/client', ['form_params' => $credentials]); $result = json_decode($api_result->getBody(), true); if ($result['status'] != 'success') { Redirect::route(env('ROUTE_LOGIN', 'login'))->send(); } else { Session::put('access_token', $result['data']['access_token']); Session::put('refresh_token', $result['data']['refresh_token']); Session::put('expired_at', $result['data']['expired_at']); if (isset($result['data']['whoami'])) { Session::put('me', $result['data']['whoami']); } } } elseif (!Session::has('access_token')) { Redirect::route(env('ROUTE_LOGIN', 'login'))->send(); } return $next($request); }
/** * * @param string $method * @param string $url * @param string $params * @return mixed */ public function call($method, $url, $params) { $guzzle = new \GuzzleHttp\Client(array('base_url' => $this->root, 'defaults' => array('headers' => array('X-API-KEY' => $this->apiKey, 'User-Agent' => 'TutoPHP/' . self::API_VERSION)))); if (isset($this->apiUsername) && !empty($this->apiUsername) && isset($this->apiSecret) && !empty($this->apiSecret)) { $_params = array_merge($params, array('auth' => array($this->apiUsername, $this->apiSecret))); } else { $_params = $params; } try { switch ($method) { case 'get': $this->response = $guzzle->get($url, $_params); break; case 'post': $this->response = $guzzle->post($url, $_params); break; } } catch (\GuzzleHttp\Exception\ClientException $ex) { $this->response = $ex->getResponse(); $json = $ex->getResponse()->json(); if (!isset($json['error'])) { throw new Tuto\Tuto_Error('We were unable to decode the JSON response from the Tuto API: ' . $json); } else { throw $this->castError($json); } return $json; } return $this->response->json(); }
public function unfollow(Request $request) { $token = $request->session()->get('x-auth-token'); $id = $request->input('id'); $api = new \GuzzleHttp\Client(['base_uri' => env('API_URL'), 'verify' => false, 'headers' => ['X-Auth-Token' => $token]]); $unfollow = $api->post('followers/unfollow', ['form_params' => ['user' => $id]]); $status = json_decode($unfollow->getBody(), true); return $status; }
public function handle($message) { $client = new \GuzzleHttp\Client(); try { $client->post($this->url, ['body' => json_encode(['text' => $message, 'username' => $this->username, 'icon_url' => $this->icon, 'attachments' => $this->attachments])]); } catch (\Exception $e) { throw new \Manavo\Chatty\ChattyException($e->getMessage(), $e->getCode(), $e); } }
private function getVkPhotoData($fileName) { $vkApi = Vk\Core::getInstance()->apiVersion('5.5')->setToken('b4320e4b95f057e4779fc2eb5b56f0d39366ace73099cde01515bf02c3869c1d1c70437d80ae61edad3a9'); $vkPhotoUploadURL = $vkApi->request('ads.getUploadURL', ['ad_format' => 2])->getResponse(); if ($vkPhotoUploadURL) { $guzzle = new \GuzzleHttp\Client(); return $guzzle->post($vkPhotoUploadURL, ['body' => ['file' => fopen($fileName, 'r')]])->json(['object' => true]); } return false; }
private function sendSlackMessage($message) { $config = DI::getDefault()->getConfig(); $client = new GuzzleHttp\Client(); $slackEndpoint = $config->monitor->slackHook; $payload = json_encode(array("text" => $message)); $response = $client->post($slackEndpoint, ['body' => $payload]); $responseText = $response->getBody($asString = true); return $responseText; }
public function handle($message) { $client = new \GuzzleHttp\Client(); try { $url = sprintf('https://api.hipchat.com/v1/rooms/message?auth_token=%s', $this->token); $client->post($url, ['body' => ['room_id' => $this->room_id, 'message' => $message, 'message_format' => 'text', 'notify' => $this->notify, 'color' => $this->color, 'from' => $this->from]]); } catch (\Exception $e) { throw new \manavo\Chatty\ChattyException($e->getMessage(), $e->getCode(), $e); } }
/** * @param string $method * @param array $params * * @return string * * @throws Exception */ public function request($method, $params = []) { $client = new \GuzzleHttp\Client(); $response = $client->post($this->getUrl($method), ['query' => $params]); if ($response->getStatusCode() == 200) { return (string) $response->getBody(); } else { throw new Exception('Sms.ru problem. Status code is ' . $response->getStatusCode(), $response->getStatusCode()); } }
public function outgoingOrder(Request $request, $id) { $organization = Organization::findOrFail($id); $order = OrganizationOrder::orderBy('created_at', 'desc')->first(); $message = "Today's lunch will be " . $order->restaurant()->name . "!"; $message .= " Make sure to <" . route('lineitem.create', [$order->id]) . "|put in your order>!"; $body = json_encode(['text' => $message]); $client = new \GuzzleHttp\Client(); $res = $client->post($organization->incoming_slack_link, ['body' => $body]); return redirect()->route('organization.view', [$organization->id]); }
function oauth_access_token($shared_secret, $code) { $url = "https://" . $this->_shopUrl . "/admin/oauth/access_token"; $config['defaults']['headers']['X-Shopify-Access-Token'] = $this->_apiKey; $client = new \GuzzleHttp\Client($config); $options['body'] = array('client_id' => $this->_apiKey, 'client_secret' => $shared_secret, 'code' => $code); $options['verify'] = False; $response = $client->post($url, $options); $postBody = $response->json(); return $postBody['access_token']; }
/** * Make request */ static function request($uri, $method) { $client = new GuzzleHttp\Client(); try { $resp = $client->post($url); $resp = $resp->json(); return $resp; } catch (Exception $e) { var_export($e->getMessage()); } }
/** * @param Interesant $interesant * @return bool */ public function saveInteresant($interesant) { $serializer = new \Itav\Component\Serializer\Serializer(); $params['interesant'] = $serializer->normalize($interesant); $client = new \GuzzleHttp\Client(); $res = $client->post("http://interesant.dev/add", ['form_params' => $params]); if ($res->getStatusCode() == 200) { return true; } return false; }
/** * autenticacion * @return <string> */ public function authenticate($username, $password) { $client = new GuzzleHttp\Client(); $body['email'] = $username; $body['password'] = $password; $res = $client->post($this->host . "/v2/users/authenticate", ['body' => json_encode($body)]); // echo $res->getBody(); // echo $res->getStatusCode(); $af_2fa_token = $res->getHeader('x-app-sign-request'); return $af_2fa_token; }
public function request($parameters) { $this->parameters = array_merge($this->parameters, $parameters); $this->checkParameters($this->parameters); $client = new \GuzzleHttp\Client(); $response = $client->post($this->getEndPoint('payment-requests/'), ['headers' => array('X-Api-Key' => $this->api_key, 'X-Auth-Token' => $this->auth_token), 'form_params' => $this->parameters])->getBody()->getContents(); $response = json_decode($response); if ($response->success) { $this->response = $response; } return $this; }
private function request($path, $method, array $data = array()) { // Setup the Guzzle client with auth, and base url $client = new \GuzzleHttp\Client(['base_url' => $this->api_url, 'defaults' => ['auth' => [$this->email, $this->token]]]); // Send any POST data if ($method === 'post') { $response = $client->post('/' . $this->api_version . $path, ['body' => json_encode($data), 'headers' => ['Content-Type' => 'application/json']]); return $response->getStatusCode() == 200; } // Default to GET return $client->get('/' . $this->api_version . $path)->json(); }
/** * Merge field data into resource. * * @param array $values An array of the data to merge into the resource. * * @throws \WebMerge\Exceptions\Exception * * @return \WebMerge\ResponseData */ public function fields(\Closure $values) { $client = new \GuzzleHttp\Client(['base_uri' => self::API_ENDPOINT, 'query' => array_filter(['test' => $this->test, 'download' => $this->download])]); $merge_path = $this->id . '/' . $this->key; $response = null; try { $response = $client->post($merge_path, ['json' => $values()]); } catch (\Exception $e) { throw new \WebMerge\Exceptions\Exception($e->getMessage()); } return new \WebMerge\ResponseData($response); }
private function sendMail() { $res = null; $httpConfig = []; if ($this->configs["service-name"] === "mailgun") { $httpConfig = ['defaults' => ['auth' => ['api', $this->configs["api-key"]]]]; } $httpClient = new \GuzzleHttp\Client($httpConfig); $httpClient->setDefaultOption('verify', false); $res = $httpClient->post('https://api.mailgun.net/v3/' . $this->configs["domain-name"] . '.mailgun.org/messages', ['body' => ['from' => $this->configs["from"], 'to' => $this->configs["to"], 'subject' => $this->configs["subject"], 'text' => $this->configs["contents"]]]); return $res->json(); }
/** * Post a message to the Notifico IRC notification service. * * @param $payload * @return null|string */ public static function post($payload) { $di = \Phalcon\Di::getDefault(); $config = $di->get('config'); $push_url = $config->apis->notifico_push_url; if ($push_url) { $client = new \GuzzleHttp\Client(); $response = $client->post($push_url, ['body' => ['payload' => $payload]]); return $response->getBody()->getContents(); } return null; }
protected function lookupUsernames($data) { $client = new \GuzzleHttp\Client(['base_uri' => $this->profileEndpoint]); $token = $this->jwtCoder->encode(['username' => 'tui_forum']); $queries = array_chunk($data, 255); $displayNames = []; foreach ($queries as $names) { $response = $client->post('profile/names/', ['headers' => ['Authorization' => 'Bearer ' . $token], 'json' => ['users' => $names]]); $displayNames = array_merge($displayNames, json_decode((string) $response->getBody(), true)); } return $displayNames; }
/** * @Given /^I call "([^"]*)" with params "([^"]*)" and method "([^"]*)"$/ */ public function iCallWithParamsAndMethod($endpoint, $params, $method) { $client = new GuzzleHttp\Client(); if ($method == 'GET') { $request = $client->get($endpoint . '?' . $params); } else { if ($method == 'POST') { parse_str($params, $params_array); $request = $client->post($endpoint, array('body' => $params_array)); } } $this->response = $request; }
public function sendSms($mobile, $message) { $mobile = $this->addCountryCode($mobile); if (is_array($mobile)) { $mobile = $this->composeBulkMobile($mobile); } $this->gwvars['to'] = $mobile; $this->gwvars['message'] = $message; $client = new \GuzzleHttp\Client(); $this->response = $client->post($this->getUrl(), ['body' => $this->gwvars])->getBody()->getContents(); Log::info('SMS Broadcast Response: ' . $this->response); return $this; }