diff --git a/FeedsOAuth.inc b/FeedsOAuth.inc index 4fddf6a95851fbf0ddf820aef0f0015281416c2a..9edde2b0dd62dcaf1d253b342bd9b7ca49ac4ab2 100644 --- a/FeedsOAuth.inc +++ b/FeedsOAuth.inc @@ -11,53 +11,9 @@ class FeedsOAuth { } public function fetch_feed($feed_url, $options = array()) { - $this->get($feed_url); - //$this->oauth_request($feed_url); + return $this->get($feed_url, $options); } - /* - public function oauth_request($url, $params = array(), $method = 'POST') { - $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $params); - $request->sign_request($this->signature_method, $this->consumer, $this->token); - switch ($method) { - case 'GET': - return $this->request($request->to_url()); - case 'POST': - return $this->request($request->get_normalized_http_url(), $request->get_parameters(), 'POST', $request); - } - } - - public function request($url, $params = array(), $method = 'POST', $request) { - print ' - URL = ' . print_r($url, 1); - print ' - params = ' . print_r($params, 1); - $data = ''; - if (count($params) > 0) { - if ($method == 'GET') { - $url .= '?'. http_build_query($params, '', '&'); - } - else { - $data = http_build_query($params, '', '&'); - } - } - - $headers = array(); - - $response = drupal_http_request($url, $headers, $method, $data); - print '
' . print_r($response, 1) . ''; - exit; - if (!$response->error) { - return $response->data; - } - else { - $error = $response->error; -// $data = $this->parse_response($response->data); - if ($data['error']) { - $error = $data['error']; - } - } - } - */ - public function get($path, $options = array()) { $options += array( 'get' => FALSE, @@ -131,4 +87,4 @@ class FeedsOAuth { return $obj; } -} \ No newline at end of file +} diff --git a/OAuth2HTTPSFetcher.inc b/OAuth2HTTPSFetcher.inc index 845f1c58a210e9bee7566f15e32b0b13fd964a9c..e3e12af1405356aaa180feee2af5f09f8bbf5d00 100644 --- a/OAuth2HTTPSFetcher.inc +++ b/OAuth2HTTPSFetcher.inc @@ -100,7 +100,10 @@ class OAuth2HTTPSFetcher extends FeedsHTTPFetcher { '#type' => 'textfield', '#title' => t('Site identifier'), '#default_value' => $this->config['site_id'], - '#description' => t('Internal identifier for this connection.'), + '#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:
%url
',
+ array('%url' => url('feeds/oauth2/callback/' . $this->config['site_id'], array('absolute' => TRUE)))
+ ),
'#required' => TRUE,
);
$form['consumer_key'] = array(
diff --git a/OAuthHTTPFetcher.inc b/OAuthHTTPFetcher.inc
index 3875a8fae13a321a878fd9e384643fde81edc5cd..b377cdcec599fb1820cfae7e5d86a3c8534662ed 100644
--- a/OAuthHTTPFetcher.inc
+++ b/OAuthHTTPFetcher.inc
@@ -11,18 +11,20 @@ class OAuthHTTPFetcherResult extends FeedsFetcherResult {
protected $consumer_secret;
protected $id;
protected $site_id;
+ protected $method;
protected $uid;
/**
* Constructor.
*/
- public function __construct($url, $authenticator, $consumer_key, $consumer_secret, $id, $site_id, $uid) {
+ public function __construct($url, $authenticator, $consumer_key, $consumer_secret, $id, $site_id, $method, $uid) {
$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;
parent::__construct('');
}
@@ -33,7 +35,7 @@ class OAuthHTTPFetcherResult extends FeedsFetcherResult {
public function getRaw() {
$access_token = call_user_func($this->authenticator, $this->uid, $this->site_id, $this->id);
$oauth = new FeedsOAuth($this->consumer_key, $this->consumer_secret, $access_token['oauth_token'], $access_token['oauth_token_secret']);
- $oauth->fetch_feed($this->url);
+ return $oauth->fetch_feed($this->url, array('get' => ($this->method === 'get')));
}
}
@@ -56,6 +58,7 @@ class OAuthHTTPFetcher extends FeedsHTTPFetcher {
$this->config['consumer_secret'],
$this->id,
$this->config['site_id'],
+ $this->config['method'],
$source_node ? $source_node->uid : $user->uid
);
}
@@ -72,6 +75,7 @@ class OAuthHTTPFetcher extends FeedsHTTPFetcher {
'request_token_url' => '',
'access_token_url' => '',
'authorize_url' => '',
+ 'method' => 'post',
) + parent::configDefaults();
}
@@ -128,6 +132,13 @@ class OAuthHTTPFetcher extends FeedsHTTPFetcher {
'#default_value' => $this->config['authorize_url'],
'#required' => TRUE,
);
+ $form['method'] = array(
+ '#type' => 'select',
+ '#title' => t('Method'),
+ '#default_value' => $this->config['method'],
+ '#options' => array('get' => 'GET', 'post' => 'POST'),
+ );
+
return $form;
}