class OAuthHTTPFetcherResult in Feeds OAuth 7
@file Definition of the import batch object created on the fetching stage by OAuthHTTPFetcher.
Hierarchy
- class \FeedsResult
- class \FeedsFetcherResult
- class \OAuthHTTPFetcherResult
- class \FeedsFetcherResult
Expanded class hierarchy of OAuthHTTPFetcherResult
File
- ./
OAuthHTTPFetcher.inc, line 9 - Definition of the import batch object created on the fetching stage by OAuthHTTPFetcher.
View source
class OAuthHTTPFetcherResult extends FeedsFetcherResult {
protected $url;
protected $authenticator;
protected $consumer_key;
protected $consumer_secret;
protected $id;
protected $site_id;
protected $method;
protected $uid;
protected $two;
// OAuth2 ?
/**
* Constructor.
*/
public function __construct($url, $authenticator, $consumer_key, $consumer_secret, $id, $site_id, $method, $uid, $two = FALSE) {
$this->url = $url;
$this->authenticator = $authenticator;
$this->consumer_key = $consumer_key;
$this->consumer_secret = $consumer_secret;
$this->id = $id;
$this->site_id = $site_id;
$this->method = $method;
$this->uid = $uid;
$this->two = $two;
parent::__construct('');
}
/**
* Implementation of FeedsImportBatch::getRaw().
*/
public function getRaw() {
// Get access token.
$access_token = call_user_func($this->authenticator, $this->uid, $this->site_id, $this->id);
if (empty($access_token)) {
watchdog('feeds_oauth', 'Authenticator %authenticator returned empty access token for uid %uid, site %site. Aborting.', array(
'%authenticator' => $this->authenticator,
'%uid' => $this->uid,
'%site' => $this->site_id,
), WATCHDOG_WARNING);
return array();
}
// Instantiate OAuth client.
$path = variable_get('feeds_oauth_library_path', FEEDS_OAUTH_LIBRARY_PATH_DEFAULT);
if ($this->two) {
require_once $path . '/lib/oauth/OAuth2Client.php';
$oauth = new proauth\OAuth2CurlClient(new proauth\OAuth2AccessToken($access_token['oauth_token']));
}
else {
require_once $path . '/lib/oauth/OAuthClient.php';
$oauth = new proauth\OAuthCurlClient(new proauth\OAuthConsumer($this->consumer_key, $this->consumer_secret), new proauth\OAuthSignatureHMACSHA1(), new proauth\OAuthToken($access_token['oauth_token'], $access_token['oauth_token_secret']));
}
// Make the call.
$parsed_url = parse_url($this->url);
$query = array();
if (!empty($parsed_url['query'])) {
parse_str($parsed_url['query'], $query);
}
if ($this->two) {
$query += array(
'access_token' => $oauth
->getAccessToken()
->getToken(),
);
}
try {
if ($this->method == 'post') {
$request = $oauth
->createPostRequest($this->url, $query);
}
else {
$request = $oauth
->createGetRequest($this->url, $query);
}
$response = $oauth
->executeRequest($request);
if ($response
->getStatusCode() == 200) {
return $response
->getBody();
}
else {
watchdog('feeds_oauth', print_r($response
->getBody(), TRUE), array(), WATCHDOG_ERROR);
}
} catch (Exception $e) {
watchdog('feeds_oauth', $e
->getMessage(), array(), WATCHDOG_ERROR);
}
return array();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FeedsFetcherResult:: |
protected | property | The path to a file where the raw data is stored. | |
FeedsFetcherResult:: |
protected | property | The raw fetched data. | |
FeedsFetcherResult:: |
protected | function | Checks that a file exists and is readable. | |
FeedsFetcherResult:: |
public | function | Constructs file name for saving the raw data. | |
FeedsFetcherResult:: |
public | function | Returns if the file to parse exists. | |
FeedsFetcherResult:: |
public | function | Returns directory for storing files that are in progress of import. | |
FeedsFetcherResult:: |
public | function | Returns the contents of a file, if it exists. | |
FeedsFetcherResult:: |
public | function | Get a path to a temporary file containing the resource provided by the fetcher. | 1 |
FeedsFetcherResult:: |
public | function | Returns if raw data exists. | |
FeedsFetcherResult:: |
public | function | Sanitize the file in place. | |
FeedsFetcherResult:: |
public | function | Sanitize the raw content string. | |
FeedsFetcherResult:: |
public | function | Sanitize the raw content string. | |
FeedsFetcherResult:: |
public | function | Saves the raw fetcher result to a file. | |
FeedsFetcherResult:: |
public | function | Prevent saving the raw result when serializing object. | |
OAuthHTTPFetcherResult:: |
protected | property | ||
OAuthHTTPFetcherResult:: |
protected | property | ||
OAuthHTTPFetcherResult:: |
protected | property | ||
OAuthHTTPFetcherResult:: |
protected | property | ||
OAuthHTTPFetcherResult:: |
protected | property | ||
OAuthHTTPFetcherResult:: |
protected | property | ||
OAuthHTTPFetcherResult:: |
protected | property | ||
OAuthHTTPFetcherResult:: |
protected | property | ||
OAuthHTTPFetcherResult:: |
protected | property | ||
OAuthHTTPFetcherResult:: |
public | function |
Implementation of FeedsImportBatch::getRaw(). Overrides FeedsFetcherResult:: |
|
OAuthHTTPFetcherResult:: |
public | function |
Constructor. Overrides FeedsFetcherResult:: |