HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/deensekroon.komma-mediadesign.nl/wwwroot/php/sweebr/SweebrRepository.php
<?php


class SweebrRepository
{
    protected $token = '44b9aadd9dca49fee07b6e26b5e97edb71e2641f';

    /*
     * Get Sweebr Results from a certain scope
     */
    public function getReportFromScope($scope)
    {

        $url = 'https://api.v3.sweebr.com/reports/overview?start=' . $scope->start->timestamp . '&end=' . $scope->end->timestamp;

        $ch = curl_init();

        $options = [
            CURLOPT_URL            => $url,

            // TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
            CURLOPT_RETURNTRANSFER => true,

            // TRUE to include the header in the output.
            CURLOPT_HEADER         => false,

            // TRUE to follow any "Location: " header that the server sends as part of the HTTP header.
            CURLOPT_FOLLOWLOCATION => true,

            // If an empty string, "", is set, a header containing all supported encoding types is sent.
            CURLOPT_ENCODING       => "",

            // TRUE to automatically set the Referer: field in requests where it follows a Location: redirect.
            CURLOPT_AUTOREFERER    => true,

            // The number of seconds to wait while trying to connect.
            CURLOPT_CONNECTTIMEOUT => 120,

            // The maximum number of seconds to allow cURL functions to execute.
            CURLOPT_TIMEOUT        => 120,

            // The maximum amount of HTTP redirections to follow. Use this option alongside CURLOPT_FOLLOWLOCATION.
            CURLOPT_MAXREDIRS      => 10,

            // An array of HTTP header fields to set.
            CURLOPT_HTTPHEADER     => ['Authorization: Bearer ' . $this->token],

            // Doesn't work with verification, so add these two parameters
            CURLOPT_SSL_VERIFYPEER => false,
            // Authenticating the certificate is not enough to be sure about the server. You typically also
            // want to ensure that the server is the server you mean to be talking to. Use CURLOPT_SSL_VERIFYHOST
            // for that. The check that the host name in the certificate is valid for the host name you're connecting
            // to is done independently of the CURLOPT_SSL_VERIFYPEER option.
            CURLOPT_SSL_VERIFYHOST => false,
        ];

        // Set options
        curl_setopt_array( $ch, $options );

        // Response
        $response = curl_exec($ch);
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $error = curl_error($ch);

        // Close curl
        curl_close($ch);

        // Test
        //$response = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/php/sweebr/SweebrTest.json');

        return [$httpCode, $response, $error];
    }
}