You are here

class OAuthHTTPFetcher in Feeds OAuth 6

Same name and namespace in other branches
  1. 7 OAuthHTTPFetcher.inc \OAuthHTTPFetcher

Support OAuth authentication.

Hierarchy

Expanded class hierarchy of OAuthHTTPFetcher

1 string reference to 'OAuthHTTPFetcher'
feeds_oauth_feeds_plugins in ./feeds_oauth.module
Implementation of hook_feed_plugins().

File

./OAuthHTTPFetcher.inc, line 45

View source
class OAuthHTTPFetcher extends FeedsHTTPFetcher {

  /**
   * Use signed URL to fetch content.
   */
  public function fetch(FeedsSource $source) {
    $source_config = $source
      ->getConfigFor($this);
    $source_node = node_load($source->feed_nid);
    global $user;
    return new OAuthHTTPBatch(trim($source_config['source']), $this->config['authenticator'], $this->config['consumer_key'], $this->config['consumer_secret'], $this->config['site_id'], $source_node ? $source_node->uid : $user->uid);
  }

  /**
   * Declare defaults.
   */
  public function configDefaults() {
    return array(
      'authenticator' => 'feeds_oauth_get_tokens',
      'site_id' => '',
      'consumer_key' => '',
      'consumer_secret' => '',
      'request_token_url' => '',
      'access_token_url' => '',
      'authorize_url' => '',
    ) + parent::configDefaults();
  }

  /**
   * Add form options.
   */
  public function configForm(&$form_state) {
    $form = parent::configForm($form_state);
    $form['use_pubsubhubbub'] = array(
      '#type' => 'value',
      '#value' => FALSE,
    );
    $form['authenticator'] = array(
      '#type' => 'select',
      '#title' => t('OAuth authenticator'),
      '#default_value' => $this->config['authenticator'],
      '#options' => module_invoke_all('feeds_oauth_authenticator'),
      '#description' => t('Choose the authentication module that provides the needed OAuth tokens.'),
    );
    $form['site_id'] = array(
      '#type' => 'textfield',
      '#title' => t('Site identifier'),
      '#default_value' => $this->config['site_id'],
      '#description' => t('Internal identifier for this connection. Callback URL on OAuth server should be suffixed with this identifier.
                           For the current configuration, callback URL will be: <code>%url</code>', array(
        '%url' => url('feeds/oauth/callback/' . $this->config['site_id'], array(
          'absolute' => TRUE,
        )),
      )),
      '#required' => TRUE,
    );
    $form['consumer_key'] = array(
      '#type' => 'textfield',
      '#title' => t('Consumer key'),
      '#default_value' => $this->config['consumer_key'],
      '#required' => TRUE,
    );
    $form['consumer_secret'] = array(
      '#type' => 'textfield',
      '#title' => t('Consumer secret'),
      '#default_value' => $this->config['consumer_secret'],
      '#required' => TRUE,
    );
    $form['request_token_url'] = array(
      '#type' => 'textfield',
      '#title' => t('Request token URL'),
      '#default_value' => $this->config['request_token_url'],
      '#required' => TRUE,
    );
    $form['access_token_url'] = array(
      '#type' => 'textfield',
      '#title' => t('Access token URL'),
      '#default_value' => $this->config['access_token_url'],
      '#required' => TRUE,
    );
    $form['authorize_url'] = array(
      '#type' => 'textfield',
      '#title' => t('Authorize URL'),
      '#default_value' => $this->config['authorize_url'],
      '#required' => TRUE,
    );
    return $form;
  }

  /**
   * Expose source form.
   */
  public function sourceForm($source_config) {
    $form = parent::sourceForm($source_config);
    global $user;
    $access_tokens = call_user_func($this->config['authenticator'], $user->uid, $this->config['site_id']);
    if (empty($access_tokens) && !empty($this->config['site_id'])) {
      drupal_set_message(t('Could not find OAuth access tokens for site %site. You should probably <a href="@url">authenticate first</a> to access protected information.', array(
        '%site' => $this->config['site_id'],
        '@url' => url('feeds/oauth/authenticate/' . $this->id),
      )), 'warning', FALSE);
    }
    return $form;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FeedsConfigurable::$config protected property
FeedsConfigurable::$disabled protected property CTools export enabled status of this object.
FeedsConfigurable::$export_type protected property
FeedsConfigurable::$id protected property
FeedsConfigurable::addConfig public function Similar to setConfig but adds to existing configuration. 1
FeedsConfigurable::configFormSubmit public function Submission handler for configForm(). 3
FeedsConfigurable::configFormValidate public function Validation handler for configForm(). 3
FeedsConfigurable::copy public function Copy a configuration. 1
FeedsConfigurable::existing public function Determine whether this object is persistent and enabled. I. e. it is defined either in code or in the database and it is enabled. 1
FeedsConfigurable::getConfig public function Implementation of getConfig(). 1
FeedsConfigurable::instance public static function Instantiate a FeedsConfigurable object. 1
FeedsConfigurable::setConfig public function Set configuration. 1
FeedsConfigurable::__get public function Override magic method __get(). Make sure that $this->config goes through getConfig()
FeedsConfigurable::__isset public function Override magic method __isset(). This is needed due to overriding __get().
FeedsFetcher::menuItem public function Menu item definition for fetchers of this class. Note how the path component in the item definition matches the return value of FeedsFetcher::path();
FeedsFetcher::path public function Construct a path for a concrete fetcher/source combination. The result of this method matches up with the general path definition in FeedsFetcher::menuItem(). For example usage look at FeedsHTTPFetcher.
FeedsHTTPFetcher::clear public function Clear caches. Overrides FeedsFetcher::clear
FeedsHTTPFetcher::importPeriod public function Implement FeedsFetcher::importPeriod(). Overrides FeedsFetcher::importPeriod
FeedsHTTPFetcher::request public function Implements FeedsFetcher::request(). Overrides FeedsFetcher::request
FeedsHTTPFetcher::sourceDelete public function Override sourceDelete() - unsubscribe from hub. Overrides FeedsPlugin::sourceDelete
FeedsHTTPFetcher::sourceFormValidate public function Override parent::sourceFormValidate(). Overrides FeedsPlugin::sourceFormValidate
FeedsHTTPFetcher::sourceSave public function Override sourceSave() - subscribe to hub. Overrides FeedsPlugin::sourceSave
FeedsHTTPFetcher::subscribe public function Implement FeedsFetcher::subscribe() - subscribe to hub. Overrides FeedsFetcher::subscribe
FeedsHTTPFetcher::subscriber protected function Convenience method for instantiating a subscriber object.
FeedsHTTPFetcher::unsubscribe public function Implement FeedsFetcher::unsubscribe() - unsubscribe from hub. Overrides FeedsFetcher::unsubscribe
FeedsPlugin::hasSourceConfig public function Returns TRUE if $this->sourceForm() returns a form. Overrides FeedsSourceInterface::hasSourceConfig
FeedsPlugin::loadMappers protected static function Loads on-behalf implementations from mappers/ directory.
FeedsPlugin::save public function Save changes to the configuration of this object. Delegate saving to parent (= Feed) which will collect information from this object by way of getConfig() and store it. Overrides FeedsConfigurable::save
FeedsPlugin::sourceDefaults public function Implementation of FeedsSourceInterface::sourceDefaults(). Overrides FeedsSourceInterface::sourceDefaults 1
FeedsPlugin::__construct protected function Constructor. Overrides FeedsConfigurable::__construct
OAuthHTTPFetcher::configDefaults public function Declare defaults. Overrides FeedsHTTPFetcher::configDefaults
OAuthHTTPFetcher::configForm public function Add form options. Overrides FeedsHTTPFetcher::configForm
OAuthHTTPFetcher::fetch public function Use signed URL to fetch content. Overrides FeedsHTTPFetcher::fetch
OAuthHTTPFetcher::sourceForm public function Expose source form. Overrides FeedsHTTPFetcher::sourceForm