From 6891fecd843f3ffe128d9cba320c37d53422f750 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Fri, 21 Dec 2012 09:39:20 -0500 Subject: [PATCH] Switched \VuFind\Connection\OpenLibrary to accept injected HTTP client; adjusted OpenLibrarySubjects recommendation module to perform injection. --- .../src/VuFind/Connection/OpenLibrary.php | 23 +++++-- .../VuFind/Recommend/OpenLibrarySubjects.php | 65 ++++++++++++++++++- 2 files changed, 80 insertions(+), 8 deletions(-) diff --git a/module/VuFind/src/VuFind/Connection/OpenLibrary.php b/module/VuFind/src/VuFind/Connection/OpenLibrary.php index 3bd31acfdb6..8d983a38c18 100644 --- a/module/VuFind/src/VuFind/Connection/OpenLibrary.php +++ b/module/VuFind/src/VuFind/Connection/OpenLibrary.php @@ -26,7 +26,6 @@ * @link http://vufind.org/wiki/system_classes Wiki */ namespace VuFind\Connection; -use VuFind\Http\Client as HttpClient; /** * Open Library Utilities @@ -41,6 +40,21 @@ use VuFind\Http\Client as HttpClient; */ class OpenLibrary { + /** + * HTTP client + * + * @var \Zend\Http\Client + */ + protected $client; + + /** + * Constructor + */ + public function __construct(\Zend\Http\Client $client) + { + $this->client = $client; + } + /** * Returns an array of elements for each work matching the * parameters. An API call will be made for each subjectType until @@ -111,11 +125,8 @@ class OpenLibrary // empty array to hold the result $result = array(); - //find out if there are any reviews - $client = new HttpClient(); - $client->setUri($url); - - $response = $client->setMethod('GET')->send(); + // find out if there are any reviews + $response = $this->client->setUri($url)->setMethod('GET')->send(); // Was the request successful? if ($response->isSuccess()) { // grab the response: diff --git a/module/VuFind/src/VuFind/Recommend/OpenLibrarySubjects.php b/module/VuFind/src/VuFind/Recommend/OpenLibrarySubjects.php index 42a92988456..f76e1b264ad 100644 --- a/module/VuFind/src/VuFind/Recommend/OpenLibrarySubjects.php +++ b/module/VuFind/src/VuFind/Recommend/OpenLibrarySubjects.php @@ -42,16 +42,77 @@ use VuFind\Connection\OpenLibrary, VuFind\Solr\Utils as SolrUtils; * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org/wiki/building_a_recommendations_module Wiki */ -class OpenLibrarySubjects implements RecommendInterface +class OpenLibrarySubjects implements RecommendInterface, + \VuFindHttp\HttpServiceAwareInterface { + /** + * Parameter to use for search terms + * + * @var string + */ protected $requestParam; + + /** + * Search limit + * + * @var int + */ protected $limit; + + /** + * Field to use for date filtering + * + * @var string + */ protected $pubFilter; + + /** + * Date filter to apply + * + * @var string + */ protected $publishedIn = ''; + + /** + * Subject to search for + * + * @var string + */ protected $subject; + + /** + * Subject types to use + * + * @var array + */ protected $subjectTypes; + + /** + * Result of search (false if none) + * + * @var array|bool + */ protected $result = false; + /** + * HTTP service + * + * @var \VuFindHttp\HttpServiceInterface + */ + protected $httpService = null; + + /** + * Set the HTTP service to be used for HTTP requests. + * + * @param HttpServiceInterface $service HTTP service + * + * @return void + */ + public function setHttpService(\VuFindHttp\HttpServiceInterface $service) + { + $this->httpService = $service; + } + /** * setConfig * @@ -131,7 +192,7 @@ class OpenLibrarySubjects implements RecommendInterface // Only proceed if we have a request parameter value if (!empty($this->subject)) { $result = array(); - $ol = new OpenLibrary(); + $ol = new OpenLibrary($this->httpService->createClient()); $result = $ol->getSubjects( $this->subject, $this->publishedIn, $this->subjectTypes, true, false, $this->limit, null, true -- GitLab