Execute a PUT or POST request

@param $verb
@return bool|mixed
@throws \GuzzleHttp\Exception\GuzzleException
970912
protected function sendData($verb, $parameters)
    {
        // Set the endpoint
        $endpoint = $this->buildEndpoint();

        // Set the header
        $this->buildHttpHeader();

        // Send the request
        $client = new Client(); //GuzzleHttp\Client

        $error = true;
        try {

            $response = $client->request($verb, $endpoint, $parameters);

            $error = false;

        } catch (\GuzzleException $e) {
            $this->errorMessage = $e->getResponse()->getBody()->getContents();

        } catch (\GuzzleHttp\Exception\ClientException $e) {
            $this->errorMessage = $e->getResponse()->getBody()->getContents();

        } catch (\GuzzleHttp\Exception\ServerException $e) {
            $this->errorMessage = $e->getResponse()->getBody()->getContents();

        } catch (Exception $e) {
            $this->errorMessage = 'Unknown Exception in Guzzle request';

        }

        return $error ? (! $error) : json_decode($response->getBody(), true);
    }
103568
public function put($uri, AbstractRequest $request = null)
    {
        $http = $this->getHttpClone();

        $http->setOption(CURLOPT_CUSTOMREQUEST, 'PUT');
        $http->setOption(CURLOPT_URL, $uri);
        if ($request) {
            $http->setOption(CURLOPT_POSTFIELDS, $this->buildPostData($request->getQuery()));
        }

        return $http->execute();
    }
558325
public function execute($method=null) {
    $isDebugEnabled = $this->logger->isDebugEnabled();
    if ($isDebugEnabled) {
      $this->logger->debug('Executing: '.get_class($this).($method ? '::'.$method: ''));
      $this->logger->debug('Request: '.$this->request);
    }

    // validate controller data
    $validationFailed = false;
    if (!$this->validate()) {
      $validationFailed = true;
    }

    // execute controller logic
    if (!$validationFailed) {
      try {
        $this->doExecute($method);
        $this->endTransaction(true);
      }
      catch (\Exception $ex) {
        if ($ex instanceof ApplicationException) {
          $error = $ex->getError();
          $this->response->addError($error);
          $this->response->setStatus($error->getStatusCode());
        }
        else {
          $this->getLogger()->error($ex);
          $error = ApplicationError::fromException($ex);
          $this->response->addError($error);
          $this->response->setStatus($error->getStatusCode());
        }
        $this->endTransaction(false);
      }
    }

    // return the last error
    $errors = array_merge($this->request->getErrors(), $this->response->getErrors());
    if (sizeof($errors) > 0) {
      $error = array_pop($errors);
      $this->response->setValue('errorCode', $error->getCode());
      $this->response->setValue('errorMessage', $error->getMessage());
      $this->response->setValue('errorData', $error->getData());
      $this->response->setStatus($error->getStatusCode());
    }

    // log errors
    for ($i=0,$count=sizeof($errors); $i<$count; $i++) {
      $error = $errors[$i];
      $message = $error->__toString();
      switch ($error->getLevel()) {
        case ApplicationError::LEVEL_WARNING:
          $this->logger->warn($message);
          break;
        default:
          $this->logger->error($message);
      }
    }

    if ($isDebugEnabled) {
      $this->logger->debug('Response: '.$this->response);
    }
  }
1198681
public function equals(Verb $verb): bool
    {
        if (!$this->id->equals($verb->id)) {
            return false;
        }

        if (null === $this->display && null === $verb->display) {
            return true;
        }

        if (null !== $this->display xor null !== $verb->display) {
            return false;
        }

        if (count($this->display) !== count($verb->getDisplay())) {
            return false;
        }

        foreach ($this->display as $language => $value) {
            if (!isset($verb->display[$language])) {
                return false;
            }

            if ($value !== $verb->display[$language]) {
                return false;
            }
        }

        return true;
    }
824829
protected function bulkPost($data, $fields, $verb = 'geocode')
    {
        $params = [
            'api_key' => $this->apiKey,
            'fields' => implode(',', $fields)
        ];

        $response = $this->client->post($verb, [
            'query' => $params,
            'json' => $data
        ]);

        return $this->checkResponse($response);
    }
5879
private function processPayload($service, $verb, $post)
    {
        $this->batch = is_array($post);
        if (false === $this->batch) {
            $post = array($post);
        }
        $this->requests = array_map(function ($payload) use ($service, $verb) {
            return new JsonRpcRequest($service, $payload, $verb);
        }, $post);
    }
62111
private function make($verb, $fetchDetails = null)
    {
        if (isset($this->cache[$verb])) {
            return $this->cache[$verb];
        }

        $data = $this->service->fetch(
            $this->word,
            $verb,
            is_null($fetchDetails) ? $this->prefetchDetails : (bool) $fetchDetails
        );

        if ($data === false) {
            return false;
        }
        $this->cache = array_merge($this->cache, $data);

        return $this->cache[$verb];
    }
751958
protected function sendRequest($verb, $params = [])
    {
        $result = $this->communicator->request($verb, $params);
        // Detect errors and die if one is found:
        if ($result->error) {
            $attribs = $result->error->attributes();
            throw new \Exception(
                "OAI-PMH error -- code: {$attribs['code']}, " .
                "value: {$result->error}"
            );
        }
        return $result;
    }
977055
protected function _execute($command) {
		try {
			if (!$class = $this->_instance($command)) {
				return false;
			}
		} catch (ClassNotFoundException $e) {
			return false;
		}
		$data = [];
		$params = $class->invokeMethod('_params');

		foreach ($params as $param) {
			$data[$param] = $class->invokeMethod("_{$param}", [$this->request]);
		}

		if ($message = $class->invokeMethod('_save', [$data])) {
			$this->out($message);
			return true;
		}
		return false;
	}
511605
public function acceptedVerb($verb)
    {

        if (isset($this->verbs[0]) && $this->verbs[0] == static::ANY_METHOD_WILDCARD) {

            return true;
        }

        return in_array(strtoupper($verb), $this->getVerbs(), true);
    }
1321168
public function execute(VerbInterface $verb, bool $noCache = false): ResultInterface
    {
        try {
            if ($verb instanceof CacheableInterface && !$noCache) {
                if ($result = self::getCached($verb)) {
                    return $result;
                }
            }

            $result = $verb->getResult();

            $command = $this->getBinary().' '.$verb->getCommand();
            $result->setCommand($command);

            $output = array();
            $exitCode = null;
            exec($command, $output, $exitCode);

            $result->setExitCode($exitCode)
                ->setOutput($output);

            if ($verb instanceof CacheableInterface && !$noCache) {
                self::addCached($verb, $result);
            }
            return $verb->getResult();
        } catch (\Exception $e) {
            throw new CommandException('Execution failure', ErrorCodes::EXECUTION_FAILURE, $e);
        }
    }
677620
public function transaction(callable $run, $attempts = 1)
    {
        $this->inTransaction = true;
        $lastInsertedId = static::$nextId;

        try {
            $result = $run($this);
            $this->inTransaction = false;
            return $result;

        } catch (\Exception $e) {

            $this->inTransaction = false;

            if(static::$nextId == $lastInsertedId) {
                throw $e;
            }

            if (isset($this->tasks[$lastInsertedId])) {
                unset($this->tasks[$lastInsertedId]);
            }

            static::$nextId--;

            throw $e;
        }
    }
959778
function send( $request )
    {
        if ( $this->Verb != '' )
        {
            $request->setMethod( $this->Verb );
        }
        // use strict comparison, so that setting it to '' by the end user will work
        if ( $this->NameVar !== null )
        {
            $request->setNameVar( $this->NameVar );
        }
        if ( $this->ResponseType !== null )
        {
            $request->setResponseType( $this->ResponseType );
        }
        if ( $this->RequestType !== null )
        {
            $request->setContentType( $this->RequestType );
        }
        if ( $this->Accept !== null )
        {
            $request->setAccept( $this->Accept );
        }
        if ( count( $this->RequestHeaders ) )
        {
            foreach( $this->RequestHeaders  as $name => $value )
            {
                $request->setExtraHeader( $name, $value );
            }
        }
        return parent::send( $request );
    }
1250033
public function request($verb, $path, $accept, array $customCURLOptions=[])
    {

        $verb = strtoupper(
            trim(
                $verb
            )
        );

        $instantiateClass = "\\Lamoni\\RESTLyte\\RESTLyteRequest\\RESTLyteRequest{$this->getResponseType()}";

        $request = new $instantiateClass(
            $this->getServer(),
            $verb,
            $path,
            $this->getAuthCredentials(),
            $accept,
            $this->getVerifySSLPeer(),
            $this->getHTTPHeaders(),
            $customCURLOptions
        );

        return $request->getResponse();
    }
554921
public function execute($request)
	{
		$method = strtolower($request->getRequestMethod());
		if(!in_array($method,array('get','put','post','delete','head')))
		{
			throw new Exception("Unknown HTTP verb");
		}

		$this->setRouter($request->getRouter());

		return $this->$method($request);
	}
1087723
public function request($verb, $arguments)
    {
        $this->emit('request.start', array(
            'verb' => $verb,
            'arguments' => $arguments
        ));
        $url = $this->urlBuilder($verb, $arguments);
        $attempt = 0;
        while (true) {
            try {
                $res = $this->httpClient->get($url, $this->getHttpOptions());
                break;
            } catch (\GuzzleHttp\Exception\ConnectException $e) {
                // Thrown in case of a networking error (connection timeout, DNS errors, etc.)
                $this->emit('request.error', array(
                    'message' => $e->getMessage(),
                ));
                time_nanosleep(intval($this->sleepTimeOnError), intval($this->sleepTimeOnError * 1000000000));
            } catch (\GuzzleHttp\Exception\ServerException $e) {
                // Thrown in case of 500 errors
                $this->emit('request.error', array(
                    'message' => $e->getMessage(),
                ));
                time_nanosleep(intval($this->sleepTimeOnError), intval($this->sleepTimeOnError * 1000000000));
            }
            $attempt++;
            if ($attempt > $this->maxRetries) {
                throw new ConnectionError('Failed to get a response from the server. Max retries (' . $this->maxRetries . ') exceeded.');
            }
        }
        $body = (string) $res->getBody();
        $this->emit('request.complete', array(
            'verb' => $verb,
            'arguments' => $arguments,
            'response' => $body
        ));
        return $body;
    }
481328
public function sendRequest($verb, $path, $body = null)
    {
        $this->logger->info('Module: ' . __CLASS__);

        if ($body instanceof Model) {
            $body = $body->toJSON(true);
        }

        $headers = [
            'Authorization' => 'ApiKey ' . $this->config->apiKey,
            'Request-ID' => uniqid('api-request-'),
            'Content-Type' => 'application/json',
        ];

        $this->logger->info('HTTP Request: ' . strtoupper($verb) . ' ' . $this->config->apiEndpoint . $path);
        $this->logger->debug("Request Headers:\n" . print_r($headers, true));

        if (isset($body)) {
            $this->logger->debug("Request Body:\n" . $body);
        }

        $response = $this->http->request(strtoupper($verb), trim($this->config->apiEndpoint . $path), [
            'body' => $body,
            'headers' => $headers
        ]);

        $this->logger->info('HTTP Code: ' . $response->getStatusCode());

        return $response->getBody()->getContents();
    }