You are here

class OAuthHTTPFetcherResult in Feeds OAuth 7

@file Definition of the import batch object created on the fetching stage by OAuthHTTPFetcher.

Hierarchy

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

Namesort descending Modifiers Type Description Overrides
FeedsFetcherResult::$file_path protected property The path to a file where the raw data is stored.
FeedsFetcherResult::$raw protected property The raw fetched data.
FeedsFetcherResult::checkFile protected function Checks that a file exists and is readable.
FeedsFetcherResult::constructFilePath public function Constructs file name for saving the raw data.
FeedsFetcherResult::fileExists public function Returns if the file to parse exists.
FeedsFetcherResult::getFeedsInProgressDir public function Returns directory for storing files that are in progress of import.
FeedsFetcherResult::getFileContents public function Returns the contents of a file, if it exists.
FeedsFetcherResult::getFilePath public function Get a path to a temporary file containing the resource provided by the fetcher. 1
FeedsFetcherResult::rawExists public function Returns if raw data exists.
FeedsFetcherResult::sanitizeFile public function Sanitize the file in place.
FeedsFetcherResult::sanitizeRaw public function Sanitize the raw content string.
FeedsFetcherResult::sanitizeRawOptimized public function Sanitize the raw content string.
FeedsFetcherResult::saveRawToFile public function Saves the raw fetcher result to a file.
FeedsFetcherResult::__sleep public function Prevent saving the raw result when serializing object.
OAuthHTTPFetcherResult::$authenticator protected property
OAuthHTTPFetcherResult::$consumer_key protected property
OAuthHTTPFetcherResult::$consumer_secret protected property
OAuthHTTPFetcherResult::$id protected property
OAuthHTTPFetcherResult::$method protected property
OAuthHTTPFetcherResult::$site_id protected property
OAuthHTTPFetcherResult::$two protected property
OAuthHTTPFetcherResult::$uid protected property
OAuthHTTPFetcherResult::$url protected property
OAuthHTTPFetcherResult::getRaw public function Implementation of FeedsImportBatch::getRaw(). Overrides FeedsFetcherResult::getRaw
OAuthHTTPFetcherResult::__construct public function Constructor. Overrides FeedsFetcherResult::__construct