Package Data | |
---|---|
Maintainer Username: | ankitjain28 |
Maintainer Contact: | ankitjain28may77@gmail.com (ankitjain28may) |
Package Create Date: | 2017-07-04 |
Package Last Update: | 2023-04-19 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-23 03:00:44 |
Package Statistics | |
---|---|
Total Downloads: | 41 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 8 |
Total Watchers: | 3 |
Total Forks: | 1 |
Total Open Issues: | 4 |
This package is using HackerEarth api to Compile and Run the code.
HackerEarth Code Checker API. Extremely simple REST API. Supports more than a dozen languages. All powered by reliable HackerEarth servers. You can use your own scoring system or build your own online judge.
PHP Innovation Award for the PHP package Hacker Earth API Certification Link
Run this command in your terminal from your project directory:
composer require ankitjain28may/hackerearth-api
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:
Ankitjain28may\HackerEarth\HackerEarthServiceProvider::class,
To use facade you have to add this line in app.php
to the aliases
array:
'HackerEarth' => Ankitjain28may\HackerEarth\Facades\HackerEarth::class,
Now run this command in your terminal to publish this package resources:
php artisan vendor:publish --provider="Ankitjain28may\HackerEarth\HackerEarthServiceProvider"
php artisan vendor:publish --tag=migrations
after publishing your config file then open config/hackerearth.php
and add your hackerearth app key:
return [
/*
|--------------------------------------------------------------------------
| HackerEarth API KEY
|--------------------------------------------------------------------------
|
| https://api.hackerearth.com/v3/code/
| https://api.hackerearth.com/v3/code/
|
*/
'api_key' => env('HACKEREARTH_SECRET_KEY', 'CLIENT_SECRET_KEY'),
];
also you can add api key in .env
:
HACKEREARTH_SECRET_KEY = YOUR_HACKER_EARTH_API_KEY
Thats it.
$data = [
"lang" => '',
"source" => '',
"input" => '',
"async" => 0, // default (1 => async req and 0 => sync req)
"callback" => '',
'id' => '',
'time_limit' => 5, // default
'memory_limit' => 262144, // default
]
async = 1
.async = 0
.create database [database name]
mysql -u[user] -p[password] [database name] < vendor\ankitjain28may\hackerearth-api\src\Database\migrate.sql
use Ankitjain28may\HackerEarth\HackerEarth;
$config = [
"api_key" => 'hackerearth_app_key',
];
$hackerearth = new HackerEarth($config);
$data = [
"lang" => 'php',
"source" => '<?php echo "hello World!"; ?>'
];
$result = $hackerearth->Compile([$data]);
var_dump($result);
$result = $hackerearth->Run([$data]);
var_dump($result);
// Asynchronous
$data = [
"lang" => 'php',
"source" => '<?php echo "hello World!"; ?>',
"async" => 1,
"callback" => 'http://callback_url',
"id" => 12 // Id from the db where to save or update response
]
$result = $hackerearth->Run([$data]);
vardump($result);
// Response at Callback URL will need to save to DB with reference to the ID, Id returned is encoded using `bin2hex` which can be decoded using `hex2bin`.
use Ankitjain28may\HackerEarth\Facades\HackerEarth;
use Ankitjain28may\HackerEarth\Models\Output;
//..
//..
$data = [
"lang" => 'php',
"source" => '<?php echo "hello World!"; ?>'
];
$result = HackerEarth::Compile([$data, ..]);
dd($result);
// Asynchronous
$data = [
"lang" => 'php',
"source" => '<?php echo "hello World!"; ?>',
"async" => 1,
"callback" => 'http://callback_url',
"id" => 12 // Id from the db where to save or update response
]
$result = $hackerearth->Compile([$data]);
dd($result);
OR
Output::saveResult(json_decode($result, True)); // Save directly to the DB
// Response at Callback URL will save to DB with reference to the ID
Output::savePayload(json_decode($_POST['payload'], True));
use Ankitjain28may\HackerEarth\Facades\HackerEarth;
use Ankitjain28may\HackerEarth\Models\Output;
//..
//..
$data = [
"lang" => 'php',
"source" => '<?php echo "hello World!"; ?>'
];
$result = HackerEarth::Run([$data, ..]);
dd($result);
// Asynchronous
$data = [
"lang" => 'php',
"source" => '<?php echo "hello World!"; ?>',
"async" => 1,
"callback" => 'http://callback_url',
"id" => 12 // Id from the db where to save or update response
]
$result = $hackerearth->Run([$data]);
dd($result);
OR
Output::saveResult(json_decode($result, True)); // Save directly to the DB
// Response at Callback URL will save to DB with reference to the ID
Output::savePayload(json_decode($_POST['payload'], True));
use Ankitjain28may\HackerEarth\Facades\HackerEarth;
//..
//..
$data = [
"lang" => 'php',
"source" => realpath("test.txt")
];
$result = HackerEarth::RunFile([$data]);
$result = HackerEarth::CompileFile([$data]);
Feel free to contribute
Copyright (c) 2017 Ankit Jain - Released under the MIT License