Пример #1
0
func (p *GooglePlusContactService) ConvertToDsocialContact(externalContact interface{}, originalDsocialContact *dm.Contact, dsocialUserId string) (dsocialContact *dm.Contact) {
	if externalContact == nil {
		return
	}
	if extContact, ok := externalContact.(*googleplus.Person); ok && extContact != nil {
		dsocialContact = dm.GooglePlusPersonToDsocial(extContact, originalDsocialContact, dsocialUserId)
	}
	return
}
Пример #2
0
func (p *GooglePlusContactService) RetrieveContact(client oauth2_client.OAuth2Client, ds DataStoreService, dsocialUserId string, contactId string) (*Contact, os.Error) {
	googleplusContact, err := googleplus.RetrieveContact(client, contactId, nil)
	if googleplusContact == nil || err != nil {
		return nil, err
	}
	externalServiceId := p.ServiceId()
	userInfo, err := client.RetrieveUserInfo()
	externalUserId := userInfo.Guid()
	useErr := err
	dsocialContactId := ""
	var origDsocialContact *dm.Contact = nil
	externalContactId := googleplusContact.Id
	if len(externalContactId) > 0 {
		dsocialContactId, err = ds.DsocialIdForExternalContactId(externalServiceId, externalUserId, dsocialUserId, contactId)
		if err != nil {
			useErr = err
		}
		if dsocialContactId != "" {
			origDsocialContact, _, err = ds.RetrieveDsocialContactForExternalContact(externalServiceId, externalUserId, externalContactId, dsocialUserId)
			if err != nil && useErr == nil {
				useErr = err
			}
		} else {
			ds.StoreExternalContact(externalServiceId, externalUserId, dsocialUserId, externalContactId, googleplusContact)
		}
	}
	dsocialContact := dm.GooglePlusPersonToDsocial(googleplusContact, origDsocialContact, dsocialUserId)
	contact := &Contact{
		ExternalServiceId: p.ServiceId(),
		ExternalUserId:    externalUserId,
		ExternalContactId: googleplusContact.Id,
		DsocialUserId:     dsocialUserId,
		DsocialContactId:  dsocialContactId,
		Value:             dsocialContact,
	}
	return contact, useErr
}