Skip to content

Commit

Permalink
add Yammer support
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonwoonj committed Apr 12, 2011
1 parent f9b10a0 commit 3b7d4e1
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions oauth.py
Expand Up @@ -65,6 +65,7 @@
MYSPACE = "myspace" MYSPACE = "myspace"
DROPBOX = "dropbox" DROPBOX = "dropbox"
LINKEDIN = "linkedin" LINKEDIN = "linkedin"
YAMMER = "yammer"




class OAuthException(Exception): class OAuthException(Exception):
Expand All @@ -87,6 +88,8 @@ def get_oauth_client(service, key, secret, callback_url):
return DropboxClient(key, secret, callback_url) return DropboxClient(key, secret, callback_url)
elif service == LINKEDIN: elif service == LINKEDIN:
return LinkedInClient(key, secret, callback_url) return LinkedInClient(key, secret, callback_url)
elif service == YAMMER:
return YammerClient(key, secret, callback_url)
else: else:
raise Exception, "Unknown OAuth service %s" % service raise Exception, "Unknown OAuth service %s" % service


Expand Down Expand Up @@ -581,3 +584,51 @@ def _lookup_user_info(self, access_token, access_secret):
user_info["picture"] = data["pictureUrl"] user_info["picture"] = data["pictureUrl"]
user_info["name"] = data["firstName"] + " " + data["lastName"] user_info["name"] = data["firstName"] + " " + data["lastName"]
return user_info return user_info


class YammerClient(OAuthClient):
"""Yammer Client.
A client for talking to the Yammer API using OAuth as the
authentication model.
"""

def __init__(self, consumer_key, consumer_secret, callback_url):
"""Constructor."""

OAuthClient.__init__(self,
YAMMER,
consumer_key,
consumer_secret,
"https://www.yammer.com/oauth/request_token",
"https://www.yammer.com/oauth/access_token",
callback_url)

def get_authorization_url(self):
"""Get Authorization URL."""

token = self._get_auth_token()
return ("https://www.yammer.com/oauth/authorize?oauth_token=%s"
"&oauth_callback=%s" % (token, urlquote(self.callback_url)))

def _lookup_user_info(self, access_token, access_secret):
"""Lookup User Info.
Lookup the user on Yammer
"""

user_info = self._get_default_user_info()

# Grab the user's profile from Yammer.
response = self.make_request("https://www.yammer.com/api/v1/users/current.json",
token=access_token,
secret=access_secret,
protected=False,
headers={"x-li-format":"json"})

data = json.loads(response.content)
user_info = self._get_default_user_info()
user_info["id"] = data["name"]
user_info["picture"] = data["mugshot_url"]
user_info["name"] = data["full_name"]
return user_info

0 comments on commit 3b7d4e1

Please sign in to comment.