self._gc = gnome.gconf.client_get_default()
# -- Check the environment is going to work...
- #
+ # FIXME: duplication
if (self._gc.get_string('/desktop/gnome/url-handlers/http/command') == 'epiphany %s'):
raise Exception('Browser in gconf invalid (see NB#136012). Installation error.')
api_key = self._gc.get_string('/apps/maemo/hermes/linkedin_api_key')
secret_key = self._gc.get_string('/apps/maemo/hermes/linkedin_key_secret')
- # FIXME: remove this
+ # FIXME: move this to gconf and postinst
api_key = '1et4G-VtmtqNfY7gF8PHtxMOf0KNWl9ericlTEtdKJeoA4ubk4wEQwf8lSL8AnYE'
secret_key = 'uk--OtmWcxER-Yh6Py5p0VeLPNlDJSMaXj1xfHILoFzrK7fM9eepNo5RbwGdkRo_'
if api_key is None or secret_key is None:
raise Exception('No LinkedIn application keys found. Installation error.')
- self.api_key = api_key
- self.secret_key = secret_key
-
- # FIXME: move this
- token_str = "oauth_token_secret=60f817af-6437-4015-962f-cc3aefee0264&oauth_token=f89c2b7b-1c12-4f83-a469-838e78901716"
- self.access_token = oauth.OAuthToken.from_string(token_str)
+ self.access_token = self._get_access_token_from_gconf()
self.consumer = oauth.OAuthConsumer(api_key, secret_key)
self.sig_method = oauth.OAuthSignatureMethod_HMAC_SHA1()
+
+ # IMPROVEMENT: verify that the access_token is valid for at least another hour
+ self._verify_access_token()
+
+
+ def authenticate(self, need_auth, block_for_auth):
+ need_auth()
+ token = self._get_request_token()
+ url = self._get_authorize_url(token)
+ verifier = block_for_auth(url)
+ self._verify_verifier(verifier)
+
# -----------------------------------------------------------------------
def get_friends(self):
friends = self._parse_dom(dom)
return friends
+
+
+ # -----------------------------------------------------------------------
+ def _verify_verifier(self, verifier):
+ try:
+ self.access_token = self._get_access_token(self.request_token, verifier)
+ self._store_access_token_in_gconf()
+ except:
+ raise Exception("authorization failed, try again")
+
+
+ # -----------------------------------------------------------------------
+ def _verify_access_token(self):
+ return True
+
# -----------------------------------------------------------------------
+ def _store_access_token_in_gconf(self, token_str):
+ self._gc.set_string('/apps/maemo/hermes/linkedin_access_token', token_str)
+
+
+ # -----------------------------------------------------------------------
+ def _get_access_token_from_gconf(self):
+ token_str = self._gc.get_string('/apps/maemo/hermes/linkedin_access_token')
+ return oauth.OAuthToken.from_string(token_str)
+
+
+ # -----------------------------------------------------------------------
def _make_api_request(self, url):
print "_make_api_request", url
oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer, token=self.access_token, http_url=url)
# -----------------------------------------------------------------------
def _get_access_token(self, token, verifier):
- """user provides the verifier, which was displayed in the browser window"""
+ """If the verifier (which was displayed in the browser window) is valid,
+ then an access token is returned which should be used to access data on the service."""
oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer, token=token, verifier=verifier, http_url=self.ACCESS_TOKEN_URL)
oauth_request.sign_request(self.sig_method, self.consumer, token)
connection = httplib.HTTPSConnection(self.LI_SERVER)
connection.request(oauth_request.http_method, self.ACCESS_TOKEN_URL, headers=oauth_request.to_header())
response = connection.getresponse()
- return oauth.OAuthToken.from_string(response.read())
+ token_str = response.read()
+ self._store_access_token_in_gconf(token_str)
+ return oauth.OAuthToken.from_string(token_str)
# -----------------------------------------------------------------------
# -----------------------------------------------------------------------
- def _get_request_token(self, callback):
+ def _get_request_token(self):
"""Get a request token from LinkedIn"""
oauth_consumer_key = self.api_key
- oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer, callback=callback, http_url=self.REQUEST_TOKEN_URL)
+ oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer, callback="oob", http_url=self.REQUEST_TOKEN_URL)
oauth_request.sign_request(self.sig_method, self.consumer, None)
connection = httplib.HTTPSConnection(self.LI_SERVER)
token = oauth.OAuthToken.from_string(response)
return token
-
- # -----------------------------------------------------------------------
- def _do_li_login(self):
- """Perform authentication against LinkedIn and store the result in gconf
- for later use. Uses the 'need_auth' and 'block_for_auth' methods on
- the callback class. The former allows a message to warn the user
- about what is about to happen to be shown; the second is to wait
- for the user to confirm they have logged in."""
- # FIXME
#!/usr/bin/env python
-class Syncjob():
+class SyncJob():
- def __init__(self, services, originalContacts):
+ def __init__(self, services, original_contacts, progress_callback):
self._services = services
- self._originalContacts = originalContacts
+ self._original_contacts = original_contacts
+
def run(self):
self._pre_process_contacts()
self._process_friends()
self._process_contacts()
+
+
+ def create_contact_for_friend(self, friend):
+ """Creates a contact for the friend:
+ FIXME: if we do it NOW, then that contact can be re-used and mapped to other unmatched friends
+ FIXME: should this really take place here ..."""
+
+ pass
+
+
+ def register_match(self, contact, friend):
+ """Makes sure that when save is clicked,"""
+
+ def get_unmatched_friends(self):
+ pass
+
+
+ def get_updated_contacts(self):
+ pass
+
+
+ def get_matched_contacts(self):
+ pass
+
+
def _pre_process_contacts(self):
- for contact in self._originalContacts:
+ for contact in self._original_contacts:
for service in self._services:
service.pre_process_contact(contact)
+
def _process_friends(self):
for service in self._services:
service.process_friends()
+
def _process_contacts(self):
- for contact in self._originalContacts:
+ for contact in self._original_contacts:
for service in self._services:
- service.process_contact(contact)
+ service.process_contact(contact)