<commit_before><?php
/**
 * Instagram API Helper plugin for Craft CMS 3.x
 *
 * A Helper for the Instagram API
 *
 * @link      https://t-k-f.ch
 * @copyright Copyright (c) 2017 <NAME>
 */

namespace tkf\instagramapihelper\controllers;

use tkf\instagramapihelper\InstagramApiHelper;

use Craft;
use craft\web\Controller;

/**
 * @author    <NAME>
 * @package   InstagramApiHelper
 * @since     1.0.0
 */
class UsersController extends Controller
{

    // Protected Properties
    // =========================================================================

    protected $allowAnonymous = true;
    private $apiUrl = 'https://api.instagram.com/v1/users';
    public $enableCsrfValidation = false;

    // Private Methods
    // =========================================================================

    private function settings()
    {
        return \tkf\instagramapihelper\InstagramApiHelper::getInstance()->settings;
    }

    private function request($path)
    {
        $cacheKey = md5($path);
        $cache = Craft::$app->cache->get($cacheKey);

        if($cache !== false)
        {
            return $cache;
        }
        else
        {
            $curl = curl_init($path);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            $result = json_decode(curl_exec($curl));
            curl_close($curl);
            Craft::$app->cache->set($cacheKey, $result, 300);

            return $result;
        }
    }

    private function response ($path)
    {
        $response = $this->request($path);

        return $this->asJson($response);
    }

    private function checkParams ($params)
    {
        $post = Craft::$app->getRequest()->getBodyParams();
        $queryString = '';

        foreach ($params as $param)
        {
            if(isset($post[$param]))
            {
                $queryString .= '&' . $param . '=' . $post[$param];
            }
        }

        return $queryString;
    }

    // Public Methods
    // =========================================================================

    public function actionSelf()
    {
        $path = $this->apiUrl . '/self/?access_token=' . $this->settings()['instagramApiToken'];

        return $this->response($path);
    }

    public function actionUser($userId)
    {
        $path = $this->apiUrl . '/' . $userId . '/?access_token=' . $this->settings()['instagramApiToken'];

        return $this->response($path);
    }

    public function actionSelfRecent()
    {
        $path = $this->apiUrl . '/self/media/recent/?access_token=' . $this->settings()['instagramApiToken'] . $this->checkParams(['count', 'max_id', 'min_id']);

        return $this->response($path);
    }

    public function actionUserRecent($userId)
    {
        $path = $this->apiUrl . '/' . $userId . '/media/recent/?access_token=' . $this->settings()['instagramApiToken'] . $this->checkParams(['count', 'max_id', 'min_id']);

        return $this->response($path);
    }

    public function actionSelfLiked()
    {
        $path = $this->apiUrl . '/self/media/liked/?access_token=' . $this->settings()['instagramApiToken'] . $this->checkParams(['count', 'max_like_id']);

        return $this->response($path);
    }

    public function actionSearch()
    {
        $path = $this->apiUrl . '/search?q=tkf&access_token=' . $this->settings()['instagramApiToken'];

        return $this->response($path);
    }
}<commit_msg>removed unavaible endpoints logic to service class<commit_after><?php
/**
 * Instagram API Helper plugin for Craft CMS 3.x
 *
 * A Helper for the Instagram API
 *
 * @link      https://t-k-f.ch
 * @copyright Copyright (c) 2017 <NAME>
 */

namespace tkf\instagramapihelper\controllers;

use tkf\instagramapihelper\InstagramApiHelper;

use Craft;
use craft\web\Controller;

/**
 * @author    <NAME>
 * @package   InstagramApiHelper
 * @since     1.0.0
 */
class UsersController extends Controller
{
    protected $allowAnonymous = true;
    private $apiUrl = 'https://api.instagram.com/v1/users';
    public $enableCsrfValidation = false;

    // Public Methods
    // =========================================================================

    public function actionSelf()
    {
        $response = InstagramApiHelper::getInstance()->helpers->getResponse($this->apiUrl, 'self', []);

        return $this->asJson($response);
    }

    public function actionSelfRecent()
    {
        $response = InstagramApiHelper::getInstance()->helpers->getResponse($this->apiUrl, 'self/media/recent', ['count', 'max_id', 'min_id']);

        return $this->asJson($response);
    }

    public function actionSelfLiked()
    {
        $response = InstagramApiHelper::getInstance()->helpers->getResponse($this->apiUrl, 'self/media/liked', ['count', 'max_id', 'min_id']);

        return $this->asJson($response);
    }
}
{'fraction_non_alphanumeric': 0.21015544041450776, 'fraction_numerical': 0.004559585492227979, 'mean_word_length': 2.8332009531374105, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 49, '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': '348028', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1353, 'n_words': 261}