-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move Fetcher to namespace Feed and fix CDATA parsing
- Loading branch information
Showing
5 changed files
with
172 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
namespace Nogo\Feedbox\Feed; | ||
|
||
use Guzzle\Http\Client; | ||
use Guzzle\Http\Message\Request; | ||
use Guzzle\Http\Message\Response; | ||
use Guzzle\Http\Exception\RequestException; | ||
|
||
/** | ||
* Class Fetcher | ||
* @package Nogo\Feedbox\Helper | ||
*/ | ||
class Fetcher | ||
{ | ||
/** | ||
* @var Client | ||
*/ | ||
protected $client; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $timeout = 10; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $error; | ||
|
||
/** | ||
* @param Client $client | ||
*/ | ||
public function setClient(Client $client) | ||
{ | ||
$this->client = $client; | ||
} | ||
|
||
/** | ||
* @return Client | ||
*/ | ||
public function getClient() | ||
{ | ||
return $this->client; | ||
} | ||
|
||
public function getError() | ||
{ | ||
return $this->error; | ||
} | ||
|
||
/** | ||
* Set fetcher timeout | ||
* | ||
* @param $timeout | ||
*/ | ||
public function setTimeout($timeout) | ||
{ | ||
$this->timeout = intval($timeout); | ||
} | ||
|
||
/** | ||
* Do get a request | ||
* @param $uri | ||
* @return null|string | ||
*/ | ||
public function get($uri) | ||
{ | ||
try { | ||
/** | ||
* @var $request Request | ||
*/ | ||
$request = $this->client->get($uri, array(), array( | ||
'timeout' => $this->timeout | ||
)); | ||
|
||
/** | ||
* @var $resonse Response | ||
*/ | ||
$response = $request->send(); | ||
|
||
$result = $response->getBody(true); | ||
} catch (RequestException $e) { | ||
$this->error = $e->getMessage(); | ||
$result = null; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters