delete() public method

public delete ( $reqId, $reason )
示例#1
1
 function doDelete($url)
 {
     $response = Requests::delete($this->apiUrl . $url, $this->header);
     return json_decode($response->body);
 }
示例#2
0
 public function request($method, $url, $api_key, $data = NULL, $headers = array("Content-Type" => "application/json", "Accept" => "application/json"))
 {
     try {
         $options = array('auth' => new \Requests_Auth_Basic(array($api_key, '')));
         if ($method == "GET") {
             $url_params = is_array($data) ? '?' . http_build_query($data) : '';
             $response = \Requests::get(Client::BASE_URL . $url . $url_params, $headers, $options);
         } else {
             if ($method == "POST") {
                 $response = \Requests::post(Client::BASE_URL . $url, $headers, json_encode($data), $options);
             } else {
                 if ($method == "PATCH") {
                     $response = \Requests::patch(Client::BASE_URL . $url, $headers, json_encode($data), $options);
                 } else {
                     if ($method == "DELETE") {
                         $response = \Requests::delete(Client::BASE_URL . $url, $headers, $options);
                     }
                 }
             }
         }
     } catch (\Exception $e) {
         throw new UnableToConnect();
     }
     if ($response->status_code >= 200 && $response->status_code <= 206) {
         if ($method == "DELETE") {
             return $response->status_code == 204 || $response->status_code == 200;
         }
         return json_decode($response->body);
     }
     if ($response->status_code == 400) {
         $code = 0;
         $message = "";
         try {
             $error = (array) json_decode($response->body)->errors[0];
             $code = key($error);
             $message = current($error);
         } catch (\Exception $e) {
             throw new UnhandledError($response->body, $response->status_code);
         }
         throw new InputValidationError($message, $code);
     }
     if ($response->status_code == 401) {
         throw new AuthenticationError();
     }
     if ($response->status_code == 404) {
         throw new NotFound();
     }
     if ($response->status_code == 403) {
         throw new InvalidApiKey();
     }
     if ($response->status_code == 405) {
         throw new MethodNotAllowed();
     }
     throw new UnhandledError($response->body, $response->status_code);
 }
示例#3
0
function issue_request($render, $url, $headers, $body)
{
    if ($render['METHOD'] == 'POST') {
        return \Requests::post($url, $headers, $body);
    } else {
        if ($render['METHOD'] == 'PUT') {
            return \Requests::put($url, $headers, $body);
        } else {
            if ($render['METHOD'] == 'DELETE') {
                return \Requests::delete($url, $headers);
            }
        }
    }
    return \Requests::get($url, $headers);
}
示例#4
0
 public function request($method, $url, $api_key, $data = NULL, $headers = array("Content-Type" => "application/json", "Accept" => "application/json"))
 {
     try {
         $options = array('auth' => new AuthBearer($api_key), 'timeout' => 120);
         if ($method == "GET") {
             $url_params = is_array($data) ? '?' . http_build_query($data) : '';
             $response = \Requests::get(Culqi::$api_base . $url . $url_params, $headers, $options);
         } else {
             if ($method == "POST") {
                 $response = \Requests::post(Culqi::$api_base . $url, $headers, json_encode($data), $options);
             } else {
                 if ($method == "PATCH") {
                     $response = \Requests::patch(Culqi::$api_base . $url, $headers, json_encode($data), $options);
                 } else {
                     if ($method == "DELETE") {
                         $response = \Requests::delete(Culqi::$api_base, $options);
                     }
                 }
             }
         }
     } catch (\Exception $e) {
         throw new Errors\UnableToConnect();
     }
     if ($response->status_code >= 200 && $response->status_code <= 206) {
         if ($method == "DELETE") {
             return $response->status_code == 204 || $response->status_code == 200;
         }
         return json_decode($response->body);
     }
     if ($response->status_code == 400) {
         $code = 0;
         $message = "";
         throw new Errors\UnhandledError($response->body, $response->status_code);
     }
     if ($response->status_code == 401) {
         throw new Errors\AuthenticationError();
     }
     if ($response->status_code == 404) {
         throw new Errors\NotFound();
     }
     if ($response->status_code == 403) {
         throw new Errors\InvalidApiKey();
     }
     if ($response->status_code == 405) {
         throw new Errors\MethodNotAllowed();
     }
     throw new Errors\UnhandledError($response->body, $response->status_code);
 }
示例#5
0
 protected function request($method, $url, $client_id, $secret_id, $data = NULL, $headers = array("Content-Type" => "application/json", "Accept" => "application/json"))
 {
     try {
         $options = array('auth' => new \Requests_Auth_Basic(array($client_id, $secret_id)));
         if ($method == "GET") {
             $url_params = is_array($data) ? '?' . http_build_query($data) : '';
             $response = \Requests::get($this->base_url . $url . $url_params, $headers, $options);
         } else {
             if ($method == "POST") {
                 $response = \Requests::post($this->base_url . $url, $headers, json_encode($data), $options);
             } else {
                 if ($method == "PATCH") {
                     $response = \Requests::patch($this->base_url . $url, $headers, json_encode($data), $options);
                 } else {
                     if ($method == "DELETE") {
                         $response = \Requests::delete($this->base_url . $url, $headers, $options);
                     }
                 }
             }
         }
     } catch (\Exception $e) {
         throw new \Exception(Error_Message::ERROR_CONNECTION);
     }
     if ($response->status_code >= 200 && $response->status_code <= 206) {
         if ($method == "DELETE") {
             return $response->status_code == 204 || $response->status_code == 200;
         }
         return json_decode($response->body);
     }
     if ($response->status_code >= 400 && $response->status_code <= 406) {
         try {
             $error = (array) json_decode($response->body);
             $code = $error['errorCode'];
             $message = $error['errorMessage'];
         } catch (\Exception $e) {
             throw new \Exception($response->body, $response->status_code);
         }
         throw new \Exception($message, $code);
     }
     throw new \Exception($response->body, $response->status_code);
 }
示例#6
0
 public function testDELETE()
 {
     $request = Requests::delete(httpbin('/delete'), array(), $this->getOptions());
     $this->assertEquals(200, $request->status_code);
     $result = json_decode($request->body, true);
     $this->assertEquals(httpbin('/delete'), $result['url']);
     $this->assertEmpty($result['args']);
 }
示例#7
0
     httpResponse($requests->getMyRequests());
     break;
 case validateRoute('POST', 'requests'):
     $logs = new Logs($db, $user);
     $requests = new Requests($db, $user, $logs);
     httpResponse($requests->createOrUpdate($postdata));
     break;
 case validateRoute('PATCH', 'requests/\\d+'):
     $requests = new Requests($db, $user);
     httpResponse($requests->createOrUpdate($postdata, (int) $params[1]));
     break;
 case validateRoute('DELETE', 'requests/\\d+'):
     $logs = new Logs($db, $user);
     $mailbox = new Mailbox($db, $user);
     $requests = new Requests($db, $user, $logs, $mailbox);
     httpResponse($requests->delete($params[1], $_GET["reason"]));
     break;
 case validateRoute('POST', 'requests/\\d+/votes'):
     $requests = new Requests($db, $user);
     $response = $requests->vote($params[1], (int) $postdata["reward"]);
     httpResponse($response);
     break;
 case validateRoute('GET', 'mailbox'):
     $mailbox = new Mailbox($db, $user);
     list($result, $totalCount) = $mailbox->query((int) $_GET["location"] ?: 0, (int) $_GET["limit"] ?: 10, (int) $_GET["index"] ?: 0);
     httpResponse($result, $totalCount);
     break;
 case validateRoute('PATCH', 'mailbox/\\d+'):
     $mailbox = new Mailbox($db, $user);
     httpResponse($mailbox->update((int) $params[1], $postdata));
     break;
示例#8
0
文件: methodsTest.php 项目: bafs/via
 $tf->assertSame($req->body, 'PUT /on');
 $req = Requests::get($url . '/multi');
 $tf->assertSame($req->body, 'MULTI /multi');
 $req = Requests::put($url . '/multi');
 $tf->assertSame($req->body, 'MULTI /multi');
 $req = Requests::post($url . '/multi');
 $tf->assertSame($req->body, 'MULTI /multi');
 $req = Requests::delete($url . '/multi');
 $tf->assertNotSame($req->body, 'MULTI /multi');
 $req = Requests::get($url . '/any');
 $tf->assertSame($req->body, 'ANY /any');
 $req = Requests::post($url . '/any');
 $tf->assertSame($req->body, 'ANY /any');
 $req = Requests::put($url . '/any');
 $tf->assertSame($req->body, 'ANY /any');
 $req = Requests::delete($url . '/any');
 $tf->assertSame($req->body, 'ANY /any');
 // $req = Requests::head($url . '/any');
 // $tf->assertSame($req->body, 'ANY /any');
 $req = Requests::get($url . '/space/');
 $tf->assertSame($req->body, 'GET /space/');
 $req = Requests::post($url . '/space/');
 $tf->assertSame($req->body, 'POST /space/');
 $req = Requests::get($url . '/_all');
 $tf->assertSame($req->body, 'all');
 $req = Requests::post($url . '/_all');
 $tf->assertSame($req->body, 'all');
 $req = Requests::post($url . '/lla');
 $tf->assertSame($req->body, 'all');
 $req = Requests::put($url . '/all');
 $tf->assertSame($req->body, 'all');
示例#9
0
 function deleteAPI($method, $function, $params = [], $keep = TRUE)
 {
     $params = is_array($params) ? $params : (array) $params;
     $params = count($params) < 1 ? '' : '?' . http_build_query($params);
     $headers = ['X-API-KEY' => APPLICATION_KEY, 'TOKEN' => $this->session->userdata('token')];
     $response = Requests::delete(API_URL . $method . '/' . $function . $params, $headers);
     $result = json_decode($response->body);
     // UPDATE TOKEN TO SESSION
     if (!empty($result->token)) {
         if ((bool) $this->session->userdata('user_id')) {
             $this->session->set_userdata('token', $result->token);
         }
     }
     $output['execution_time_api'] = $result->execution_time;
     $output['environment_api'] = $result->environment;
     $output['message'] = $result->message;
     // OUTPUT
     if (!$keep) {
         $this->xresponse($result->status, $output, $response->status_code);
     } else {
         return $result;
     }
 }
示例#10
0
 /**
  * Delete an existing item (DELETE items/{id} request).
  *
  * @param stdClass $item_id ID of the item to be deleted.
  * @throws Exception If an error response was returned by VWflow
  */
 function deleteItem($item_id)
 {
     $url = $this->uri . "items/" . $item_id . "/";
     $headers = array('Content-Type' => 'application/json');
     $response = Requests::delete($url, $headers, $this->request_options);
     $this->_checkErrorResponse($response);
 }
示例#11
0
 /**
  * DSL wrapper to make a HTTP request based on supported HTTP methods.
  *
  * @param   string  $uri        Path to API resource
  * @param   array   $args       Associative array of passed arguments
  * @param   array   $headers    List of passed headers
  * @param   string  $method     HTTP method
  * @return  array               Processed response
  * @see     Sixreps::_response
  */
 protected function _request($uri, $args = array(), $headers = array(), $method = 'GET')
 {
     $url = $this->_host . trim($uri, '/');
     switch ($method) {
         case 'GET':
             if (!empty($args)) {
                 $url = $url . '?' . http_build_query($args);
             }
             $request = Requests::get($url, array());
             break;
         case 'POST':
             $request = Requests::post($url, array(), $args);
             break;
         case 'PUT':
             $request = Requests::put($url, array(), $args);
             break;
         case 'DELETE':
             if (!empty($args)) {
                 $url = $url . '?' . http_build_query($args);
             }
             $request = Requests::delete($url, array());
             break;
         default:
             throw new InvalidArgumentException(sprintf('Unsupported %s HTTP method. It should match one of %s keywords.', $method, implode(', ', $this->_http_methods)));
     }
     $body = $request->body;
     $info['headers'] = $request->headers;
     $info['headers'] = $request->headers;
     $info['status_code'] = $request->status_code;
     $info['success'] = $request->success;
     $info['redirects'] = $request->redirects;
     $info['url'] = $request->url;
     return $this->_response($body, $info, $method);
 }
示例#12
0
 /**
  * Method for clearing the DNS cache set with remapHosts
  *
  * @return string
  */
 public function clearDnsCache()
 {
     $url = "http://{$this->browsermob_url}/proxy/{$this->port}/dns/cache";
     $response = Requests::delete($url);
     return $response;
 }
示例#13
0
 /**
  * Delete the object
  *
  * @throws Requests_Exception Failed to delete object
  * @return boolean Was the deletion successful?
  */
 public function delete($permanent = false)
 {
     $url = $this->meta['links']['self'];
     if ($permanent) {
         if (strpos($url, '?') !== false) {
             $url .= '&force=true';
         } else {
             $url .= '?force=true';
         }
     }
     $response = Requests::delete($url, array(), $this->api->getDefaultOptions());
     $response->throw_for_status();
     $this->data = array();
     $this->changed = array();
     return true;
 }
<?php

include 'baseline.php';
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$newsletter_delete = $config['BASEURL'] . '/users/' . $request->ekstern_id . '/nyhedsbreve/' . $config['TBT_NID'] . '?location_id=' . $config['LOCATION_ID'];
$response = Requests::delete($newsletter_delete, $headers, null);
echo $response->body;
示例#15
0
<?php

include 'baseline.php';
$url = $config['BASEURL'] . '/users/' . $request->ekstern_id . '/nyhedsbreve/' . $config['GODTTIP_NID'] . '?location_id=' . $config['LOCATION_ID'];
$headers = array('Content-Type' => 'application/json');
$response = Requests::delete($url);
echo $response->body;
示例#16
0
function delete_subscription_by_id($access_token, $api_root, $subscriptionId)
{
    global $endpoint;
    // Delete a previously created subscription.
    $auth_header = build_oauth2_auth_header($access_token);
    $header = array();
    $header = array_merge($header, $auth_header);
    // DELETE /v1/orgs/<org id>/subscriptions/<subscriptionId>
    $url = $endpoint . $api_root->_links->subscriptions->href . '/' . $subscriptionId;
    $response = Requests::delete($url, $header);
    return json_decode($response->body);
}
<?php

//DELETE
//Add
include 'baseline.php';
$url = $config['BASEURL'] . '/users/' . $request->ekstern_id . '/interesser';
$request->location_id = $config['LOCATION_ID'];
$to_add_payload = new stdClass();
$to_add_payload->interesser = $request->add;
$to_add_payload->location_id = $config['LOCATION_ID'];
$headers = array('Content-Type' => 'application/json');
if (count($to_add_payload->interesser) > 0) {
    Requests::post($url, $headers, json_encode($to_add_payload));
}
if (count($request->remove) > 0) {
    $url = $url . '?interesser=[' . implode(",", $request->remove) . ']';
    Requests::delete($url);
}
echo "";
示例#18
0
 protected function delete($uri, $timeout)
 {
     $response = \Requests::delete($uri, array(), ['timeout' => ceil($timeout)]);
     $this->checkErrors($response);
     return $response->body;
 }