Skip to content

Commit

Permalink
Merge Chullo and FedoraApi classes (#70)
Browse files Browse the repository at this point in the history
* Merge Chullo and FedoraApi classes

* Changes to tests (#1)

* chipping away at tests

* coding standards

* TEST; See if removing sections like this effect our code coverage.

* REAPER GONNA REAP

* code review

* code review
  • Loading branch information
ruebot authored and whikloj committed Apr 21, 2017
1 parent f59f935 commit 7dcef92
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 572 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ Then just `php composer.phar install` as usual.

## Usage

### Fedora
```php
use Islandora\Chullo\Chullo;

// Instantiated with static factory
$chullo = Chullo::create('http://localhost:8080/fcrepo/rest');
$chullo = FedoraApi::create('http://localhost:8080/fcrepo/rest');

// Create a new resource
$uri = $chullo->createResource(); // http://localhost:8080/fcrepo/rest/0b/0b/6c/68/0b0b6c68-30d8-410c-8a0e-154d0fd4ca20
Expand Down
270 changes: 0 additions & 270 deletions src/Chullo.php

This file was deleted.

75 changes: 75 additions & 0 deletions src/FedoraApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,79 @@ public function deleteResource(
$options
);
}

/**
* Saves RDF in Fedora.
*
* @param EasyRdf_Resource $graph Graph to save
* @param string $uri Resource URI
* @param array $headers HTTP Headers
*
* @return ResponseInterface
*/
public function saveGraph(
\EasyRdf_Graph $graph,
$uri = '',
$headers = []
) {
// Serialze the rdf.
$turtle = $graph->serialise('turtle');

// Checksum it.
$checksum_value = sha1($turtle);

// Set headers.
$headers['Content-Type'] = 'text/turtle';
$headers['digest'] = 'sha1=' . $checksum_value;

// Save it.
return $this->saveResource($uri, $turtle, $headers);
}

/**
* Creates RDF in Fedora.
*
* @param EasyRdf_Resource $graph Graph to save
* @param string $uri Resource URI
* @param array $headers HTTP Headers
*
* @return ResponseInterface
*/
public function createGraph(
\EasyRdf_Graph $graph,
$uri = '',
$headers = []
) {
// Serialze the rdf.
$turtle = $graph->serialise('turtle');

// Checksum it.
$checksum_value = sha1($turtle);

// Set headers.
$headers['Content-Type'] = 'text/turtle';
$headers['digest'] = 'sha1=' . $checksum_value;

// Save it.
return $this->createResource($uri, $turtle, $headers);
}


/**
* Gets RDF in Fedora.
*
* @param ResponseInterface $request Response received
*
* @return \EasyRdf_Graph
*/
public function getGraph(ResponseInterface $response)
{
// Extract rdf as response body and return Easy_RDF Graph object.
$rdf = $response->getBody()->getContents();
$graph = new \EasyRdf_Graph();
if (!empty($rdf)) {
$graph->parse($rdf, 'jsonld');
}
return $graph;
}
}
13 changes: 13 additions & 0 deletions src/IFedoraApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,17 @@ public function deleteResource(
$uri = "",
$headers = []
);

/**
* Saves RDF in Fedora.
*
* @param EasyRdf_Resource $rdf Graph to save
* @param string $uri Resource URI
* @param array $headers HTTP Headers
*/
public function saveGraph(
\EasyRdf_Graph $graph,
$uri = "",
$headers = []
);
}
Loading

0 comments on commit 7dcef92

Please sign in to comment.