1 | <?php |
||
14 | class OLFilteredHttpResponseParser extends FilteredHttpResponseParser { |
||
15 | |||
16 | /** |
||
17 | * @see https://openlibrary.org/dev/docs/api/books |
||
18 | */ |
||
19 | const OL_REST = "https://openlibrary.org/api/"; |
||
20 | |||
21 | /** |
||
22 | * @since 0.1 |
||
23 | * |
||
24 | * {@inheritDoc} |
||
25 | */ |
||
26 | 3 | public function getRawResponseById( $olID ) { |
|
27 | 3 | return $this->requestResponseFor( $olID ); |
|
28 | } |
||
29 | |||
30 | /** |
||
31 | * @since 0.1 |
||
32 | * |
||
33 | * {@inheritDoc} |
||
34 | */ |
||
35 | 5 | public function doFilterResponseById( $olID ) { |
|
36 | |||
37 | 5 | $text = $this->requestResponseFor( $olID ); |
|
38 | |||
39 | 5 | if ( $this->httpRequest->getLastError() !== '' ) { |
|
40 | 1 | return $this->addMessage( array( 'onoi-remi-request-error', $this->httpRequest->getLastError(), $olID ) ); |
|
41 | } |
||
42 | |||
43 | 4 | $json = json_decode( |
|
44 | 4 | $text, |
|
45 | true |
||
46 | 4 | ); |
|
47 | |||
48 | 4 | if ( $json === null || $json === '' || $json === array() ) { |
|
49 | 1 | return $this->addMessage( array( 'onoi-remi-response-empty', $olID ) ); |
|
50 | } |
||
51 | |||
52 | 3 | $this->doProcessJson( $json ); |
|
53 | |||
54 | 3 | $this->filteredRecord->set( 'retrieved-from', 'https://openlibrary.org/' ); |
|
55 | 3 | } |
|
56 | |||
57 | 3 | private function doProcessJson( $json ) { |
|
65 | |||
66 | /** |
||
67 | * @see https://openlibrary.org/dev/docs/api/books#data |
||
68 | * |
||
69 | * @param string $id |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | 5 | private function requestResponseFor( $id ) { |
|
92 | |||
93 | } |
||
94 |