<commit_before><?php

namespace Yotpo;

require(dirname(dirname(dirname(__FILE__))) . '/bootstrap.php');

use Httpful\Request;
use Httpful\Mime;
use Httpful\Response;

/**
 * Yotpo PHP inetrface for api.yotpo.com
 *
 * @author vlad
 */
class Yotpo {

    const VERSION = '0.0.3';

    protected static $app_key, $secret, $base_uri = 'https://api.yotpo.com';

    public function __construct($app_key = null, $secret = null, $base_uri = null) {
        if ($app_key != null) {
            self::$app_key = $app_key;
        }

        if ($secret != null) {
            self::$secret = $secret;
        }

        if ($base_uri != null) {
            self::$base_uri = $base_uri;
        }

        $template = Request::init()
                ->withoutStrictSsl()        // Ease up on some of the SSL checks
                ->expectsJson()             // Expect JSON responses
                ->sendsType(Mime::JSON)
                ->addHeader('yotpo_api_connector', 'PHP-' . Yotpo::VERSION);

        // Set it as a template
        Request::ini($template);
    }

    protected function get($uri, array $params = null) {
        $params = array_filter($params, 'strlen');
        return self::process_response(Request::get(self::$base_uri . $uri . http_build_query($params))->send());
    }

    protected function post($uri, array $params = null) {
        $params = array_filter($params, 'strlen');
        return self::process_response(Request::get(self::$base_uri . $uri)->body($params)->send());
    }

    protected function put($uri, array $params = null) {
        $params = array_filter($params, 'strlen');
        return self::process_response(Request::post(self::$base_uri . $uri)->body($params)->send());
    }

    protected function delete($uri, array $params = null) {
        $params = array_filter($params, 'strlen');
        return self::process_response(Request::delete(self::$base_uri . $uri . http_build_query($params))->send());
    }

    protected static function process_response(Response $response) {
        if ($response->hasBody()) {
            return $response->body;
        } else {
            throw 'Invalid Response';
        }
    }

    public function create_user(array $user_hash) {
        $user = array(
            'email' => $user_hash['email'],
            'display_name' => $user_hash['display_name'],
            'first_name' => $user_hash['first_name'],
            'last_name' => $user_hash['last_name'],
            'website_name' => $user_hash['website_name'],
            'password' => $<PASSWORD>['password'],
            'support_url' => $user_hash['support_url'],
            'callback_url' => $user_hash['callback_url'],<commit_msg>Fixed get and delete requests<commit_after><?php

namespace Yotpo;

require(dirname(dirname(dirname(__FILE__))) . '/bootstrap.php');

use Httpful\Request;
use Httpful\Mime;
use Httpful\Response;

/**
 * Yotpo PHP inetrface for api.yotpo.com
 *
 * @author vlad
 */
class Yotpo {

    const VERSION = '0.0.3';

    protected static $app_key, $secret, $base_uri = 'https://api.yotpo.com';

    public function __construct($app_key = null, $secret = null, $base_uri = null) {
        if ($app_key != null) {
            self::$app_key = $app_key;
        }

        if ($secret != null) {
            self::$secret = $secret;
        }

        if ($base_uri != null) {
            self::$base_uri = $base_uri;
        }

        $template = Request::init()
                ->withoutStrictSsl()        // Ease up on some of the SSL checks
                ->expectsJson()             // Expect JSON responses
                ->sendsType(Mime::JSON)
                ->addHeader('yotpo_api_connector', 'PHP-' . Yotpo::VERSION);

        // Set it as a template
        Request::ini($template);
    }

    protected function get($uri, array $params = null) {
        $params = array_filter($params, 'strlen');
        return self::process_response(Request::get(self::$base_uri . $uri .'?'. http_build_query($params))->send());
    }

    protected function post($uri, array $params = null) {
        $params = array_filter($params, 'strlen');
        return self::process_response(Request::get(self::$base_uri . $uri)->body($params)->send());
    }

    protected function put($uri, array $params = null) {
        $params = array_filter($params, 'strlen');
        return self::process_response(Request::post(self::$base_uri . $uri)->body($params)->send());
    }

    protected function delete($uri, array $params = null) {
        $params = array_filter($params, 'strlen');
        return self::process_response(Request::delete(self::$base_uri . $uri .'?'. http_build_query($params))->send());
    }

    protected static function process_response(Response $response) {
        if ($response->hasBody()) {
            return $response->body;
        } else {
            throw 'Invalid Response';
        }
    }

    public function create_user(array $user_hash) {
        $user = array(
            'email' => $user_hash['email'],
            'display_name' => $user_hash['display_name'],
            'first_name' => $user_hash['first_name'],
            'last_name' => $user_hash['last_name'],
            'website_name' => $user_hash['website_name'],
            'password' => $<PASSWORD>['password'],
            'support_url' => $user_hash['support_url'],
            'callback_url' => $user_hash['callback_url'],
{'fraction_non_alphanumeric': 0.15877128053293857, 'fraction_numerical': 0.0011102886750555144, 'mean_word_length': 2.5396201702685004, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 45, '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': '309739', 'n_tokens_mistral': 1617, 'n_tokens_neox': 1604, 'n_words': 327}