This commit is contained in:
Chris Rossi
2013-12-20 11:53:19 -05:00
committed by Diana Huang
parent f286296568
commit c2651497a2
2 changed files with 13 additions and 1 deletions

View File

@@ -60,6 +60,9 @@ class LinkedinAPI(object):
return query['code'][0]
def access_token_url(self, code):
"""
Construct URL for retreiving access token, given authorization code.
"""
config = self.config
return ("https://www.linkedin.com/uas/oauth2/accessToken"
"?grant_type=authorization_code"
@@ -68,6 +71,9 @@ class LinkedinAPI(object):
config['CLIENT_SECRET']))
def call_json_api(self, url):
"""
Make an HTTP call to the LinkedIn JSON API.
"""
try:
request = urllib2.Request(url, headers={'x-li-format': 'json'})
response = urllib2.urlopen(request).read()
@@ -92,12 +98,18 @@ class LinkedinAPI(object):
return access_token
def require_token(self):
"""
Raise CommandError if user has not yet obtained an access token.
"""
if self.token is None:
raise CommandError(
"You must log in to LinkedIn in order to use this script. "
"Please use the 'login' command to log in to LinkedIn.")
def batch_url(self, emails):
"""
Construct URL for querying a batch of email addresses.
"""
self.require_token()
queries = ','.join(("email=" + email for email in emails))
url = "https://api.linkedin.com/v1/people::(%s):(id)" % queries

View File

@@ -42,7 +42,7 @@ class Command(BaseCommand):
"certificate mail form will be used."),)
def __init__(self):
super(BaseCommand, self).__init__()
super(Command, self).__init__()
self.api = LinkedinAPI(self)
def handle(self, *args, **options):