<commit_before><?php

namespace UltraSoftcore\MatchCalendar;


use GuzzleHttp\Client;
use GuzzleHttp\Post\PostBody;
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;

class ApiBridge
{

    public function me(Request $request, Application $app)
    {
        if (!$request->query->has('access_token')) {
            return $app->json(['error' => 'Must provide an access token'], 400);
        }

        $client = new Client([
            'defaults' => [
                'headers' => [
                    'Authorization' => 'bearer ' . $request->query->get('access_token')
                ]
            ]
        ]);

        $req = $client->createRequest('GET', 'https://oauth.reddit.com/api/v1/me');
        $res = $client->send($req);

        return $app->json($res->json(), $res->getStatusCode());
    }

    public function submitSelf(Request $request, Application $app)
    {
        if(!$request->request->has('access_token')) {
            return $app->json(['error' => 'Must provide an access token'], 400);
        }
        $access_token = $request->request->get('access_token');

        if(!$request->request->has('content')) {
            return $app->json(['error' => 'Must provide content to send'], 400);
        }
        $content = $request->request->get('content');

        if(!$request->request->has('subreddit')) {
            return $app->json(['error' => 'Must provide subreddit to send to'], 400);
        }
        $subreddit = $request->request->get('subreddit');

        if(!$request->request->has('title')) {
            return $app->json(['error' => 'Must provide title of post'], 400);
        }
        $title = $request->request->get('title');

        $client = new Client([
            'defaults' => [
                'headers' => [
                    'Authorization' => 'bearer ' . $access_token
                ]
            ]
        ]);

        $req = $client->createRequest('POST', 'https://oauth.reddit.com/api/submit');

        /** @var PostBody $postBody */
        $postBody = $req->getBody();

        $postBody->setField('kind', 'self');
        $postBody->setField('text', $content);
        $postBody->setField('title', $title);
        $postBody->setField('sr', $subreddit);

        $res = $client->send($req);
        return $app->json($res->json(), $res->getStatusCode());
    }
}
<commit_msg>make sure to get json back<commit_after><?php

namespace UltraSoftcore\MatchCalendar;


use GuzzleHttp\Client;
use GuzzleHttp\Post\PostBody;
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;

class ApiBridge
{

    public function me(Request $request, Application $app)
    {
        if (!$request->query->has('access_token')) {
            return $app->json(['error' => 'Must provide an access token'], 400);
        }

        $client = new Client([
            'defaults' => [
                'headers' => [
                    'Authorization' => 'bearer ' . $request->query->get('access_token')
                ]
            ]
        ]);

        $req = $client->createRequest('GET', 'https://oauth.reddit.com/api/v1/me');
        $res = $client->send($req);

        return $app->json($res->json(), $res->getStatusCode());
    }

    public function submitSelf(Request $request, Application $app)
    {
        if(!$request->request->has('access_token')) {
            return $app->json(['error' => 'Must provide an access token'], 400);
        }
        $access_token = $request->request->get('access_token');

        if(!$request->request->has('content')) {
            return $app->json(['error' => 'Must provide content to send'], 400);
        }
        $content = $request->request->get('content');

        if(!$request->request->has('subreddit')) {
            return $app->json(['error' => 'Must provide subreddit to send to'], 400);
        }
        $subreddit = $request->request->get('subreddit');

        if(!$request->request->has('title')) {
            return $app->json(['error' => 'Must provide title of post'], 400);
        }
        $title = $request->request->get('title');

        $client = new Client([
            'defaults' => [
                'headers' => [
                    'Authorization' => 'bearer ' . $access_token
                ]
            ]
        ]);

        $req = $client->createRequest('POST', 'https://oauth.reddit.com/api/submit');

        /** @var PostBody $postBody */
        $postBody = $req->getBody();

        $postBody->setField('api_type', 'json');
        $postBody->setField('kind', 'self');
        $postBody->setField('text', $content);
        $postBody->setField('title', $title);
        $postBody->setField('sr', $subreddit);

        $res = $client->send($req);
        return $app->json($res->json(), $res->getStatusCode());
    }
}

{'fraction_non_alphanumeric': 0.18463780183180684, 'fraction_numerical': 0.006661115736885929, 'mean_word_length': 2.222669349429913, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 106, 'https://': 4, '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': '3695237', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1375, 'n_words': 257}