public function assignToUser($pid, $uid, $filters = []) { $result = $this->client->post("/gdc/md/{$pid}/userfilters", ['userFilters' => ['items' => [["user" => Users::getUriFromUid($uid), "userFilters" => $filters]]]]); if (!isset($result['userFiltersUpdateResult']['successful']) || !count($result['userFiltersUpdateResult']['successful'])) { throw Exception::unexpectedResponseError('Assign filters to user failed', 'POST', "/gdc/md/{$pid}/userfilters", $result); } }
private function getToken() { if (!$this->token) { $response = $this->client->post('tokens', '', json_encode(array("username" => $this->username, "password" => $this->password)))->send(); $this->token = $response->json(); } return $this->token; }
public function createUser($login, $password, $domain, array $options = []) { $result = $this->client->post("/gdc/account/domains/{$domain}/users", ['accountSetting' => array_merge(['login' => strtolower($login), 'email' => strtolower($login), 'password' => $password, 'verifyPassword' => $password], $options)]); if (isset($result['uri'])) { return self::getUidFromUri($result['uri']); } else { throw Exception::unexpectedResponseError('Create user failed', 'POST', "/gdc/account/domains/{$domain}/users", $result); } }
public function schedule($to, $txt, $date) { $client = new Client($this->user, $this->token); $data = array("destinations" => $to, "text" => $txt, "scheduleDate" => $date); $response = $client->post('messages', $data); return $response->scheduleId; }
public function send($to, $txt) { $client = new Client($this->user, $this->token); $data = array("destinations" => $to, "text" => $txt); $response = $client->post('messages', $data); return $response->deliveryToken; }
public function testPost() { $client = new Client('', '', false); $email = array('FromName' => 'Mailjet PHP test', 'FromEmail' => '*****@*****.**', 'Text-Part' => 'Simple Email test', 'Subject' => 'PHPunit', 'Html-Part' => '<h3>Simple Email Test</h3>', 'Recipients' => array(array('Email' => '*****@*****.**')), 'MJ-custom-ID' => 'Hello ID'); $ret = $client->post(Resources::$Email, array('body' => $email)); $this->assertUrl('/send', $ret); $this->assertPayload($email, $ret); }
public function testPost() { $client = new Client('', '', false); $email = ['FromName' => 'Mailjet PHP test', 'FromEmail' => '*****@*****.**', 'Text-Part' => 'Simple Email test', 'Subject' => 'PHPunit', 'Html-Part' => '<h3>Simple Email Test</h3>', 'Recipients' => [['Email' => '*****@*****.**']], 'MJ-custom-ID' => 'Hello ID']; $ret = $client->post(Resources::$Email, ['body' => $email]); $this->assertUrl('/send', $ret); $this->assertPayload($email, $ret); }
/** * Perform a POST request, get a decoded JSON response. * Internally verifies an Ed25519 signature. * * @param string $url * @param SignaturePublicKey $publicKey * @param array $params * @return mixed */ public function postSignedJSON(string $url, SignaturePublicKey $publicKey, array $params = []) { $response = $this->client->post($url, $this->params($params, $url)); if ($response instanceof Response) { return $this->parseSignedJSON($response, $publicKey); } return null; }
public function create($options = []) { $data = Client::post(static::endpoint(), $this->payload(), $options); if (count($data) > 0) { $data = json_decode($data, true); } return $this->parse($data); }
public static function getRefreshToken($code) { $endpoint = 'https://connect.stripe.com/oauth/token'; $params = array('client_secret' => $_ENV['STRIPE_SECRET_KEY'], 'code' => $code, 'grant_type' => 'authorization_code'); $url = self::makeurl($endpoint, $params); $client = new Client(); $returned_object = $client->post($endpoint, ['body' => $params])->json(); return $returned_object; }
public function diff($pid, $model) { $uri = "/gdc/projects/{$pid}/model/diff?includeDeprecated=true&includeGrain=true"; $result = $this->client->post($uri, ['diffRequest' => ['targetModel' => $model]]); if (isset($result['asyncTask']['link']['poll'])) { $try = 1; do { sleep(10 * $try); $taskResponse = $this->client->get($result['asyncTask']['link']['poll']); if (!isset($taskResponse['asyncTask']['link']['poll'])) { if (isset($taskResponse['projectModelDiff']['updateScripts'])) { $lessDestructive = []; $moreDestructive = []; // Preserve data if possible foreach ($taskResponse['projectModelDiff']['updateScripts'] as $updateScript) { if ($updateScript['updateScript']['preserveData'] && !$updateScript['updateScript']['cascadeDrops']) { $lessDestructive = $updateScript['updateScript']['maqlDdlChunks']; } if (!count($lessDestructive) && !$updateScript['updateScript']['preserveData'] && !$updateScript['updateScript']['cascadeDrops']) { $lessDestructive = $updateScript['updateScript']['maqlDdlChunks']; } if (!$updateScript['updateScript']['preserveData'] && $updateScript['updateScript']['cascadeDrops']) { $moreDestructive = $updateScript['updateScript']['maqlDdlChunks']; } if (!count($moreDestructive) && $updateScript['updateScript']['preserveData'] && $updateScript['updateScript']['cascadeDrops']) { $moreDestructive = $updateScript['updateScript']['maqlDdlChunks']; } } $description = []; foreach ($taskResponse['projectModelDiff']['updateOperations'] as $o) { $description[] = vsprintf($o['updateOperation']['description'], $o['updateOperation']['parameters']); } return ['moreDestructiveMaql' => $moreDestructive, 'lessDestructiveMaql' => $lessDestructive, 'description' => $description]; } else { throw Exception::unexpectedResponseError('Polling of Model diff could not be finished', 'GET', $result['asyncTask']['link']['poll'], $taskResponse); } } $try++; } while (true); } else { throw Exception::unexpectedResponseError('Polling of Model diff could not be started', 'POST', $uri, $result); } return false; }
public function disableUser($uid, $pid) { try { $result = $this->client->get("/gdc/projects/{$pid}/users/{$uid}"); $this->client->post("/gdc/projects/{$pid}/users", ['user' => ['content' => ['status' => 'DISABLED', 'userRoles' => $result['user']['content']['userRoles']], 'links' => ['self' => $result['user']['links']['self']]]]); } catch (Exception $e) { if ($e->getCode() != 404) { throw $e; } } }
public function testPOST() { // create our http client (Guzzle) $client = new Client('http://localhost:8000', array('request.options' => array('exceptions' => false))); $nickname = 'ObjectOrienter' . rand(0, 999); $data = array('nickname' => $nickname, 'avatarNumber' => 5, 'tagLine' => 'a test dev!'); $request = $client->post('/api/programmers', null, json_encode($data)); $response = $request->send(); $this->assertEquals(201, $response->getStatusCode()); $this->assertTrue($response->hasHeader('Location')); $data = json_decode($response->getBody(true), true); $this->assertArrayHasKey('nickname', $data); }
public function loadData($pid, $dirName) { $uri = "/gdc/md/{$pid}/etl/pull2"; $result = $this->client->post($uri, ['pullIntegration' => $dirName]); if (isset($result['pull2Task']['links']['poll'])) { $try = 1; do { sleep(10 * $try); $taskResponse = $this->client->get($result['pull2Task']['links']['poll']); if (!isset($taskResponse['wTaskStatus']['status'])) { throw Exception::unexpectedResponseError('ETL task could not be checked', 'GET', $result['pull2Task']['links']['poll'], $taskResponse); } $try++; } while ($taskResponse['wTaskStatus']['status'] == 'RUNNING'); if ($taskResponse['wTaskStatus']['status'] == 'ERROR') { $errors = []; if (isset($taskResponse['messages'])) { foreach ($taskResponse['messages'] as $m) { if (isset($m['error'])) { $errors[] = Exception::parseMessage($m['error']); } } } if (isset($taskResponse['wTaskStatus']['messages'])) { foreach ($taskResponse['wTaskStatus']['messages'] as $m) { if (isset($m['error'])) { $errors[] = Exception::parseMessage($m['error']); } } } throw new Exception($errors); } return isset($taskResponse['messages']) ? $taskResponse['messages'] : []; } else { throw Exception::unexpectedResponseError('ETL task failed', 'POST', $uri, $result); } }
/** * Send notification to LeanCloud * * @return array */ public function send() { $out = $this->encode(); $resp = Client::post("/push", $out); return $resp; }
/** * Add a new comment to the issue * * @param Comment $comment * * @return array */ public function addComment($comment) { return $this->client->post(sprintf('projects/%d/issues/%d/comments', $this->projectId, $this->id), $comment->toArray()); }
public function queryApp($appID) { if (isset($appID)) { $this->loadComponent('Progress'); $this->Progress->determineApp($appID, true, null, false, true, false); if ($results->done != 1) { // Application is incomplete for one of four reasons 1: Missing an Application, 2: Number of Cubs doesn't match, 3: Number of Leaders doesn't match, 4: Payment is incomplete. $issues = []; $issueKeys = []; // Check 1 - does it have an invoice if ($results->invDone != 1 && $results->invCount != 1) { arraypush($issues, 'An invoice has not been generated.'); arraypush($issueKeys, 0); } // Check 2 - does it have the right number of Cubs if ($results->cubsDone != 1 || $results->invCubs != $results->attCubs) { arraypush($issues, 'There are Cubs names missing or some that have not been cancelled on the invoice.'); arraypush($issueKeys, 1); arraypush($issues, 'There are more Cubs names on the application than invoiced for.'); arraypush($issueKeys, 2); } // Check 3 - does it have the right number of Leaders & YLs if ($results->cubsNotDone != 1 || $results->invNotCubs != $results->attNotCubs) { arraypush($issues, 'There are Young Leaders names missing or some that have not been cancelled on the invoice.'); arraypush($issueKeys, 3); arraypush($issues, 'There are more Young Leaders names on the application than invoiced for.'); arraypush($issueKeys, 4); arraypush($issues, 'There are Leaders names missing or some that have not been cancelled on the invoice.'); arraypush($issueKeys, 5); arraypush($issues, 'There are more Leaders names on the application than invoiced for.'); arraypush($issueKeys, 6); } // Check 4 - is it all paid up if ($results->payDone != 1 && $sumValues != $sumPayments) { arraypush($issues, 'Payment is Outstanding'); arraypush($issueKeys, 7); } $notification = $this->Notifications->newEntity(); $notification = $this->Notifications->patchEntity($notification, $invoiceData); if ($this->Notifications->save($notification)) { $notificationId = $notification->get('id'); $noteData = ['note_text' => 'A Balance Outstanding Prompt Email was Sent with Notification id #' . $notificationId, 'visible' => false, 'user_id' => $user->id, 'invoice_id' => $invoice->id, 'application_id' => $app->id]; $note = $notes->newEntity(); $note = $notes->patchEntity($note, $noteData); if ($notes->save($note)) { $this->Flash->success(__('Outstanding Balance Prompt Sent.')); $this->getMailer('Payment')->send('outstanding', [$user, $group, $notification, $invoice, $app]); $sets = TableRegistry::get('Settings'); $jsonInvoice = json_encode($invoiceData); $pApiKey = $sets->get(13)->text; $projectId = $sets->get(14)->text; $eventType = 'OutstandingPayment'; $keenURL = 'https://api.keen.io/3.0/projects/' . $projectId . '/events/' . $eventType . '?api_key=' . $pApiKey; $http = new Client(); $response = $http->post($keenURL, $jsonInvoice, ['type' => 'json']); $genericType = 'Notification'; $keenGenURL = 'https://api.keen.io/3.0/projects/' . $projectId . '/events/' . $genericType . '?api_key=' . $pApiKey; $http = new Client(); $response = $http->post($keenGenURL, $jsonInvoice, ['type' => 'json']); return $this->redirect(['controller' => 'Invoices', 'action' => 'view', 'prefix' => 'admin', $invoiceId]); } else { $this->Flash->error(__('The note could not be saved. Please, try again.')); } } } } }
public function export($pid, $uri) { $result = $this->client->post("/gdc/app/projects/{$pid}/execute/raw/", ["report_req" => ["reportDefinition" => $uri]]); return $result['uri']; }
public static function create($amount, $description, $currency = "SAR") { $data = [self::AMOUNT => $amount, self::DESCRIPTION => $description, self::CURRENCY => $currency]; return json_decode(Client::post("https://api.moyasar.com/v1/invoices", $data)); }
/** * Create a new release build for the project * * @param ReleaseBuild $releaseBuild * * @return array */ public function createReleaseBuild($releaseBuild) { return $this->client->post(sprintf('projects/%d/release_builds', $this->id), $releaseBuild->toArray()); }
/** * Call any path, POST method. * * @param string $path the path * @param array $parameters POST parameters * @param array $requestOptions reconfigure the request * * @return array */ protected function post($path, array $parameters = array(), array $requestOptions = array()) { return $this->client->post($path, $parameters, $requestOptions); }
/** * Verify SMS code * * @param string $phoneNumber * @param string $smsCode */ public static function verifySmsCode($phoneNumber, $smsCode) { Client::post("/verifySmsCode/{$smsCode}?mobilePhoneNumber={$phoneNumber}", null); }
/** * @param string $code * * @return mixed */ public function getToken($code) { return $this->client->post('/oauth2/token', array('client_id' => $this->clientId, 'redirect_uri' => $this->redirectUrl, 'client_secret' => $this->clientSecret, 'code' => $code, 'grant_type' => 'authorization_code')); }
/** * Get auth token * * @param $redirect * @param $code * @return StreamInterface */ public function token(string $redirect, string $code) : StreamInterface { $response = $this->client->post('https://' . $this->region . '.battle.net/oauth/token', ['form_params' => ['redirect_uri' => $redirect, 'scope' => $this->scopes, 'grant_type' => 'authorization_code', 'code' => $code], 'auth' => [$this->apiKey, $this->apiSecret]]); return $response->getBody(); }
public static function refund($id, $amount = 0) { $data = [self::AMOUNT => $amount]; return json_decode(Client::post("https://api.moyasar.com/v1/payments/{$id}/refund", $data)); }
public function testNestedData() { $client = new Client($this->testUrl); $data = array('username' => 'my_username', 'info' => array('name' => 'my_name', 'mail' => 'my_email', 'profile' => array('twitter' => 'my_twitter', 'github' => 'my_github'))); $this->assertEquals($data, json_decode($client->post($data), JSON_OBJECT_AS_ARRAY)['post']); }
public function get_access_token() { $app_client_values = array('Email' => $this->client_email, 'ApiKey' => $this->api_key); $access_data = Client::post("Security", $app_client_values); return $access_data['Response']['TokenId']; }
/** * @param string $path * @param array $params * * @return mixed */ public function post($path, array $params = array()) { return $this->client->post($this->preparePath($path), $params); }
public function testPostClient() { Client::relateIQ(GlobalVar::KEY, GlobalVar::SECRET); Client::endpoint('https://api.relateiq.com/v2/accounts/'); $this->assertEquals("https://api.relateiq.com/v2/accounts/", Client::endpoint()); Client::headers(["Content-type" => "application/json", "Accept" => "application/json"]); $this->assertEquals(["Content-type" => "application/json", "Accept" => "application/json"], Client::headers()); $data = ['name' => 'Account1']; $this->assertEquals(200, Client::post('', $data, [])->code); }