SpotifyWebAPI\Request::send PHP Method

send() public method

You'll probably want to use one of the convenience methods instead.
public send ( string $method, string $url, array $parameters = [], array $headers = [] ) : array
$method string The HTTP method to use.
$url string The URL to request.
$parameters array Optional. Query parameters.
$headers array Optional. HTTP headers.
return array Response data. - array|object body The response body. Type is controlled by Request::setReturnAssoc(). - array headers Response headers. - int status HTTP status code. - string url The requested URL.
    public function send($method, $url, $parameters = [], $headers = [])
    {
        // Sometimes a JSON object is passed
        if (is_array($parameters) || is_object($parameters)) {
            $parameters = http_build_query($parameters);
        }
        $mergedHeaders = [];
        foreach ($headers as $key => $val) {
            $mergedHeaders[] = "{$key}: {$val}";
        }
        $options = [CURLOPT_CAINFO => __DIR__ . '/cacert.pem', CURLOPT_HEADER => true, CURLOPT_HTTPHEADER => $mergedHeaders, CURLOPT_RETURNTRANSFER => true];
        $url = rtrim($url, '/');
        $method = strtoupper($method);
        switch ($method) {
            case 'DELETE':
                // No break
            // No break
            case 'PUT':
                $options[CURLOPT_CUSTOMREQUEST] = $method;
                $options[CURLOPT_POSTFIELDS] = $parameters;
                break;
            case 'POST':
                $options[CURLOPT_POST] = true;
                $options[CURLOPT_POSTFIELDS] = $parameters;
                break;
            default:
                $options[CURLOPT_CUSTOMREQUEST] = $method;
                if ($parameters) {
                    $url .= '/?' . $parameters;
                }
                break;
        }
        $options[CURLOPT_URL] = $url;
        $options[CURLOPT_ENCODING] = "gzip";
        $ch = curl_init();
        curl_setopt_array($ch, $options);
        $response = curl_exec($ch);
        if (curl_error($ch)) {
            throw new SpotifyWebAPIException('cURL transport error: ' . curl_errno($ch) . ' ' . curl_error($ch));
        }
        list($headers, $body) = explode("\r\n\r\n", $response, 2);
        $status = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $headers = $this->parseHeaders($headers);
        $body = $this->parseBody($body, $status);
        curl_close($ch);
        return ['body' => $body, 'headers' => $headers, 'status' => $status, 'url' => $url];
    }

Usage Example

 public function testSendReturnAssoc()
 {
     $request = new SpotifyWebAPI\Request();
     $request->setReturnAssoc(true);
     $response = $request->send('GET', 'https://api.spotify.com/v1/albums/7u6zL7kqpgLPISZYXNTgYk');
     $this->assertArrayHasKey('id', $response['body']);
 }
All Usage Examples Of SpotifyWebAPI\Request::send