summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarim Ratib2013-06-13 06:48:02 (GMT)
committer Karim Ratib2013-06-13 06:48:02 (GMT)
commit205da7ca7533af8aa1a20a0401f32bd1d4192ff6 (patch)
tree6e9b099dac7bea96ff3982215f4245ebab60e036
parent32c5d4f29856580615995a6e21b1d4a25d9177ab (diff)
Fix FeedsOAuth results #2018041 + support GET #2017905
-rw-r--r--FeedsOAuth.inc48
-rw-r--r--OAuth2HTTPSFetcher.inc5
-rw-r--r--OAuthHTTPFetcher.inc15
3 files changed, 19 insertions, 49 deletions
diff --git a/FeedsOAuth.inc b/FeedsOAuth.inc
index 4fddf6a..9edde2b 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 '<pre>' . print_r($response, 1) . '</pre>';
- 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 845f1c5..e3e12af 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: <code>%url</code>',
+ 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 3875a8f..b377cdc 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;
}