Skip to content

PHP package which connects to the HackerEarth API for compiling/running code

Notifications You must be signed in to change notification settings

HackerEarth/hackerearth-api-connector-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

hackerearth-api-connector-php

The file 'hackapi.php' connects with the hackerearth API. It consists of a class `HackApi` with the following functions you can call :

set_client_secret($a)

This function helps you set your client secret. Call this function with your client secret just after you create a new object of the class. Should be called once when you create the object for successful compilations and running of codes.

init($language,$source_code,$input)

This function should be called just before calling the compile or run functions. This initialises the variables for smooth compiling. "$language" should be either as the normal language name or as hackerearth api wants it to be. The source code should contain code in the language specified. You can leave input as blank. It doesnt affect the result of compilation but it is recommended to be passed if you are going to run the program on some input.

compile()

This function is to be called after init() has been called. This function compiles the code submitted. You can check the compiler message by accessing the variable as $obj->compile_status and check if the call to api was correct by the value of $obj->message

run()

This function is called to run the source code. On a successful call, you will get the results in a list of variables discussed later.

Variables After Successful run() call

The variables you can access to gather information about the code run after calling the function run() are:
1. `id` : The code id on hackerearth.
2. `memory_used` : The amount of memory used by the code.
3. `time_used` : The execution time of program.
4. `message` : Message returned by the API.
5. `compile_status` : Whether the compilation was successful or not.
6. `run_status` : Status of the execution of code.
7. `output` : The output of the code.
8. `output_html` : The output of the code in HTML format.
9. `signal` : SIGSEV or any other signal.
10. `run_status_detail` : More detail about the run status.
11. `array_curl` : The json returned from hackerearth api in array format. In case you want to directly access that.

You can access variables as $obj->memory_used , where $obj = new HackApi.

About

PHP package which connects to the HackerEarth API for compiling/running code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages