Skip to content

Commit

Permalink
Clarify method names
Browse files Browse the repository at this point in the history
  • Loading branch information
mwjames committed Sep 25, 2015
1 parent fedc1a4 commit 4118e5f
Show file tree
Hide file tree
Showing 21 changed files with 86 additions and 84 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ is now being deployed as independent library. Supported providers are:

## Requirements

PHP 5.3 / HHVM 3.3 or later
PHP 5.3 / HHVM 3.5 or later

## Installation

Expand All @@ -28,7 +28,7 @@ The recommended installation method for this library is to add the dependency to
```json
{
"require": {
"onoi/remi": "~0.1"
"onoi/remi": "~0.2"
}
}
```
Expand All @@ -49,7 +49,7 @@ $crossRefFilteredHttpResponseParser = $filteredHttpResponseParserFactory->newCro
new FilteredRecord()
)

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

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

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

`FilteredHttpResponseParser::doParseFor` 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
`FilteredHttpResponseParser::doFilterResponseFor` 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.

`FilteredRecord::setRedactedFields` can be used to remove selected fields from the record.
Expand All @@ -85,6 +85,8 @@ The library provides unit tests that covers the core-functionality normally run

### Release notes

- 0.2 (2015-09-25)
- Changed `ResponseParser` interface to clarify method names
- 0.1 (2015-08-03) Initial release
- Added `ResponseParser` interface
- Added `FilteredHttpResponseParserFactory` to provide access to CrossRef, VIAF, PubMed, OCLC, and OpenLibrary REST API
Expand Down
4 changes: 2 additions & 2 deletions src/CrossRef/CrossRefFilteredHttpResponseParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getRawResponse( $doi ) {
*
* {@inheritDoc}
*/
public function doParseFor( $doi ) {
public function doFilterResponseFor( $doi ) {

$json = json_decode(
$this->requestResponseFor( $doi ),
Expand All @@ -53,7 +53,7 @@ public function doParseFor( $doi ) {
private function doProcessCiteproc( $json ) {

$crossRefCiteprocJsonProcessor = new CrossRefCiteprocJsonProcessor(
$this->getRecord()
$this->getFilteredRecord()
);

$crossRefCiteprocJsonProcessor->doProcess( $json );
Expand Down
16 changes: 8 additions & 8 deletions src/FilteredHttpResponseParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class FilteredHttpResponseParser implements ResponseParser {
/**
* @var FilteredRecord
*/
protected $record;
protected $filteredRecord;

/**
* @var array
Expand All @@ -31,11 +31,11 @@ abstract class FilteredHttpResponseParser implements ResponseParser {
* @since 0.1
*
* @param HttpRequest $httpRequest
* @param FilteredRecord $record
* @param FilteredRecord $filteredRecord
*/
public function __construct( HttpRequest $httpRequest, FilteredRecord $record ) {
public function __construct( HttpRequest $httpRequest, FilteredRecord $filteredRecord ) {
$this->httpRequest = $httpRequest;
$this->record = $record;
$this->filteredRecord = $filteredRecord;
}

/**
Expand All @@ -61,16 +61,16 @@ public function getMessages() {
*
* {@inheritDoc}
*/
public function getRecord() {
return $this->record;
public function getFilteredRecord() {
return $this->filteredRecord;
}

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

Expand All @@ -79,7 +79,7 @@ public function usedCache() {
*
* {@inheritDoc}
*/
abstract public function doParseFor( $query );
abstract public function doFilterResponseFor( $query );

/**
* @since 0.1
Expand Down
34 changes: 17 additions & 17 deletions src/Ncbi/NcbiPubMedFilteredHttpResponseParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class NcbiPubMedFilteredHttpResponseParser extends FilteredHttpResponseParser {
*/
public function getRawResponse( $id ) {

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

return $this->requestSummaryResponseFor( $id, $db ) . $this->requestAbstractResponseFor( $id, $db );
}
Expand All @@ -38,9 +38,9 @@ public function getRawResponse( $id ) {
*
* {@inheritDoc}
*/
public function doParseFor( $id ) {
public function doFilterResponseFor( $id ) {

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

$text = $this->requestSummaryResponseFor( $id, $db );

Expand Down Expand Up @@ -78,49 +78,49 @@ private function doProcessSummary( $text, $id, $db ) {

if ( isset( $record['pubtype'] ) ) {
foreach ( $record['pubtype'] as $type ) {
$this->getRecord()->append( 'type', $type );
$this->filteredRecord->append( 'type', $type );
}
}

foreach ( $record['articleids'] as $articleids ) {

if ( $articleids['idtype'] === 'doi' ) {
$this->getRecord()->set( 'doi', $articleids['value'] );
$this->filteredRecord->set( 'doi', $articleids['value'] );
}

if ( $articleids['idtype'] === 'pmid' ) {
$this->getRecord()->set( 'pmid', $articleids['value'] );
$this->filteredRecord->set( 'pmid', $articleids['value'] );
}

if ( $articleids['idtype'] === 'pubmed' ) {
$this->getRecord()->set( 'pmid', $articleids['value'] );
$this->filteredRecord->set( 'pmid', $articleids['value'] );
}

if ( $articleids['idtype'] === 'pmcid' && $db === 'pmc' ) {
$this->getRecord()->set( 'pmcid', $articleids['value'] );
$this->filteredRecord->set( 'pmcid', $articleids['value'] );
}

if ( $articleids['idtype'] === 'pmc' && $db === 'pubmed' ) {
$this->getRecord()->set( 'pmcid', $articleids['value'] );
$this->filteredRecord->set( 'pmcid', $articleids['value'] );
}
}

foreach ( $record['authors'] as $author ) {
$this->getRecord()->append( 'author', $author['name'] );
$this->filteredRecord->append( 'author', $author['name'] );
}

$this->getRecord()->set( 'title', $record['title'] );
$this->getRecord()->set( 'journal', $record['fulljournalname'] );
$this->getRecord()->set( 'pubdate', $record['pubdate'] );
$this->getRecord()->set( 'volume', $record['volume'] );
$this->getRecord()->set( 'issue', $record['issue'] );
$this->getRecord()->set( 'pages', $record['pages'] );
$this->filteredRecord->set( 'title', $record['title'] );
$this->filteredRecord->set( 'journal', $record['fulljournalname'] );
$this->filteredRecord->set( 'pubdate', $record['pubdate'] );
$this->filteredRecord->set( 'volume', $record['volume'] );
$this->filteredRecord->set( 'issue', $record['issue'] );
$this->filteredRecord->set( 'pages', $record['pages'] );
}

private function doProcessAbstract( $xml ) {

$ncbiEntrezAbstractXMLProcessor = new NcbiEntrezAbstractXMLProcessor(
$this->getRecord()
$this->filteredRecord
);

$ncbiEntrezAbstractXMLProcessor->doProcess( $xml );
Expand Down
16 changes: 8 additions & 8 deletions src/NullResponseParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ class NullResponseParser implements ResponseParser {
/**
* @var FilteredRecord
*/
private $record;
private $filteredRecord;

/**
* @since 0.1
*
* @param FilteredRecord $record
* @param FilteredRecord $filteredRecord
*/
public function __construct( FilteredRecord $record ) {
$this->record = $record;
public function __construct( FilteredRecord $filteredRecord ) {
$this->filteredRecord = $filteredRecord;
}

/**
* @since 0.1
*
* {@inheritDoc}
*/
public function getRecord() {
return $this->record;
public function getFilteredRecord() {
return $this->filteredRecord;
}

/**
Expand All @@ -47,7 +47,7 @@ public function getMessages() {
*
* {@inheritDoc}
*/
public function usedCache() {
public function usesCache() {
return false;
}

Expand All @@ -56,7 +56,7 @@ public function usedCache() {
*
* {@inheritDoc}
*/
public function doParseFor( $query ) {}
public function doFilterResponseFor( $query ) {}

/**
* @since 0.1
Expand Down
4 changes: 2 additions & 2 deletions src/Oclc/OclcFilteredHttpResponseParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getRawResponse( $oclcID ) {
*
* {@inheritDoc}
*/
public function doParseFor( $oclcID ) {
public function doFilterResponseFor( $oclcID ) {

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

Expand All @@ -52,7 +52,7 @@ public function doParseFor( $oclcID ) {
private function doProcessJsonLd( $oclcID, $jsonld ) {

$simpleOclcJsonLdGraphProcessor = new SimpleOclcJsonLdGraphProcessor(
$this->getRecord()
$this->filteredRecord
);

$simpleOclcJsonLdGraphProcessor->doProcess( $oclcID, $jsonld );
Expand Down
4 changes: 2 additions & 2 deletions src/OpenLibrary/OLFilteredHttpResponseParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getRawResponse( $olID ) {
*
* {@inheritDoc}
*/
public function doParseFor( $olID ) {
public function doFilterResponseFor( $olID ) {

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

Expand All @@ -55,7 +55,7 @@ public function doParseFor( $olID ) {
private function doProcessJson( $json ) {

$olBooksAPIJsonProcessor = new OLBooksAPIJsonProcessor(
$this->getRecord()
$this->filteredRecord
);

$olBooksAPIJsonProcessor->doProcess( $json );
Expand Down
12 changes: 6 additions & 6 deletions src/ResponseParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface ResponseParser {
*
* @return FilteredRecord
*/
public function getRecord();
public function getFilteredRecord();

/**
* @since 0.1
Expand All @@ -29,22 +29,22 @@ public function getMessages();
*
* @return boolean
*/
public function usedCache();
public function usesCache();

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

/**
* @since 0.1
*
* @param string $query
* @param string $id
*
* @return string
*/
public function getRawResponse( $query );
public function getRawResponse( $id );

}
10 changes: 5 additions & 5 deletions src/Viaf/ViafFilteredHttpResponseParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function getRawResponse( $viafID ) {
*
* {@inheritDoc}
*/
public function doParseFor( $viafID ) {
public function doFilterResponseFor( $viafID ) {

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

Expand Down Expand Up @@ -63,16 +63,16 @@ private function doProcessDom( $dom, $viafID ) {
return $this->addMessage( array( 'onoi-remi-parser-no-id-match', $viafID ) );
}

$this->getRecord()->set( 'viaf', $viafID );
$this->filteredRecord->set( 'viaf', $viafID );

foreach ( $dom->getElementsByTagName( 'nameType' ) as $item ) {
$this->getRecord()->set( 'type', $item->nodeValue );
$this->filteredRecord->set( 'type', $item->nodeValue );
}

foreach ( $dom->getElementsByTagName( 'sources' ) as $item ) {
foreach ( $item->getElementsByTagName( 'source' ) as $i ) {
list( $key, $value ) = explode( '|', $i->nodeValue, 2 );
$this->getRecord()->set( strtolower( $key ), str_replace( ' ' ,'', $value ) );
$this->filteredRecord->set( strtolower( $key ), str_replace( ' ' ,'', $value ) );
}
}

Expand All @@ -81,7 +81,7 @@ private function doProcessDom( $dom, $viafID ) {
foreach ( $dom->getElementsByTagName( 'data' ) as $item ) {

foreach ( $item->getElementsByTagName( 'text' ) as $i ) {
$this->getRecord()->set( 'name', str_replace( '.', '', $i->nodeValue ) );
$this->filteredRecord->set( 'name', str_replace( '.', '', $i->nodeValue ) );
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public function testParser( $id, $httpRequestFile, $expectedResultFile ) {
$instance->getRawResponse( $id )
);

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

$this->assertEquals(
$expected,
$instance->getRecord()->getRecordFields()
$instance->getFilteredRecord()->getRecordFields()
);
}

Expand Down
Loading

0 comments on commit 4118e5f

Please sign in to comment.