use Tsugi\Core\LTIX; use Tsugi\Util\LTI; use Tsugi\Util\Net; $sanity = array('re.findall' => 'You should use re.findall() to extract the numbers'); // Compute the stuff for the output $code = $USER->id + $LINK->id + $CONTEXT->id; $sample_url = dataUrl('regex_sum_42.txt'); $actual_url = dataUrl('regex_sum_' . $code . '.txt'); $sample_data = Net::doGet($sample_url); $sample_count = strlen($sample_data); $response = Net::getLastHttpResponse(); if ($response != 200) { die("Response={$response} url={$sample_url}"); } $actual_data = Net::doGet($actual_url); $actual_count = strlen($actual_data); $response = Net::getLastHttpResponse(); if ($response != 200) { die("Response={$response} url={$actual_url}"); } $actual_matches = array(); preg_match_all('/[0-9]+/', $actual_data, $actual_matches); $actual_count = count($actual_matches[0]); $actual_sum = 0; foreach ($actual_matches[0] as $match) { $actual_sum = $actual_sum + $match; } $sample_matches = array(); preg_match_all('/[0-9]+/', $sample_data, $sample_matches); $sample_count = count($sample_matches[0]);
$p = $CFG->dbprefix; if (!$USER->instructor) { die('Must be instructor'); } $sanity = array('urllib' => 'You should use urllib to retrieve the data from the API', 'urlencode' => 'You should use urlencode add parameters to the API url', 'json' => 'You should use the json library to parse the API data'); echo "<pre>\n"; echo "Running test...\n"; // Run though all the locations // var_dump($LOCATIONS); $url = LTIX::curPageUrlScript(); $i = 500; foreach ($LOCATIONS as $key => $location) { // echo(htmlentities($location)."\n"); $api_url = str_replace('geo_test.php', 'data/geojson', $url); $sample_url = $api_url . '?sensor=false&address=' . urlencode($location); $sample_data = Net::doGet($sample_url); $sample_count = strlen($sample_data); $response = Net::getLastHttpResponse(); $sample_json = json_decode($sample_data); if ($response != 200 || $sample_json == null || !isset($sample_json->results[0])) { echo "*** Bad response={$response} url={$sample_url} json_error=" . json_last_error_msg() . "\n"; echo jsonIndent($sample_data); continue; } // echo("<pre>\n");echo(jsonIndent(json_encode($sample_json)));echo("</pre>\n"); if (!isset($sample_json->results[0]->place_id)) { echo "*** Could not find place_id {$location}\n"; // echo(jsonIndent($sample_data)); continue; } $sample_place = $sample_json->results[0]->place_id;
public function testGet() { $stuff = Net::doGet("http://www.dr-chuck.com/page1.htm"); $this->assertContains("The First Page", $stuff); }
public static function sendOAuthGET($endpoint, $oauth_consumer_key, $oauth_consumer_secret, $accept_type, $signature = false) { $test_token = ''; $hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); if ($signature == "HMAC-SHA256") { $hmac_method = new OAuthSignatureMethod_HMAC_SHA256(); } $test_consumer = new OAuthConsumer($oauth_consumer_key, $oauth_consumer_secret, NULL); $parms = array(); $acc_req = OAuthRequest::from_consumer_and_token($test_consumer, $test_token, "GET", $endpoint, $parms); $acc_req->sign_request($hmac_method, $test_consumer, $test_token); // Pass this back up "out of band" for debugging global $LastOAuthBodyBaseString; $LastOAuthBodyBaseString = $acc_req->get_signature_base_string(); $header = $acc_req->to_header(); $header = $header . "\r\nAccept: " . $accept_type . "\r\n"; global $LastGETHeader; $LastGETHeader = $header; return Net::doGet($endpoint, $header); }
echo "key_sha256=" . $key_sha256 . "<br>"; $oldproxy = $PDOX->rowDie("SELECT user_id\n FROM {$CFG->dbprefix}lti_key\n WHERE key_sha256 = :SHA LIMIT 1", array(":SHA" => $key_sha256)); if (is_array($oldproxy) && $oldproxy['user_id'] != $_SESSION['id']) { lmsDie("Registration key {$reg_key} cannot be registered."); } $reg_password = $_POST['reg_password']; } else { echo "</pre>"; lmsDie("lti_message_type not supported " . $lti_message_type); } } $launch_presentation_return_url = $_POST['launch_presentation_return_url']; $tc_profile_url = $_POST['tc_profile_url']; if (strlen($tc_profile_url) > 1) { echo "Retrieving profile from " . $tc_profile_url . "\n"; $tc_profile_json = Net::doGet($tc_profile_url); echo "Retrieved " . strlen($tc_profile_json) . " characters.\n"; echo "</pre>\n"; $OUTPUT->togglePre("Retrieved Consumer Profile", $tc_profile_json); $tc_profile = json_decode($tc_profile_json); if ($tc_profile == null) { lmsDie("Unable to parse tc_profile error=" . json_last_error()); } } else { lmsDie("We must have a tc_profile_url to continue..."); } // Find the registration URL echo "<pre>\n"; $tc_services = $tc_profile->service_offered; echo "Found " . count($tc_services) . " services profile..\n"; if (count($tc_services) < 1) {
$updated_at = $row['updated_at']; $updated_time = strtotime($updated_at); $datediff = $now - $updated_time; $json_content = json_decode($row['json_content']); if ($json_content == null) { error_log("JSON error in cache for {$address}: " . json_last_error_msg()); } if ($json_content != null && $datediff < $expire_seconds) { error_log("Retrieved {$address} from cache delta={$datediff} updated_at=" . $row['updated_at']); echo jsonIndent(json_encode($json_content)); return; } } // Must retrieve the information $getUrl = 'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=' . urlencode($address); $data = Net::doGet($getUrl); $response = Net::getLastHttpResponse(); $json_data = json_decode($data); if ($json_data == null) { error_log("JSON error from Google for {$address}: " . json_last_error_msg()); error_log($data); } // If there is a problem and we have cache even if expired, use cached copy if ($json_data == null || $response != 200) { if ($json_content != null) { error_log("Error {$response} on {$getUrl} - cached copy used"); echo jsonIndent(json_encode($json_content)); return; } error_log("Error {$response} on {$getUrl}"); http_response_code($response);
function getJsonOrDie($sample_url) { $sample_data = Net::doGet($sample_url); $sample_count = strlen($sample_data); $response = Net::getLastHttpResponse(); $sample_json = json_decode($sample_data); if ($response != 200 || $sample_json == null) { error_log("DIE: Sample response={$response} url={$sample_url} json_error=" . json_last_error_msg()); die("Sample response={$response} url={$sample_url} json_error=" . json_last_error_msg()); } return $sample_json; }
} $reg_password = $_POST['reg_password']; } else { echo "</pre>"; lmsDie("lti_message_type not supported " . $lti_message_type); } } if ($tool_proxy_guid_from_consumer) { echo "We Received a tool_proxy_guid= {$tool_proxy_guid} \n"; } $launch_presentation_return_url = $_POST['launch_presentation_return_url']; $tc_profile_url = $_POST['tc_profile_url']; if (strlen($tc_profile_url) > 1) { echo "Retrieving profile from " . $tc_profile_url . "\n"; $header = "Accept: application/vnd.ims.lti.v2.toolconsumerprofile+json"; $tc_profile_json = Net::doGet($tc_profile_url, $header); echo "Retrieved " . strlen($tc_profile_json) . " characters.\n"; echo "</pre>\n"; $OUTPUT->togglePre("Retrieved Consumer Profile", $tc_profile_json); $tc_profile = json_decode($tc_profile_json); if ($tc_profile == null) { lmsDie("Unable to parse tc_profile error=" . json_last_error()); } } else { lmsDie("We must have a tc_profile_url to continue..."); } // Find the registration URL echo "<pre>\n"; $tc_services = $tc_profile->service_offered; echo "Found " . count($tc_services) . " services profile..\n"; if (count($tc_services) < 1) {