Skip to content

Commit

Permalink
Merge pull request #4 from onoi/tidy
Browse files Browse the repository at this point in the history
Tidy some method names
  • Loading branch information
mwjames committed Sep 21, 2016
2 parents 2902cd8 + d775877 commit b8eebcb
Show file tree
Hide file tree
Showing 20 changed files with 94 additions and 39 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -49,7 +49,7 @@ $crossRefFilteredHttpResponseParser = $filteredHttpResponseParserFactory->newCro
new FilteredRecord()
)

$crossRefFilteredHttpResponseParser->doFilterResponseFor( '10.1126/science.1152662' );
$crossRefFilteredHttpResponseParser->doFilterResponseById( '10.1126/science.1152662' );

$filteredRecord = new FilteredRecord();
$filteredRecord->setRedactedFields( array( 'pages', 'abstract' ) );
Expand All @@ -58,12 +58,12 @@ $pubMedFilteredHttpResponseParser = $filteredHttpResponseParserFactory->newNcbiP
$filteredRecord
)

$pubMedFilteredHttpResponseParser->doFilterResponseFor( '19782018' );
$pubMedFilteredHttpResponseParser->doFilterResponseById( '19782018' );
```
The `FilteredHttpResponseParser` (implementing the `ResponseParser` interface) returns a
simple `array` filtered from a REST response.

`FilteredHttpResponseParser::doFilterResponseFor` is not expected to make any input validation (in terms of
`FilteredHttpResponseParser::doFilterResponseById` is not expected to make any input validation (in terms of
format or range) for the requested response therefore the implementing class is responsible for an appropriate
validation process.

Expand Down
4 changes: 2 additions & 2 deletions src/CrossRef/CrossRefFilteredHttpResponseParser.php
Expand Up @@ -23,7 +23,7 @@ class CrossRefFilteredHttpResponseParser extends FilteredHttpResponseParser {
*
* {@inheritDoc}
*/
public function getRawResponse( $doi ) {
public function getRawResponseById( $doi ) {
return $this->requestResponseFor( $doi );
}

Expand All @@ -32,7 +32,7 @@ public function getRawResponse( $doi ) {
*
* {@inheritDoc}
*/
public function doFilterResponseFor( $doi ) {
public function doFilterResponseById( $doi ) {

$json = json_decode(
$this->requestResponseFor( $doi ),
Expand Down
31 changes: 29 additions & 2 deletions src/FilteredHttpResponseParser.php
Expand Up @@ -71,6 +71,15 @@ public function getFilteredRecord() {
* {@inheritDoc}
*/
public function usesCache() {
return $this->isFromCache();
}

/**
* @since 0.1
*
* {@inheritDoc}
*/
public function isFromCache() {
return method_exists( $this->httpRequest, 'isCached' ) ? $this->httpRequest->isCached() : false;
}

Expand All @@ -79,13 +88,31 @@ public function usesCache() {
*
* {@inheritDoc}
*/
abstract public function doFilterResponseFor( $query );
public function doFilterResponseFor( $id ) {
return $this->doFilterResponseById( $id );
}

/**
* @since 0.1
*
* {@inheritDoc}
*/
abstract public function getRawResponse( $query );
public function getRawResponse( $id ) {
return $this->getRawResponseById( $id );
}

/**
* @since 0.3
*
* {@inheritDoc}
*/
abstract public function doFilterResponseById( $id );

/**
* @since 0.3
*
* {@inheritDoc}
*/
abstract public function getRawResponseById( $id );

}
4 changes: 2 additions & 2 deletions src/Ncbi/NcbiPubMedFilteredHttpResponseParser.php
Expand Up @@ -26,7 +26,7 @@ class NcbiPubMedFilteredHttpResponseParser extends FilteredHttpResponseParser {
*
* {@inheritDoc}
*/
public function getRawResponse( $id ) {
public function getRawResponseById( $id ) {

$db = $this->filteredRecord->get( 'ncbi-dbtype' );

Expand All @@ -38,7 +38,7 @@ public function getRawResponse( $id ) {
*
* {@inheritDoc}
*/
public function doFilterResponseFor( $id ) {
public function doFilterResponseById( $id ) {

$db = $this->filteredRecord->get( 'ncbi-dbtype' );

Expand Down
25 changes: 25 additions & 0 deletions src/NullResponseParser.php
Expand Up @@ -51,13 +51,38 @@ public function usesCache() {
return false;
}

/**
* @since 0.3
*
* {@inheritDoc}
*/
public function isFromCache() {
return false;
}

/**
* @since 0.3
*
* {@inheritDoc}
*/
public function doFilterResponseById( $query ) {}

/**
* @since 0.1
*
* {@inheritDoc}
*/
public function doFilterResponseFor( $query ) {}

/**
* @since 0.3
*
* {@inheritDoc}
*/
public function getRawResponseById( $query ) {
return '';
}

/**
* @since 0.1
*
Expand Down
4 changes: 2 additions & 2 deletions src/Oclc/OclcFilteredHttpResponseParser.php
Expand Up @@ -23,7 +23,7 @@ class OclcFilteredHttpResponseParser extends FilteredHttpResponseParser {
*
* {@inheritDoc}
*/
public function getRawResponse( $oclcID ) {
public function getRawResponseById( $oclcID ) {
return $this->requestResponseFor( $oclcID );
}

Expand All @@ -32,7 +32,7 @@ public function getRawResponse( $oclcID ) {
*
* {@inheritDoc}
*/
public function doFilterResponseFor( $oclcID ) {
public function doFilterResponseById( $oclcID ) {

$text = $this->requestResponseFor( $oclcID );

Expand Down
4 changes: 2 additions & 2 deletions src/OpenLibrary/OLFilteredHttpResponseParser.php
Expand Up @@ -23,7 +23,7 @@ class OLFilteredHttpResponseParser extends FilteredHttpResponseParser {
*
* {@inheritDoc}
*/
public function getRawResponse( $olID ) {
public function getRawResponseById( $olID ) {
return $this->requestResponseFor( $olID );
}

Expand All @@ -32,7 +32,7 @@ public function getRawResponse( $olID ) {
*
* {@inheritDoc}
*/
public function doFilterResponseFor( $olID ) {
public function doFilterResponseById( $olID ) {

$text = $this->requestResponseFor( $olID );

Expand Down
3 changes: 3 additions & 0 deletions src/ResponseParser.php
Expand Up @@ -29,13 +29,15 @@ public function getMessages();
*
* @return boolean
*/
//public function isFromCache();
public function usesCache();

/**
* @since 0.1
*
* @param string $id
*/
//public function doFilterResponseById( $id );
public function doFilterResponseFor( $id );

/**
Expand All @@ -45,6 +47,7 @@ public function doFilterResponseFor( $id );
*
* @return string
*/
//public function getRawResponseById( $id );
public function getRawResponse( $id );

}
4 changes: 2 additions & 2 deletions src/Viaf/ViafFilteredHttpResponseParser.php
Expand Up @@ -24,7 +24,7 @@ class ViafFilteredHttpResponseParser extends FilteredHttpResponseParser {
*
* {@inheritDoc}
*/
public function getRawResponse( $viafID ) {
public function getRawResponseById( $viafID ) {
return $this->requestResponseFor( $viafID );
}

Expand All @@ -33,7 +33,7 @@ public function getRawResponse( $viafID ) {
*
* {@inheritDoc}
*/
public function doFilterResponseFor( $viafID ) {
public function doFilterResponseById( $viafID ) {

$xml = $this->requestResponseFor( $viafID );

Expand Down
Expand Up @@ -44,10 +44,10 @@ public function testParser( $id, $httpRequestFile, $expectedResultFile ) {

$this->assertEquals(
$contents,
$instance->getRawResponse( $id )
$instance->getRawResponseById( $id )
);

$instance->doFilterResponseFor( $id );
$instance->doFilterResponseById( $id );

$this->assertJsonStringEqualsJsonFile(
$expectedResultFile,
Expand Down
Expand Up @@ -37,10 +37,10 @@ public function testPMIDParser( $id, $httpJsonRequestFile, $httpXmlRequestFile,

$this->assertEquals(
$jsonContents . $xmlContents,
$instance->getRawResponse( $id )
$instance->getRawResponseById( $id )
);

$instance->doFilterResponseFor( $id );
$instance->doFilterResponseById( $id );

$this->assertJsonStringEqualsJsonFile(
$expectedResultFile,
Expand Down Expand Up @@ -70,10 +70,10 @@ public function testPMCIDParser( $id, $httpJsonRequestFile, $httpXmlRequestFile,

$this->assertEquals(
$jsonContents . $xmlContents,
$instance->getRawResponse( $id )
$instance->getRawResponseById( $id )
);

$instance->doFilterResponseFor( $id );
$instance->doFilterResponseById( $id );

$this->assertJsonStringEqualsJsonFile(
$expectedResultFile,
Expand Down
Expand Up @@ -44,10 +44,10 @@ public function testParser( $id, $httpRequestFile, $expectedResultFile ) {

$this->assertEquals(
$contents,
$instance->getRawResponse( $id )
$instance->getRawResponseById( $id )
);

$instance->doFilterResponseFor( $id );
$instance->doFilterResponseById( $id );

$this->assertJsonStringEqualsJsonFile(
$expectedResultFile,
Expand Down
Expand Up @@ -44,10 +44,10 @@ public function testParser( $id, $httpRequestFile, $expectedResultFile ) {

$this->assertEquals(
$contents,
$instance->getRawResponse( $id )
$instance->getRawResponseById( $id )
);

$instance->doFilterResponseFor( $id );
$instance->doFilterResponseById( $id );

$this->assertJsonStringEqualsJsonFile(
$expectedResultFile,
Expand Down
Expand Up @@ -44,10 +44,10 @@ public function testParser( $id, $httpRequestFile, $expectedResultFile ) {

$this->assertEquals(
$contents,
$instance->getRawResponse( $id )
$instance->getRawResponseById( $id )
);

$instance->doFilterResponseFor( $id );
$instance->doFilterResponseById( $id );

$this->assertJsonStringEqualsJsonFile(
$expectedResultFile,
Expand Down
Expand Up @@ -50,7 +50,7 @@ public function testFailedResponse() {
$filteredRecord
);

$instance->doFilterResponseFor( 'foo' );
$instance->doFilterResponseById( 'foo' );

$this->assertEquals(
array( array(
Expand Down Expand Up @@ -81,7 +81,7 @@ public function testNullResponse() {
$filteredRecord
);

$instance->doFilterResponseFor( 'foo' );
$instance->doFilterResponseById( 'foo' );

$this->assertEquals(
array( array(
Expand Down
Expand Up @@ -50,7 +50,7 @@ public function testFailedResponse() {
$filteredRecord
);

$instance->doFilterResponseFor( 'foo' );
$instance->doFilterResponseById( 'foo' );

$this->assertEquals(
array( array(
Expand Down Expand Up @@ -81,7 +81,7 @@ public function testNullResponse() {
$filteredRecord
);

$instance->doFilterResponseFor( 'foo' );
$instance->doFilterResponseById( 'foo' );

$this->assertEquals(
array( array(
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/Unit/NullResponseParserTest.php
Expand Up @@ -49,11 +49,11 @@ public function testCommonMethods() {
);

$this->assertNull(
$instance->doFilterResponseFor( 42 )
$instance->doFilterResponseById( 42 )
);

$this->assertEmpty(
$instance->getRawResponse( 42 )
$instance->getRawResponseById( 42 )
);
}

Expand Down
Expand Up @@ -50,7 +50,7 @@ public function testFailedResponse() {
$filteredRecord
);

$instance->doFilterResponseFor( 'foo' );
$instance->doFilterResponseById( 'foo' );

$this->assertEquals(
array( array(
Expand Down Expand Up @@ -81,7 +81,7 @@ public function testNullResponse() {
$filteredRecord
);

$instance->doFilterResponseFor( 'foo' );
$instance->doFilterResponseById( 'foo' );

$this->assertEquals(
array( array(
Expand Down
Expand Up @@ -50,7 +50,7 @@ public function testFailedResponse() {
$filteredRecord
);

$instance->doFilterResponseFor( 'foo' );
$instance->doFilterResponseById( 'foo' );

$this->assertEquals(
array( array(
Expand Down Expand Up @@ -81,7 +81,7 @@ public function testNullResponse() {
$filteredRecord
);

$instance->doFilterResponseFor( 'foo' );
$instance->doFilterResponseById( 'foo' );

$this->assertEquals(
array( array(
Expand Down

0 comments on commit b8eebcb

Please sign in to comment.