~ubuntu-branches/ubuntu/saucy/friends/saucy-proposed

« back to all changes in this revision

Viewing changes to friends/utils/base.py

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Jonathan Davies, Robert Bruce Park, Ubuntu daily release
  • Date: 2013-07-18 07:12:41 UTC
  • mfrom: (1.1.24)
  • Revision ID: package-import@ubuntu.com-20130718071241-cbywh3taz0e1olcq
Tags: 0.2.0+13.10.20130718-0ubuntu1
[ Jonathan Davies ]
* Add LinkedIn support.

[ Robert Bruce Park ]
* Add LinkedIn support.

[ Ubuntu daily release ]
* Automatic snapshot from revision 223

Show diffs side-by-side

added added

removed removed

Lines of Context:
201
201
        self._account = account
202
202
        self._Name = self.__class__.__name__
203
203
        self._name = self._Name.lower()
 
204
        self._address_book = 'friends-{}-contacts'.format(self._name)
204
205
 
205
206
    def _whoami(self, result):
206
207
        """Use OAuth login results to identify the authenticating user.
347
348
                account_id=self._account.id
348
349
                )
349
350
            )
350
 
# linkify the message
 
351
        # linkify the message
351
352
        orig_message = kwargs.get('message', '')
352
353
        kwargs['message'] = linkify_string(orig_message)
353
354
        args = []
544
545
        client.open_sync(False, None)
545
546
        return client
546
547
 
547
 
    def _push_to_eds(self, online_service, contact):
548
 
        source_match = self._get_eds_source(online_service)
 
548
    def _push_to_eds(self, contact):
 
549
        source_match = self._get_eds_source()
549
550
        if source_match is None:
550
551
            raise ContactsError(
551
552
                '{} does not have an address book.'.format(
552
 
                    online_service))
 
553
                    self._address_book))
553
554
        client = self._new_book_client(source_match)
554
555
        success = client.add_contact_sync(contact, None)
555
556
        if not success:
559
560
        if self._source_registry is None:
560
561
            self._source_registry = EDataServer.SourceRegistry.new_sync(None)
561
562
 
562
 
    def _create_eds_source(self, online_service):
 
563
    def _create_eds_source(self):
563
564
        self._get_eds_source_registry()
564
565
        source = EDataServer.Source.new(None, None)
565
 
        source.set_display_name(online_service)
 
566
        source.set_display_name(self._address_book)
566
567
        source.set_parent('local-stub')
567
568
        extension = source.get_extension(
568
569
            EDataServer.SOURCE_EXTENSION_ADDRESS_BOOK)
576
577
            time.sleep(2)
577
578
            return self._source_registry.ref_source(source.get_uid())
578
579
 
579
 
    def _get_eds_source(self, online_service):
 
580
    def _get_eds_source(self):
580
581
        self._get_eds_source_registry()
581
582
        for previous_source in self._source_registry.list_sources(None):
582
 
            if previous_source.get_display_name() == online_service:
 
583
            if previous_source.get_display_name() == self._address_book:
583
584
                return self._source_registry.ref_source(
584
585
                    previous_source.get_uid())
 
586
        # if we got this far, then the source doesn't exist; create it
 
587
        return self._create_eds_source()
585
588
 
586
589
    def _previously_stored_contact(self, source, field, search_term):
587
590
        client = self._new_book_client(source)
612
615
        vcard = EBookContacts.VCard.new()
613
616
        info = social_network_attrs
614
617
 
615
 
        for i in info:
616
 
            attr = EBookContacts.VCardAttribute.new('social-networking-attributes', i)
617
 
            if type(info[i]) == type(dict()):
618
 
                for j in info[i]:
619
 
                    param = EBookContacts.VCardAttributeParam.new(j)
620
 
                    param.add_value(info[i][j])
 
618
        for key, val in info.items():
 
619
            attr = EBookContacts.VCardAttribute.new(
 
620
                'social-networking-attributes', key)
 
621
            if isinstance(val, dict):
 
622
                for subkey, subval in val.items():
 
623
                    param = EBookContacts.VCardAttributeParam.new(subkey)
 
624
                    param.add_value(subval)
621
625
                    attr.add_param(param);
622
626
            else:
623
 
                attr.add_value(info[i])
 
627
                attr.add_value(val)
624
628
            vcard.add_attribute(attr)
625
629
 
626
630
        contact = EBookContacts.Contact.new_from_vcard(