/**
 * Services requests based on the incoming request path
 *
 * @param   string $incoming_request_uri  The URI being visited in this script
 * @param   array  $options               Options used for Clever API requests
 */
function process_incoming_requests($incoming_request_uri, array $options)
{
    if (preg_match('/oauth/', $incoming_request_uri)) {
        try {
            $me = process_client_redirect($_GET['code'], $options);
            echo "<p>Here's some information about the user:</p>";
            echo "<ul>";
            $fields = array('type' => 'User type', 'id' => 'User ID', 'district' => 'District ID');
            foreach ($fields as $key => $label) {
                echo "<li>{$label}: {$me['data'][$key]}";
            }
            echo "</ul>";
        } catch (Exception $e) {
            echo "<p>Something exceptional happened while interacting with Clever.";
            echo "<pre>";
            print_r($e);
            echo "</pre>";
        }
    } else {
        // Our home page route will create a Clever Instant Login button for users
        $sign_in_link = generate_sign_in_with_clever_link($options);
        echo "<h1>clever_oauth_examples: Login!</h1>";
        echo '<p>' . $sign_in_link . '</p>';
        echo "<p>Ready to handle OAuth 2.0 client redirects on {$options['client_redirect_url']}.</p>";
    }
}
 public function testGenerateSignInWithCleverLink()
 {
     $our_options = prepare_options_for_clever();
     $url = generate_sign_in_with_clever_url($our_options);
     $link = generate_sign_in_with_clever_link($our_options);
     $this->assertStringStartsWith("<a href='{$url}'", $link);
     $this->assertStringEndsWith("</a>", $link);
 }