Skip to content
stuartlewis edited this page Sep 13, 2010 · 1 revision

Example code for requesting a service document:

require("swordappclient.php");
$testurl = "http://client.swordapp.org/client/servicedocument";
$testuser = "sword-user";
$testpw = "sword-user";
//$testobo = "[email protected]";
$testsac = new SWORDAPPClient();
print "About to request servicedocument from " . $testurl . "\n";
if (empty($testuser)) { print "As: anonymous\n"; }
else { print "As: " . $testuser . "\n"; }       
$testsdr = $testsac->servicedocument(
$testurl, $testuser, $testpw, $testobo);
print "Received HTTP status code: " . $testsdr->sac_status .
" (" . $testsdr->sac_statusmessage . ")\n";
if ($testsdr->sac_status == 200) {
    print " - Version: " . $testsdr->sac_version . "\n";
    print " - Supports Verbose: " . $testsdr->sac_verbose . "\n";
    print " - Supports NoOp: " . $testsdr->sac_noop . "\n";
    print " - Maximum uplaod size: ";
    if (!empty($testsdr->sac_maxuploadsize)) {
    print $testsdr->sac_maxuploadsize . " kB\n";
    } else {
    print "undefined\n";
    }
    $workspaces = $testsdr->sac_workspaces;
    foreach ($testsdr->sac_workspaces as $workspace) {
        $wstitle = $workspace->sac_workspacetitle;
        echo "   - Workspace: ".$wstitle."\n";
        $collections = $workspace->sac_collections;
        foreach ($collections as $collection) {
            $ctitle = $collection->sac_colltitle;
            echo "     - Collection: " . $ctitle . " (" . $collection->sac_href . ")\n";
            if (count($collection->sac_accept) > 0) {
                    foreach ($collection->sac_accept as $accept) {
                            echo "        - Accepts: " . $accept . "\n";
                    }
            }
            if (count($collection->sac_acceptpackaging) > 0) {
                    foreach ($collection->sac_acceptpackaging as $acceptpackaging => $q) {
                            echo "        - Accepted packaging format: " .
                                 $acceptpackaging . " (q=" . $q . ")\n";
                    }
            }
            if (!empty($collection->sac_collpolicy)) {
                    echo "        - Collection Policy: " . $collection->sac_collpolicy . "\n";
            }
            echo "        - Collection abstract: " . $collection->sac_abstract . "\n";
            $mediation = "false";
            if ($collection->sac_mediation == true) { $mediation = "true"; }
            echo "        - Mediation: " . $mediation . "\n";
            if (!empty($collection->sac_service)) {
                    echo "        - Service document: " . $collection->sac_service . "\n";
            }
        }
    }
}
Clone this wiki locally