<commit_before><?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/

Route::get('/', function()
{
	return View::make('hello');
});

Route::get('/edit', function()
{
    return View::make('edit');
});

Route::get('/oauth', function()
{
    $consumerKey = $_ENV['TUMBLR_API_CONSUMER_KEY'];
    $consumerSecret = $_ENV['TUMBLR_API_SECRET_KEY'];

    $tmpToken = Session::get('tmp_oauth_token', null);
    $tmpTokenSecret = Session::get('tmp_oauth_token_secret', null);

    $client = new Tumblr\API\Client($consumerKey, $consumerSecret, $tmpToken, $tmpTokenSecret);

    // Change the base url
    $requestHandler = $client->getRequestHandler();
    $requestHandler->setBaseUrl('https://www.tumblr.com/');

    if (Input::has('oauth_verifier'))
    {
        // exchange the verifier for the keys
        $verifier = trim(Input::get('oauth_verifier'));
        $resp = $requestHandler->request('POST', 'oauth/access_token', array('oauth_verifier' => $verifier));
        $out = (string) $resp->body;
        $data = array();
        parse_str($out, $data);

        Session::forget('tmp_oauth_token');
        Session::forget('tmp_oauth_token_secret');

        Session::put('Tumblr_oauth_token', $data['oauth_token']);
        Session::put('Tumblr_oauth_token_secret', $data['oauth_token_secret']);
    }


    if ( ! Session::has('Tumblr_oauth_token') || ! Session::has('Tumblr_oauth_token_secret'))
    {
        // start the old gal up
        $callbackUrl = 'http://localhost:8000/oauth';

        $resp = $requestHandler->request('POST', 'oauth/request_token', array(
                'oauth_callback' => $callbackUrl
            ));

        // Get the result
        $result = (string)$resp->body;
        parse_str($result, $keys);

        Session::put('tmp_oauth_token', $keys['oauth_token']);
        Session::put('tmp_oauth_token_secret', $keys['oauth_token_secret']);

        $url = 'https://www.tumblr.com/oauth/authorize?oauth_token=' . $keys['oauth_token'];

        return Redirect::to($url);
    }

    $client = new Tumblr\API\Client(
        $consumerKey,
        $consumerSecret,
        Session::get('Tumblr_oauth_token'),
        Session::get('Tumblr_oauth_token_secret')
    );

    $info = $client->getUserInfo();

    return View::make('oauth_success');
});

Route::get('/test', function()
{
    $client = new Tumblr\API\Client(
        $_ENV['TUMBLR_API_CONSUMER_KEY'],
        $_ENV['TUMBLR_API_SECRET_KEY'],
        Session::get('Tumblr_oauth_token'),
        Session::get('Tumblr_oauth_token_secret')
    );

    // Change the base url
//    $requestHandler = $client->getRequestHandler();
//    $requestHandler->setBaseUrl('https://www.tumblr.com/');

    $info = $client->getUserInfo();
    dd( "\ncongrats " . $info->user->name . "!\n");
});
<commit_msg>Change routing for API<commit_after><?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/

Route::get('/', function()
{
	return View::make('hello');
});

/*
 * Add Route group for API Access
 */
Route::group(array('prefix' => 'api'), function()
{
    Route::resource('theme', 'ThemeController');
});

Route::get('/oauth', function()
{
    $consumerKey = $_ENV['TUMBLR_API_CONSUMER_KEY'];
    $consumerSecret = $_ENV['TUMBLR_API_SECRET_KEY'];

    $tmpToken = Session::get('tmp_oauth_token', null);
    $tmpTokenSecret = Session::get('tmp_oauth_token_secret', null);

    $client = new Tumblr\API\Client($consumerKey, $consumerSecret, $tmpToken, $tmpTokenSecret);

    // Change the base url
    $requestHandler = $client->getRequestHandler();
    $requestHandler->setBaseUrl('https://www.tumblr.com/');

    if (Input::has('oauth_verifier'))
    {
        // exchange the verifier for the keys
        $verifier = trim(Input::get('oauth_verifier'));
        $resp = $requestHandler->request('POST', 'oauth/access_token', array('oauth_verifier' => $verifier));
        $out = (string) $resp->body;
        $data = array();
        parse_str($out, $data);

        Session::forget('tmp_oauth_token');
        Session::forget('tmp_oauth_token_secret');

        Session::put('Tumblr_oauth_token', $data['oauth_token']);
        Session::put('Tumblr_oauth_token_secret', $data['oauth_token_secret']);
    }


    if ( ! Session::has('Tumblr_oauth_token') || ! Session::has('Tumblr_oauth_token_secret'))
    {
        // start the old gal up
        $callbackUrl = 'http://localhost:8000/oauth';

        $resp = $requestHandler->request('POST', 'oauth/request_token', array(
                'oauth_callback' => $callbackUrl
            ));

        // Get the result
        $result = (string)$resp->body;
        parse_str($result, $keys);

        Session::put('tmp_oauth_token', $keys['oauth_token']);
        Session::put('tmp_oauth_token_secret', $keys['oauth_token_secret']);

        $url = 'https://www.tumblr.com/oauth/authorize?oauth_token=' . $keys['oauth_token'];

        return Redirect::to($url);
    }

    $client = new Tumblr\API\Client(
        $consumerKey,
        $consumerSecret,
        Session::get('Tumblr_oauth_token'),
        Session::get('Tumblr_oauth_token_secret')
    );

    $info = $client->getUserInfo();

    return View::make('oauth_success');
});

Route::get('/test', function()
{
    $client = new Tumblr\API\Client(
        $_ENV['TUMBLR_API_CONSUMER_KEY'],
        $_ENV['TUMBLR_API_SECRET_KEY'],
        Session::get('Tumblr_oauth_token'),
        Session::get('Tumblr_oauth_token_secret')
    );

    // Change the base url
//    $requestHandler = $client->getRequestHandler();
//    $requestHandler->setBaseUrl('https://www.tumblr.com/');

    $info = $client->getUserInfo();
    dd( "\ncongrats " . $info->user->name . "!\n");
});

{'fraction_non_alphanumeric': 0.2100362947767082, 'fraction_numerical': 0.001262427015938141, 'mean_word_length': 2.8226779252110976, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, 'https://': 6, 'lorem ipsum': 0, 'www.': 6, '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': '4574730', 'n_tokens_mistral': 2070, 'n_tokens_neox': 1958, 'n_words': 342}