Permalink
Browse files

added getGUID method, updated methods to use yql, fixed offset/limits…

… in some queries, new simpler addContact method
  • Loading branch information...
1 parent b05547a commit b0454201779342daceaf148dc889f34254ef22cb @zagraves zagraves committed May 3, 2010
Showing with 30 additions and 22 deletions.
  1. +30 −22 lib/Yahoo/YahooOAuthApplication.class.php
View
52 lib/Yahoo/YahooOAuthApplication.class.php
@@ -62,6 +62,13 @@ public function __construct($consumer_key, $consumer_secret, $application_id, $c
$this->signature_method_plaintext = new OAuthSignatureMethod_PLAINTEXT();
$this->signature_method_hmac_sha1 = new OAuthSignatureMethod_HMAC_SHA1();
}
+
+ public function getGUID()
+ {
+ if($this->token) {
+ return $this->token->yahoo_guid;
+ }
+ }
public function getOpenIDUrl($return_to = false, $lang = 'en', $openIdEndpoint = 'https://open.login.yahooapis.com/openid/op/auth')
{
@@ -195,7 +202,7 @@ public function getProfile($guid = null)
return isset($rsp->query->results) ? $rsp->query->results : false;
}
-
+
public function getProfileImages($guid = null, $size = null)
{
if($guid == null && !is_null($this->token))
@@ -245,7 +252,7 @@ public function getConnections($guid = null, $offset = 0, $limit = 10)
$guid = $this->token->yahoo_guid;
}
- $rsp = $this->yql(sprintf('SELECT * FROM social.connections WHERE owner_guid="%s"', $guid));
+ $rsp = $this->yql(sprintf('SELECT * FROM social.connections(%s,%s) WHERE owner_guid="%s"', $offset, $limit, $guid));
return isset($rsp->query->results) ? $rsp->query->results : false;
}
@@ -257,7 +264,7 @@ public function getContacts($guid = null, $offset = 0, $limit = 10)
$guid = $this->token->yahoo_guid;
}
- $rsp = $this->yql(sprintf('SELECT * FROM social.contacts WHERE guid="%s"', $guid));
+ $rsp = $this->yql(sprintf('SELECT * FROM social.contacts(%s,%s) WHERE guid="%s"', $offset, $limit, $guid));
return isset($rsp->query->results) ? $rsp->query->results : false;
}
@@ -269,15 +276,9 @@ public function getContact($guid = NULL, $cid)
$guid = $this->token->yahoo_guid;
}
- $url = sprintf(YahooOAuthClient::SOCIAL_API_URL.'/user/%s/contact/%s', $guid, $cid);
- $parameters = array('format' => 'json');
-
- $oauth_request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, 'GET', $url, $parameters);
- $oauth_request->sign_request($this->signature_method_hmac_sha1, $this->consumer, $this->token);
-
- $data = json_decode($this->client->access_resource($oauth_request));
-
- return ($data) ? $data->contact : false;
+ $rsp = $this->yql(sprintf('SELECT * from social.contacts WHERE guid="%s" AND contact_id="%s";', $guid, $cid));
+
+ return isset($rsp->query->results) ? $rsp->query->results : false;
}
public function getContactSync($guid = null, $rev = 0)
@@ -286,16 +287,10 @@ public function getContactSync($guid = null, $rev = 0)
{
$guid = $this->token->yahoo_guid;
}
-
- $url = sprintf(YahooOAuthClient::SOCIAL_API_URL.'/user/%s/contacts', $guid);
- $parameters = array('format' => 'json', 'view' => 'sync', 'rev' => $rev);
-
- $oauth_request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, 'GET', $url, $parameters);
- $oauth_request->sign_request($this->signature_method_hmac_sha1, $this->consumer, $this->token);
-
- $data = json_decode($this->client->access_resource($oauth_request));
-
- return ($data) ? $data->contactsync : false;
+
+ $rsp = $this->yql(sprintf('SELECT * from social.contacts.sync WHERE guid="%s" AND rev="%s";', $guid, $rev));
+
+ return isset($rsp->query->results) ? $rsp->query->results : false;
}
public function syncContacts($guid = null, $contactsync)
@@ -318,6 +313,19 @@ public function syncContacts($guid = null, $contactsync)
return $http['response_body'];
}
+
+ public function addSimpleContact($guid = null, $givenName, $familyName, $email, $nickname)
+ {
+ if($guid == null && !is_null($this->token))
+ {
+ $guid = $this->token->yahoo_guid;
+ }
+
+ $query = sprintf('INSERT INTO social.contacts (owner_guid, givenName, familyName, email, nickname) VALUES ("%s", "%s", "%s", "%s", "%s")', $guid, $givenName, $familyName, $email, $nickname);
+ $rsp = $this->yql($query, array(), YahooCurl::PUT);
+
+ return isset($rsp->query->results) ? $rsp->query->results : false;
+ }
public function addContact($guid = null, $contact)
{

0 comments on commit b045420

Please sign in to comment.