public function deleteProject($projectid) { // Login as admin. $client = new GuzzleHttp\Client(['cookies' => true]); global $CDASH_BASE_URL; try { $response = $client->request('POST', $CDASH_BASE_URL . '/user.php', ['form_params' => ['login' => 'simpletest@localhost', 'passwd' => 'simpletest', 'sent' => 'Login >>']]); } catch (GuzzleHttp\Exception\ClientException $e) { $this->fail($e->getMessage()); return false; } // Delete project. $project_array = array('Id' => $projectid); try { $response = $client->delete($CDASH_BASE_URL . '/api/v1/project.php', ['json' => ['project' => $project_array]]); } catch (GuzzleHttp\Exception\ClientException $e) { $this->fail($e->getMessage()); return false; } // Make sure the project doesn't exist anymore. $project = new Project(); $project->Id = $projectid; if ($project->Exists()) { $this->fail("Project {$projectid} still exists after it should have been deleted"); } }
// form submission handler $app->post('/add', function (Request $request) use($app, $guzzle) { $symbol = strip_tags($request->get('symbol')); $units = (int) $request->get('units'); if ($units <= 0) { throw new Exception('Invalid input'); } $doc = ['uid' => $_SESSION['uid'], 'symbol' => $symbol, 'units' => $units]; $guzzle->post($app->config['db_name'], ['json' => $doc]); return $app->redirect($app["url_generator"]->generate('index') . '#manage'); })->before($authenticate); $app->get('/delete/{rid}', function ($rid) use($app, $guzzle) { $arr = explode('.', $rid); $id = $arr[0]; $rev = $arr[1]; $guzzle->delete($app->config['db_name'] . '/' . $id . '?rev=' . $rev); return $app->redirect($app["url_generator"]->generate('index') . '#manage'); })->before($authenticate); // login handler // check if authenticated against provider // retrieve user email address and save to session $app->get('/login', function () use($app, $auth) { $google = $auth->authenticate("Google"); $currentUser = $google->getUserProfile(); $_SESSION['uid'] = $currentUser->email; return $app->redirect($app["url_generator"]->generate('index') . '#search'); })->bind('login'); // logout handler // log out and display logout information page $app->get('/logout', function () use($app, $auth) { $auth->logoutAllProviders();
/** * @Then As :user delete the created comment it should return :statusCode */ public function asDeleteTheCreatedCommentItShouldReturn($user, $statusCode) { $url = $this->baseUrl . '/remote.php/dav/comments/files/' . $this->fileId . '/' . $this->commentId; $client = new \GuzzleHttp\Client(); try { $res = $client->delete($url, ['auth' => [$user, '123456'], 'headers' => ['Content-Type' => 'application/json']]); } catch (\GuzzleHttp\Exception\ClientException $e) { $res = $e->getResponse(); } if ($res->getStatusCode() !== (int) $statusCode) { throw new \Exception("Response status code was not {$statusCode} (" . $res->getStatusCode() . ")"); } }
private function clearRules() { // Initialize Guzzle client and define rules URL $client = new \GuzzleHttp\Client(); $url = 'https://api.gnip.com/accounts/' . GNIP_ACCOUNT . '/publishers/' . $this->endpoint . '/streams/track/Prod/rules.json'; // Get existing rules Log::info('Fetching existing rules'); try { $res = $client->get($url, ['auth' => [GNIP_USERNAME, GNIP_PASSWORD]]); } catch (\Exception $e) { if ($e->hasResponse()) { Log::info('Error: ' . $e->getResponse()->getBody()); } else { Log::info('Gnip API Request error'); } return false; } // Delete existing rules $rules = $res->json(); if (count($rules['rules']) > 0) { Log::info('Deleting existing rules'); try { $res = $client->delete($url, ['auth' => [GNIP_USERNAME, GNIP_PASSWORD], 'json' => $rules]); } catch (\Exception $e) { if ($e->hasResponse()) { Log::info('Error: ' . $e->getResponse()->getBody()); } else { Log::info('Gnip API Request error'); } return false; } } // Add new rules Log::info('Adding new rules'); $rules = ['rules' => []]; foreach ($this->filters as $filter) { $rules['rules'][] = ['tag' => $filter->id, 'value' => str_replace("\n", " ", $filter->query_gnip)]; } try { $res = $client->post($url, ['auth' => [GNIP_USERNAME, GNIP_PASSWORD], 'json' => $rules]); } catch (\Exception $e) { if ($e->hasResponse()) { Log::info('Error: ' . $e->getResponse()->getBody()); } else { Log::info('Gnip API Request error'); } return false; } return true; }
<?php require 'vendor/autoload.php'; $client = new GuzzleHttp\Client(); $id = $_GET['id']; $response = $client->request('GET', 'http://docent.cmi.hro.nl/bootb/restdemo/notes', ['query' => ['id' => $id]]); $json = json_decode($response->getBody()); if ($_POST != null) { $response = $client->delete('http://docent.cmi.hro.nl/bootb/restdemo/notes/' . $id); header('Location: index.php'); } ?> <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" href="css/foundation.css"/> </head> <body> <table class="hover"> <thead> <tr> <th width="100">ID</th> <th width="250">Title</th> <th width="500">Body</th> <th width="250">Author</th> <th width="250"></th> </tr>
<?php require __DIR__ . '/vendor/autoload.php'; $client = new \GuzzleHttp\Client(['base_url' => 'http://localhost:8000', 'defaults' => ['exceptions' => false]]); $book1 = array('title' => 'title - test2 - ' . rand(0, 999), 'description' => 'description - test2 - ' . rand(0, 999), 'owner' => 1); $book2 = array('title' => 'edited 9', 'description' => 'edited 9'); $book3 = array('title' => 'edited 10', 'description' => 'edited 10'); $response1 = $client->post('/api/book', ['body' => json_encode($book1)]); //$response2_1 = $client->get('/api/book/3'); //$response2_2 = $client->get('/api/book/16'); //$response3 = $client->get('/api/book'); $response4 = $client->put('/api/book/30', ['body' => json_encode($book2)]); $response5 = $client->delete('/api/book/33'); $response6 = $client->patch("/api/book/31", ['body' => json_encode($book3)]); echo $response1; echo "\n\n"; //echo $response2_1; //echo $response2_2; //echo $response3; echo $response4; echo "\n\n"; echo $response5; echo "\n\n"; echo $response6; echo "\n\n";
foreach ($resp->data as $key => $value) { echo $key . " : {"; foreach ($value as $num => $err) { echo $err . ","; } echo "}" . "<br>"; } echo "<a href='/users/" . $id . "/edit'>Retry</a><br>"; return "Form contains errors.."; } return new Response("User updated! <a href='/users/" . $id . "'>check out</a>", 201); }); //delete $app->delete('/users/{id}', function (Silex\Application $app, $id) { $client = new GuzzleHttp\Client(); $res = $client->delete("https://basic-rails-api.herokuapp.com/api/v1/users/" . $id); $resp = json_decode($res->getBody()); if (!$resp->status) { echo $resp->message; return "<br>Error in deleting account"; } return "User deleted <a href='/users'>All users</a>"; }); $app->get('/users', function () use($app) { return $app->redirect("/"); }); $app->get('/users/new', function (Silex\Application $app) { return $app['twig']->render('new-user.html.twig', array()); })->bind('new-user'); // Section A // We will later add the configuration, etc. here
/** * Remove a check with the given id * @param int $checkId * @return string */ public function removeCheck($checkId) { $client = new \GuzzleHttp\Client(['base_uri' => 'https://api.pingdom.com/api/2.0/']); try { $response = $client->delete('https://api.pingdom.com/api/2.0/checks/' . $checkId, ['auth' => [$this->username, $this->password], 'headers' => ['App-Key' => $this->token]]); $response = json_decode($response->getBody(), true); } catch (\Exception $e) { var_dump($e->getResponse()->getBody()->getContents()); throw $e; } return $response; }