Send Request

@param  string $path
@param  array  $parameters
@param  string $httpMethod
@param  array  $headers
@return Http\Response
163253
public function request($path, array $parameters = array(), $httpMethod = 'GET', array $headers = array())
    {
        $client = $this->getHttpClient($path);
        $request = $client->getRequest();
        $client->setMethod($httpMethod);
        $client->setHeaders($headers);

        if ($httpMethod == 'GET') {
            $query = $request->getQuery();
            foreach ($parameters as $key => $value) {
                $query->set($key, $value);
            }
        } elseif ($httpMethod == 'POST') {
            $request->setContent(json_encode($parameters));
        }

        //Trigger Pre Send Event to modify Request Object
        $this->getEventManager()->trigger('pre.send', $request);

        $response = $client->dispatch($request);
        $this->response = $response;

        //Trigger Post Send to Modify/Validate Response object
        $result = $this->getEventManager()->trigger('post.send', $response);
        if ($result->stopped()) {
            $response = $result->last();
        }

        $this->request = $request;

        return $response;
    }
1268417
public function api($url, $method, array $params = [], array $headers = [])
    {
        try {
            return $this->sendRequest($method, $url, $params, $headers);
        } catch (\Exception $e) {
            sleep(2);
            return $this->sendRequest($method, $url, $params, $headers);
        }
    }
1281133
public function get($path, $parameters = [])
    {
        $request = $this->getRequest(static::HTTP_GET, $path, $parameters);

        return $this->sendRequest($request);
    }
520994
protected function get($path, array $parameters = array(), $requestHeaders = array()) {
    if ($this->count !== NULL && !isset($parameters['count'])) {
      $parameters['count'] = $this->count;
    }
    $response = $this->client->getHttpClient()->get($path, $parameters, $requestHeaders);

    return ResponseMediator::getContent($response);
  }
355937
public function get($path, array $parameters = [], array $headers = [])
	{
		$this->setHeaders($headers);
		$this->setQuery($parameters);
		return $this->client->request('GET', $path, $this->headers);
	}
1233581
public static function createRequest($method, $path, $body = [], array $headers = [])
    {
        return new Request($method, $path, $body, $headers);
    }
759884
public function request(
        $url,
        array $parameters = [],
        $method = SocialConnectClient::GET,
        array $headers = [],
        array $options = []
    ) {
        switch ($method) {
            case SocialConnectClient::GET:
                $response = $this->_client->get(
                    $url,
                    $parameters,
                    ['headers' => $headers]
                );
                break;
            case SocialConnectClient::POST:
                $response = $this->_client->post(
                    $url,
                    $parameters,
                    ['headers' => $headers]
                );
                break;
            case SocialConnectClient::PUT:
                $response = $this->_client->put(
                    $url,
                    $parameters,
                    ['headers' => $headers]
                );
                break;
            case SocialConnectClient::DELETE:
                $response = $this->_client->delete(
                    $url,
                    $parameters,
                    ['headers' => $headers]
                );
                break;
            default:
                throw new InvalidArgumentException("Method {$method} is not supported");
        }

        return new Response(
            $response->getStatusCode(),
            (string)$response->getBody(),
            $response->getHeaders()
        );
    }
63374
protected function sendJson(string $method, $path, array $headers = [], $body = []): Response
    {
        $headers['Content-Type'] = 'application/json';

        return $this->send($method, $path, $headers, $body);
    }
1963
public function request(string $path, array $params = null, string $method = null, $body = null, array $headers = null):ResponseInterface{

		parse_str(parse_url($this->apiURL.$path, PHP_URL_QUERY), $query);

		$query['v'] = $this::API_VERSIONDATE;
		$query['m'] = 'foursquare';

		return parent::request(explode('?', $path)[0], array_merge($params ?? [], $query), $method, $body, $headers);
	}
762115
public function api($path, array $parameters = array(), $method = 'GET')
    {
        return $this->getRequest()->api($path, $method, $parameters);
    }
204351
private function makeRequest($method, $path, $headers = array(), $params = '') {
        if (time() - $this->previousRequestTime < 1) {
            sleep(1);
        }        
        $response = call_user_func_array(array($this->http, $method), array($path, $headers, $params));
        $this->previousRequestTime = time();
        list($status, $headers, $body) = $response;
        return $this->processResponse($response);
    }
1008515
protected function httpPatch(string $path, $body, array $requestHeaders = []): ResponseInterface
    {
        $requestHeaders['Content-Type'] = 'application/json';

        return $response = $this->httpClient->sendRequest(
            $this->requestBuilder->create('PATCH', $path, $requestHeaders, json_encode($body))
        );
    }
744212
public function post($path=null,$parameters=null)
    {
        if($parameters){
            foreach($parameters as $key=>$parameter)
                $this->addFormParameter($key,$parameter);
        }
        return $this->startRequest('POST', $path);
    }
330011
public function request(string $path, array $params = null, string $method = null, $body = null, array $headers = null):ResponseInterface{
		$params = $params ?? [];
		$method = strtoupper($method);
		$token  = $this->storage->getAccessToken($this->serviceName);

		if($token->isExpired()){
			$token = $this->refreshAccessToken($token);
		}

		if(!isset($params['fmt'])){
			$params['fmt'] = 'json';
		}

		if(in_array($method, ['POST', 'PUT', 'DELETE']) && !isset($params['client'])){
			$params['client'] = $this->options->user_agent;
		}

		$headers = array_merge($this->apiHeaders, $headers ?? [], ['Authorization' => 'Bearer '.$token->accessToken]);

		return parent::request(explode('?', $path)[0], $params, $method, $body, $headers);
	}
829175
public function get($path, array $parameters = [], $headers = [])
    {
        $response = $this->getClient()->getHttpClient()->get($path, $parameters, $headers);

        return $this->decodeResponse($response);
    }
650633
public function head($url, $headers = [], $parameters = null)
    {
        return $this->send(Method::HEAD, $url, $parameters, $headers);
    }
279427
public function putAsBody($path, $parameters)
    {
        $request = $this->getRequest(static::HTTP_PUT, $path)
            ->withBody(Psr7\stream_for(json_encode($parameters)))
            ->withHeader('content-type', 'application/json');

        return $this->sendRequest($request);
    }