shipu/hackerrank-api

PHP and Laravel HackerRank Code Checker API

v1.1 2018-03-28 10:46 UTC

This package is auto-updated.

Last update: 2024-10-19 10:48:39 UTC


README

Latest Stable Version Latest Unstable Version License

HackerRank Code Checker API. Extremely simple REST API. Supports more than a dozen languages. All powered by reliable HackerRank servers. You can use your own scoring system or build your own online judge.

40+ programming languages support.

Installation

Themevel is a Laravel package so you can install it via Composer. Run this command in your terminal from your project directory:

composer require shipu/hackerrank-api

Wait for a while, Composer will automatically install Themevel in your project.

Laravel Configuration

When the download is complete, you have to call this package service in config/app.php config file. To do that, add this line in app.php in providers array:

Shipu\HackerRank\HackerRankServiceProvider::class,

To use facade you have to add this line in app.php to the aliases array:

'HackerRank' => Shipu\HackerRank\Facades\HackerRank::class,

Now run this command in your terminal to publish this package resources:

php artisan vendor:publish --provider="Shipu\HackerRank\HackerRankServiceProvider"

after publishing your config file then open config/hackerrank.php and add your hackerrank app key:

return [
    /*
    |--------------------------------------------------------------------------
    | HackerRank API KEY
    |--------------------------------------------------------------------------
    |
    | https://www.hackerrank.com/api/
    |
    */

    'api_key' => env('HACKERRANK_API_KEY', 'YOUR_HACKER_RANK_API_KEY'),
];

also you can add api key in .env :

 HACKERRANK_API_KEY = YOUR_HACKER_RANK_API_KEY

Thats it.

API List

  • languages()
  • submission($lang, $source, $testcases = [ "1" ], $format = 'json', $wait = true, $callback_url = '')

Usages

use Shipu\HackerRank\HackerRank;

$config = [
            "api_key"     => 'hackerrank_app_key',
        ];
        
 
 $hackerRank = new HackerRank($config);
 
 $allLanguages = $hackerRank->checker()->languages();
 
 var_dump($allLanguages->data);

For Laravel Usage

use Shipu\HackerRank\Facades\HackerRank;
//..
//..
$allLanguages = HackerRank::checker()->languages();

dd($allLanguages->data);

Code Submission

use Shipu\HackerRank\Facades\HackerRank;
//..
//..
$response = HackerRank::checker()->submission('php', '<?php echo "It's Working"; ?>');

dd($response->data);

Code Submission with TestCase

use Shipu\HackerRank\Facades\HackerRank;
//..
//..
// Problem is returns the sum of two integers.
// Problem link: https://www.hackerrank.com/challenges/solve-me-first
// Submit code with two tescase example.

$response = HackerRank::checker()->submission('php', '<?php
               function solveMeFirst($a,$b){
                 return $a+$b;
               }
               $handle = fopen ("php://stdin","r");
               $_a = fgets($handle);
               $_b = fgets($handle);
               $sum = solveMeFirst((int)$_a,(int)$_b);
               print ($sum);
               fclose($handle);
           ?>', 
           ["1\n2", "2\n3"]);

// output array respectively as test cases
dd($response->data->result->stdout);

Support on Beerpay

Hey dude! Help me out for a couple of 🍻!

Beerpay Beerpay