Skip to content

Commit

Permalink
Address Islandora/documentation#302 ; Query Par… (#51)
Browse files Browse the repository at this point in the history
* Address Islandora/documentation#302 ; Query Parameters: CHECKSUM (Optional - DEPRECATED)
  • Loading branch information
ruebot authored and whikloj committed Jul 22, 2016
1 parent 1593cae commit 89a50b3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 62 deletions.
40 changes: 18 additions & 22 deletions src/Chullo.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,27 +153,24 @@ public function getGraph(
/**
* Creates a new resource in Fedora.
*
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
* @param string $checksum SHA-1 checksum
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
*
* @return string Uri of newly created resource or null if failed
*/
public function createResource(
$uri = "",
$content = null,
$headers = [],
$transaction = "",
$checksum = ""
$transaction = ""
) {
$response = $this->api->createResource(
$uri,
$content,
$headers,
$transaction,
$checksum
$transaction
);

if ($response->getStatusCode() != 201) {
Expand All @@ -188,27 +185,24 @@ public function createResource(
/**
* Saves a resource in Fedora.
*
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
* @param string $checksum SHA-1 checksum
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
*
* @return boolean True if successful
*/
public function saveResource(
$uri,
$content = null,
$headers = [],
$transaction = "",
$checksum = ""
$transaction = ""
) {
$response = $this->api->saveResource(
$uri,
$content,
$headers,
$transaction,
$checksum
$transaction
);

return $response->getStatusCode() == 204;
Expand All @@ -232,15 +226,17 @@ public function saveGraph(
$turtle = $graph->serialise('turtle');

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

// Save it.
return $this->saveResource(
$uri,
$turtle,
['Content-Type' => 'text/turtle'],
$transaction,
$checksum
[
'Content-Type' => 'text/turtle',
'digest' => 'sha1='.$checksum_value
],
$transaction
);
}

Expand Down
34 changes: 10 additions & 24 deletions src/FedoraApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,18 @@ public function getResourceOptions($uri = "")
/**
* Creates a new resource in Fedora.
*
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
* @param string $checksum SHA-1 checksum
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
*
* @return ResponseInterface
*/
public function createResource(
$uri = "",
$content = null,
$headers = [],
$transaction = "",
$checksum = ""
$transaction = ""
) {
$options = ['http_errors' => false];

Expand All @@ -162,11 +160,6 @@ public function createResource(
// Set headers.
$options['headers'] = $headers;

// Set query string.
if (!empty($checksum)) {
$options['query'] = ['checksum' => $checksum];
}

// Ensure uri takes transaction into account.
$uri = $this->prepareUri($uri, $transaction);

Expand All @@ -180,20 +173,18 @@ public function createResource(
/**
* Saves a resource in Fedora.
*
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
* @param string $checksum SHA-1 checksum
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
*
* @return ResponseInterface
*/
public function saveResource(
$uri,
$content = null,
$headers = [],
$transaction = "",
$checksum = ""
$transaction = ""
) {
$options = ['http_errors' => false];

Expand All @@ -203,11 +194,6 @@ public function saveResource(
// Set headers.
$options['headers'] = $headers;

// Set query string.
if (!empty($checksum)) {
$options['query'] = ['checksum' => $checksum];
}

// Ensure uri takes transaction into account.
$uri = $this->prepareUri($uri, $transaction);

Expand Down
24 changes: 10 additions & 14 deletions src/IFedoraApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,35 +71,31 @@ public function getResourceOptions($uri = "");
/**
* Creates a new resource in Fedora.
*
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
* @param string $checksum SHA-1 checksum
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
*/
public function createResource(
$uri = "",
$content = null,
$headers = [],
$transaction = "",
$checksum = ""
$transaction = ""
);

/**
* Saves a resource in Fedora.
*
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
* @param string $checksum SHA-1 checksum
* @param string $uri Resource URI
* @param string $content String or binary content
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
*/
public function saveResource(
$uri,
$content = null,
$headers = [],
$transaction = "",
$checksum = ""
$transaction = ""
);

/**
Expand Down
4 changes: 2 additions & 2 deletions test/CreateTransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public function testReturnsNullOtherwise()
]);

$handler = HandlerStack::create($mock);
$guzzle = new Client(['handler' => $handler]);
$guzzle = new Client(['handler' => $handler, 'base_uri' => 'http://localhost:8080/fcrepo/rest']);
$api = new FedoraApi($guzzle);
$client = new Chullo($api);

//404
$result = $client->createResource();
$result = $client->createTransaction();
$this->assertNull($result);
}
}

0 comments on commit 89a50b3

Please sign in to comment.