Skip to content
Snippets Groups Projects
Commit 6891fecd authored by Demian Katz's avatar Demian Katz
Browse files

Switched \VuFind\Connection\OpenLibrary to accept injected HTTP client;...

Switched \VuFind\Connection\OpenLibrary to accept injected HTTP client; adjusted OpenLibrarySubjects recommendation module to perform injection.
parent 8a2115d9
No related merge requests found
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
* @link http://vufind.org/wiki/system_classes Wiki * @link http://vufind.org/wiki/system_classes Wiki
*/ */
namespace VuFind\Connection; namespace VuFind\Connection;
use VuFind\Http\Client as HttpClient;
/** /**
* Open Library Utilities * Open Library Utilities
...@@ -41,6 +40,21 @@ use VuFind\Http\Client as HttpClient; ...@@ -41,6 +40,21 @@ use VuFind\Http\Client as HttpClient;
*/ */
class OpenLibrary 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 * Returns an array of elements for each work matching the
* parameters. An API call will be made for each subjectType until * parameters. An API call will be made for each subjectType until
...@@ -111,11 +125,8 @@ class OpenLibrary ...@@ -111,11 +125,8 @@ class OpenLibrary
// empty array to hold the result // empty array to hold the result
$result = array(); $result = array();
//find out if there are any reviews // find out if there are any reviews
$client = new HttpClient(); $response = $this->client->setUri($url)->setMethod('GET')->send();
$client->setUri($url);
$response = $client->setMethod('GET')->send();
// Was the request successful? // Was the request successful?
if ($response->isSuccess()) { if ($response->isSuccess()) {
// grab the response: // grab the response:
......
...@@ -42,16 +42,77 @@ use VuFind\Connection\OpenLibrary, VuFind\Solr\Utils as SolrUtils; ...@@ -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 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/building_a_recommendations_module Wiki * @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; protected $requestParam;
/**
* Search limit
*
* @var int
*/
protected $limit; protected $limit;
/**
* Field to use for date filtering
*
* @var string
*/
protected $pubFilter; protected $pubFilter;
/**
* Date filter to apply
*
* @var string
*/
protected $publishedIn = ''; protected $publishedIn = '';
/**
* Subject to search for
*
* @var string
*/
protected $subject; protected $subject;
/**
* Subject types to use
*
* @var array
*/
protected $subjectTypes; protected $subjectTypes;
/**
* Result of search (false if none)
*
* @var array|bool
*/
protected $result = false; 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 * setConfig
* *
...@@ -131,7 +192,7 @@ class OpenLibrarySubjects implements RecommendInterface ...@@ -131,7 +192,7 @@ class OpenLibrarySubjects implements RecommendInterface
// Only proceed if we have a request parameter value // Only proceed if we have a request parameter value
if (!empty($this->subject)) { if (!empty($this->subject)) {
$result = array(); $result = array();
$ol = new OpenLibrary(); $ol = new OpenLibrary($this->httpService->createClient());
$result = $ol->getSubjects( $result = $ol->getSubjects(
$this->subject, $this->publishedIn, $this->subjectTypes, true, false, $this->subject, $this->publishedIn, $this->subjectTypes, true, false,
$this->limit, null, true $this->limit, null, true
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment