/**
  * @requires PHPUnit 5
  */
 public function testAutorizationFail()
 {
     $access_token = "fake access token";
     $endpoint = getenv("SE_ENDPOINT_PROBLEMS");
     $client = new ProblemsClientV3($access_token, $endpoint);
     $this->expectException(SphereEngineResponseException::class);
     $this->expectExceptionCode(401);
     $client->test();
 }
 public function testAutorizationFail()
 {
     $access_token = "fake access token";
     $endpoint = getenv("SE_ENDPOINT_PROBLEMS");
     $invalidClient = new ProblemsClientV3($access_token, $endpoint);
     try {
         $invalidClient->test();
         $this->assertTrue(false);
     } catch (SphereEngineResponseException $e) {
         $this->assertTrue($e->getCode() == 401);
     }
 }
示例#3
0
<?php

/**
 * Example presents usage of the successful getProblems() API method  
 */
use SphereEngine\Api\ProblemsClientV3;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$response = $client->getProblems();
<?php

/**
 * Example presents usage of the successful deleteProblemTestcase() API method  
 */
use SphereEngine\Api\ProblemsClientV3;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$problemCode = 'EXAMPLE';
$testcaseNumber = 0;
$response = $client->deleteProblemTestcase($problemCode, $testcaseNumber);
<?php

/**
 * Example presents usage of the successful createSubmission() API method
*/
use SphereEngine\Api\ProblemsClientV3;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$problemCode = 'TEST';
$source = 'int main() { return 0; }';
$compiler = 11;
// C language
$response = $client->createSubmission($problemCode, $source, $compiler);
// response['id'] stores the ID of the created submission
<?php

/**
 * Example presents error handling for deleteProblemTestcase() API method    
 */
use SphereEngine\Api\ProblemsClientV3;
use SphereEngine\Api\SphereEngineResponseException;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$problemCode = 'EXAMPLE';
$nonexistingTestcaseNumber = 9999;
try {
    $response = $client->deleteProblemTestcase($problemCode, $nonexistingTestcaseNumber);
} catch (SphereEngineResponseException $e) {
    if ($e->getCode() == 401) {
        echo 'Invalid access token';
    } elseif ($e->getCode() == 403) {
        echo 'Access to the problem is forbidden';
    } elseif ($e->getCode() == 404) {
        // aggregates two possible reasons of 404 error
        // non existing problem or testcase
        echo 'Non existing resource (problem, testcase), details available in the message: ' . $e->getMessage();
    }
}
<?php

/**
 * Example presents error handling for updateProblem() API method
*/
use SphereEngine\Api\ProblemsClientV3;
use SphereEngine\Api\SphereEngineResponseException;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$problemCode = 'NONEXISTING_CODE';
$newProblemName = 'New example problem name';
try {
    $response = $client->updateProblem($problemCode, $newProblemName);
} catch (SphereEngineResponseException $e) {
    if ($e->getCode() == 401) {
        echo 'Invalid access token';
    } elseif ($e->getCode() == 403) {
        echo 'Access to the problem is forbidden';
    } elseif ($e->getCode() == 400) {
        // aggregates two possible reasons of 400 error
        // empty problem code, empty problem name
        echo 'Bad request (empty problem code, empty problem name), details available in the message: ' . $e->getMessage();
    } elseif ($e->getCode() == 404) {
        // aggregates two possible reasons of 404 error
        // non existing problem or masterjudge
<?php

/**
 * Example presents usage of the successful updateProblem() API method
*/
use SphereEngine\Api\ProblemsClientV3;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$newProblemName = 'New example problem name';
$response = $client->updateProblem('EXAMPLE', $newProblemName);
示例#9
0
<?php

/**
 * Example presents usage of the successful getCompilers() API method  
 */
use SphereEngine\Api\ProblemsClientV3;
// require library
require_once '../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$response = $client->getCompilers();
示例#10
0
<?php

/**
 * Example presents usage of the successful getJudge() API method  
 */
use SphereEngine\Api\ProblemsClientV3;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$response = $client->getJudge(1);
示例#11
0
<?php

/**
 * Example presents usage of the successful getJudges() API method  
 */
use SphereEngine\Api\ProblemsClientV3;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$response = $client->getJudges();
<?php

/**
 * Example presents error handling for updateProblemTestcase() API method    
 */
use SphereEngine\Api\ProblemsClientV3;
use SphereEngine\Api\SphereEngineResponseException;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$problemCode = 'TEST';
$testcaseNumber = 0;
$newNonexistingJudge = 9999;
try {
    $response = $client->updateProblemTestcase($problemCode, $testcaseNumber, null, null, null, $newNonexistingJudge);
} catch (SphereEngineResponseException $e) {
    if ($e->getCode() == 401) {
        echo 'Invalid access token';
    } elseif ($e->getCode() == 403) {
        echo 'Access to the problem is forbidden';
    } elseif ($e->getCode() == 404) {
        // aggregates three possible reasons of 404 error
        // non existing problem, testcase or judge
        echo 'Non existing resource (problem, testcase or judge), details available in the message: ' . $e->getMessage();
    }
}
<?php

/**
 * Example presents error handling for createJudge() API method  
*/
use SphereEngine\Api\ProblemsClientV3;
use SphereEngine\Api\SphereEngineResponseException;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$source = 'int main() { return 0; }';
$nonexisting_compiler = 9999;
try {
    $response = $client->createJudge($source, $nonexisting_compiler);
    // response['id'] stores the ID of the created judge
} catch (SphereEngineResponseException $e) {
    if ($e->getCode() == 401) {
        echo 'Invalid access token';
    } elseif ($e->getCode() == 400) {
        echo 'Empty source';
    } elseif ($e->getCode() == 404) {
        echo 'Compiler does not exist';
    }
}
示例#14
0
<?php

/**
 * Example presents usage of the successful updateJudge() API method
*/
use SphereEngine\Api\ProblemsClientV3;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$source = 'int main() { return 0; }';
$compiler = 11;
// C language
$response = $client->updateJudge(1, $source, $compiler);
<?php

/**
 * Example presents usage of the successful getProblemTestcaseFile() API method  
 */
use SphereEngine\Api\ProblemsClientV3;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$problemCode = 'TEST';
$testcaseNumber = 0;
$file = 'input';
$response = $client->getProblemTestcaseFile($problemCode, $testcaseNumber, $file);
<?php

/**
 * Example presents error handling for getProblemTestcases() API method    
 */
use SphereEngine\Api\ProblemsClientV3;
use SphereEngine\Api\SphereEngineResponseException;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$problemCode = 'NONEXISTING_CODE';
try {
    $response = $client->getProblemTestcases($problemCode);
} catch (SphereEngineResponseException $e) {
    if ($e->getCode() == 401) {
        echo 'Invalid access token';
    } elseif ($e->getCode() == 403) {
        echo 'Access to the problem is forbidden';
    } elseif ($e->getCode() == 404) {
        echo 'Problem does not exist';
    }
}
示例#17
0
<?php

/**
 * Example presents usage of the successful getProblem() API method  
 */
use SphereEngine\Api\ProblemsClientV3;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$response = $client->getProblem("TEST");
示例#18
0
<?php

/**
 * Example presents usage of the successful getSubmission() API method  
 */
use SphereEngine\Api\ProblemsClientV3;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$response = $client->getSubmission(2016);
示例#19
0
<?php

/**
 * Example presents usage of the successful createProblem() API method  
 */
use SphereEngine\Api\ProblemsClientV3;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$code = "EXAMPLE";
$name = "Example problem";
$response = $client->createProblem($code, $name);
// response['id'] stores the ID of the created problem
<?php

/**
 * Example presents error handling for getProblem() API method    
 */
use SphereEngine\Api\ProblemsClientV3;
use SphereEngine\Api\SphereEngineResponseException;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$problemCode = 'NONEXISTING_CODE';
try {
    $response = $client->getProblem($problemCode);
} catch (SphereEngineResponseException $e) {
    if ($e->getCode() == 401) {
        echo 'Invalid access token';
    } elseif ($e->getCode() == 404) {
        echo 'Problem does not exist';
    }
}
<?php

/**
 * Example presents error handling for createProblemTestcase() API method  
*/
use SphereEngine\Api\ProblemsClientV3;
use SphereEngine\Api\SphereEngineResponseException;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$code = "EXAMPLE";
$input = "model input";
$output = "model output";
$timelimit = 5;
$nonexistingJudge = 9999;
try {
    $response = $client->createProblemTestcase($code, $input, $output, $timelimit, $nonexistingJudge);
    // response['number'] stores the number of created testcase
} catch (SphereEngineResponseException $e) {
    if ($e->getCode() == 401) {
        echo 'Invalid access token';
    } elseif ($e->getCode() == 403) {
        echo 'Access to the problem is forbidden';
    } elseif ($e->getCode() == 404) {
        // aggregates two possible reasons of 400 error
        // non existing problem and judge
示例#22
0
<?php

/**
 * Example presents authorization error handling for 
 * Sphere Engine Problems API client
*/
use SphereEngine\Api\ProblemsClientV3;
use SphereEngine\Api\SphereEngineResponseException;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = "wrong access token";
$endpoint = '<endpoint>';
$client = new ProblemsClientV3($accessToken, $endpoint);
// initialization
try {
    $client->test();
} catch (SphereEngineResponseException $e) {
    if ($e->getCode() == 401) {
        echo 'Invalid access token';
    }
}
<?php

/**
 * Example presents error handling for createSubmission() API method
*/
use SphereEngine\Api\ProblemsClientV3;
use SphereEngine\Api\SphereEngineResponseException;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$problemCode = 'TEST';
$source = 'int main() { return 0; }';
$nonexistingCompiler = 99999;
try {
    $response = $client->createSubmission($problemCode, $source, $nonexistingCompiler);
    // response['id'] stores the ID of the created submission
} catch (SphereEngineResponseException $e) {
    if ($e->getCode() == 401) {
        echo 'Invalid access token';
    } elseif ($e->getCode() == 404) {
        // aggregates three possible reasons of 404 error
        // non existing problem, compiler or user
        echo 'Non existing resource (problem, compiler or user), details available in the message: ' . $e->getMessage();
    } elseif ($e->getCode() == 400) {
        echo 'Empty source code';
    }
<?php

/**
 * Example presents usage of the successful createProblemTestcase() API method  
 */
use SphereEngine\Api\ProblemsClientV3;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$code = "EXAMPLE";
$input = "model input";
$output = "model output";
$timelimit = 5;
$judgeId = 1;
$response = $client->createProblemTestcase($code, $input, $output, $timelimit, $judgeId);
// response['number'] stores the number of created testcase
<?php

/**
 * Example presents error handling for updateJudge() API method  
*/
use SphereEngine\Api\ProblemsClientV3;
use SphereEngine\Api\SphereEngineResponseException;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$source = 'int main() { return 0; }';
$nonexistingCompiler = 9999;
try {
    $response = $client->updateJudge(1, $source, $nonexistingCompiler);
} catch (SphereEngineResponseException $e) {
    if ($e->getCode() == 401) {
        echo 'Invalid access token';
    } elseif ($e->getCode() == 400) {
        echo 'Empty source';
    } elseif ($e->getCode() == 403) {
        echo 'Access to the judge is forbidden';
    } elseif ($e->getCode() == 404) {
        // aggregates two possible reasons of 404 error
        // non existing judge or compiler
        echo 'Non existing resource (judge, compiler), details available in the message: ' . $e->getMessage();
    }
<?php

/**
 * Example presents usage of the successful getProblemTestcases() API method  
 */
use SphereEngine\Api\ProblemsClientV3;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$response = $client->getProblemTestcases("TEST");
<?php

/**
 * Example presents error handling for updateProblemActiveTestcases() API method  
*/
use SphereEngine\Api\ProblemsClientV3;
use SphereEngine\Api\SphereEngineResponseException;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$problemCode = 'NONEXISTING_CODE';
$activeTestcases = [1, 2, 3];
try {
    $response = $client->updateProblemActiveTestcases($problemCode, $activeTestcases);
} catch (SphereEngineResponseException $e) {
    if ($e->getCode() == 401) {
        echo 'Invalid access token';
    } elseif ($e->getCode() == 403) {
        echo 'Access to the problem is forbidden';
    } elseif ($e->getCode() == 400) {
        echo 'Empty problem code';
    } elseif ($e->getCode() == 404) {
        echo 'Non existing problem';
    }
}
<?php

/**
 * Example presents usage of the successful updateProblemTestcase() API method  
 */
use SphereEngine\Api\ProblemsClientV3;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$problemCode = 'TEST';
$testcaseNumber = 0;
$newInput = 'New testcase input';
$response = $client->updateProblemTestcase($problemCode, $testcaseNumber, $newInput);
<?php

/**
 * Example presents usage of the successful updateProblemActiveTestcases() API method
*/
use SphereEngine\Api\ProblemsClientV3;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$activeTestcases = [1, 2, 3];
$response = $client->updateProblemActiveTestcases('EXAMPLE', $activeTestcases);
<?php

/**
 * Example presents error handling for getJudge() API method    
 */
use SphereEngine\Api\ProblemsClientV3;
use SphereEngine\Api\SphereEngineResponseException;
// require library
require_once '../../../autoload.php';
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$nonexisting_judge_id = 999999;
try {
    $response = $client->getJudge($nonexisting_judge_id);
} catch (SphereEngineResponseException $e) {
    if ($e->getCode() == 401) {
        echo 'Invalid access token';
    } elseif ($e->getCode() == 404) {
        echo 'Judge does not exist';
    } elseif ($e->getCode() == 403) {
        echo 'Access to the judge is forbidden';
    }
}