<commit_before><?php namespace ImguBox\Services;

use GuzzleHttp\Client;
use ImguBox\User;
use ImguBox\Token;

class ImgurService
{
    /**
     * Guzzle Instance
     * @var GuzzleHttp\Client
     */
    protected $client;


    /**
     * User Instance
     * @var ImguBox\User
     */
    protected $user;

    /**
     * Token Instance
     * @var ImguBox\Token
     */
    protected $token;

    /**
     * Available API Endpoints
     * @var array
     */
    protected $scopes = [
        'base_url' => 'https://api.imgur.com/',
        'version'  => '/3/',
        'account'  => [
            'favorites' => 'account/__USERNAME__/favorites'
        ],
        'gallery' => [
            'image' => 'image/__ID__',
            'album' => 'album/__ID__'
        ]
    ];

    public function __construct(Client $client)
    {
        $this->client = $client;
    }

    /**
     * Set User
     * @param User $user
     */
    public function setUser(User $user)
    {
        $this->user = $user;
    }

    /**
     * Set Token
     * @param Token $token
     */
    public function setToken(Token $token)
    {
        $this->token = $token;
        $this->prepareClient($token);
    }

    /**
     * Get Users Favorites
     * @return object
     */
    public function favorites()
    {
        $version   = array_get($this->scopes, 'version');
        $favorites = array_get($this->scopes, 'account.favorites');
        $favorites = $this->replaceUsername($favorites);

        $response  = $this->client->get($version.$favorites, ['exceptions' => false]);

        $body = $response->getBody();
        return json_decode($body)->data;
    }

    /**
     * Get Image Model
     * @param  string $id
     * @return object
     */
    public function image($id)
    {
        $version  = array_get($this->scopes, 'version');
        $image    = array_get($this->scopes, 'gallery.image');
        $image    = $this->replaceId($image, $id);

        $response = $this->client->get($version.$image, ['exceptions' => false]);

        $body     = $response->getBody();
        return json_decode($body)->data;
    }

    /**
     * Get Gallery Model
     * @param  string $id
     * @return object
     */
    public function gallery($id)
    {
        $version  = array_get($this->scopes, 'version');
        $image    = array_get($this->scopes, 'gallery.album');
        $image    = $this->replaceId($image, $id);

        $response = $this->client->get($version.$image, ['exceptions' => false]);

        $body     = $response->getBody();
        return json_decode($body)->data;
    }

    /**
     * Refresh an access_token
     * @param  User   $user
     * @return object
     */
    public function refreshToken()
    {
        $response = $this->client->post('oauth2/token', [
            'body' => [
                'refresh_token' => $this->token->refresh_token,
                'client_id'     => env('IMGUR_KEY'),
                'client_secret' => env('IMGUR_SECRET'),
                'grant_type'    => 'refresh_token'
            ],
            'exceptions' => false
        ]);

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

    /**
     * Request access and refresh_token from Imgur
     * @return object
     */
    public function getAccessToken($code)
    {
        $client = new $this->client([
            'base_url' => array_get($this->scopes, 'base_url'),
        ]);<commit_msg>ImgurService Api Calls return request, not the body<commit_after><?php namespace ImguBox\Services;

use GuzzleHttp\Client;
use ImguBox\User;
use ImguBox\Token;

class ImgurService
{
    /**
     * Guzzle Instance
     * @var GuzzleHttp\Client
     */
    protected $client;


    /**
     * User Instance
     * @var ImguBox\User
     */
    protected $user;

    /**
     * Token Instance
     * @var ImguBox\Token
     */
    protected $token;

    /**
     * Available API Endpoints
     * @var array
     */
    protected $scopes = [
        'base_url' => 'https://api.imgur.com/',
        'version'  => '/3/',
        'account'  => [
            'favorites' => 'account/__USERNAME__/favorites'
        ],
        'gallery' => [
            'image' => 'image/__ID__',
            'album' => 'album/__ID__'
        ]
    ];

    public function __construct(Client $client)
    {
        $this->client = $client;
    }

    /**
     * Set User
     * @param User $user
     */
    public function setUser(User $user)
    {
        $this->user = $user;
    }

    /**
     * Set Token
     * @param Token $token
     */
    public function setToken(Token $token)
    {
        $this->token = $token;
        $this->prepareClient($token);
    }

    /**
     * Get Users Favorites
     * @return object
     */
    public function favorites()
    {
        $version   = array_get($this->scopes, 'version');
        $favorites = array_get($this->scopes, 'account.favorites');
        $favorites = $this->replaceUsername($favorites);

        return $this->client->get($version.$favorites, ["exceptions" => false]);
    }

    /**
     * Get Image Model
     * @param  string $id
     * @return object
     */
    public function image($id)
    {
        $version  = array_get($this->scopes, 'version');
        $image    = array_get($this->scopes, 'gallery.image');
        $image    = $this->replaceId($image, $id);

        return $this->client->get($version.$image, ["exceptions" => false]);
    }

    /**
     * Get Gallery Model
     * @param  string $id
     * @return object
     */
    public function gallery($id)
    {
        $version  = array_get($this->scopes, 'version');
        $image    = array_get($this->scopes, 'gallery.album');
        $image    = $this->replaceId($image, $id);

        return $this->client->get($version.$image, ["exceptions" => false]);
    }

    /**
     * Refresh an access_token
     * @param  User   $user
     * @return object
     */
    public function refreshToken()
    {
        $response = $this->client->post('oauth2/token', [
            'body' => [
                'refresh_token' => $this->token->refresh_token,
                'client_id'     => env('IMGUR_KEY'),
                'client_secret' => env('IMGUR_SECRET'),
                'grant_type'    => 'refresh_token'
            ],
            'exceptions' => false
        ]);

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

    /**
     * Request access and refresh_token from Imgur
     * @return object
     */
    public function getAccessToken($code)
    {
        $client = new $this->client([
            'base_url' => array_get($this->scopes, 'base_url'),
        ]);
{'fraction_non_alphanumeric': 0.15629719118091212, 'fraction_numerical': 0.0006040471156750226, 'mean_word_length': 1.8547413793103449, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 95, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2858827', 'n_tokens_mistral': 2084, 'n_tokens_neox': 2037, 'n_words': 395}