func (p *YahooContactService) ConvertToDsocialContact(externalContact interface{}, originalDsocialContact *dm.Contact, dsocialUserId string) (dsocialContact *dm.Contact) { if externalContact == nil { return } if extContact, ok := externalContact.(*yahoo.Contact); ok && extContact != nil { dsocialContact = dm.YahooContactToDsocial(extContact, originalDsocialContact, dsocialUserId) } return }
func (p *YahooContactService) RetrieveContacts(client oauth2_client.OAuth2Client, ds DataStoreService, dsocialUserId string, next NextToken) ([]*Contact, NextToken, error) { var m url.Values m = make(url.Values) m.Add("count", "max") if next == nil { } else if start, ok := next.(int); ok { m.Add("start", strconv.Itoa(start)) } resp, err := yahoo.RetrieveContacts(client, m) if resp == nil || resp.Contacts.Contacts == nil || len(resp.Contacts.Contacts) == 0 || err != nil { return make([]*Contact, 0), nil, err } contacts := make([]*Contact, len(resp.Contacts.Contacts)) externalServiceId := p.ServiceId() userInfo, err := client.RetrieveUserInfo() externalUserId := userInfo.Guid() var useErr error = nil for i, yahooContact := range resp.Contacts.Contacts { externalContactId := strconv.FormatInt(yahooContact.Id, 10) dsocialContactId := "" var origDsocialContact *dm.Contact = nil if len(externalContactId) > 0 { dsocialContactId, err = ds.DsocialIdForExternalContactId(externalServiceId, externalUserId, dsocialUserId, externalContactId) if err != nil { useErr = err continue } if dsocialContactId != "" { origDsocialContact, _, err = ds.RetrieveDsocialContactForExternalContact(externalServiceId, externalUserId, externalContactId, dsocialUserId) if err != nil { useErr = err continue } } else { ds.StoreExternalContact(externalServiceId, externalUserId, dsocialUserId, externalContactId, &yahooContact) } } dsocialContact := dm.YahooContactToDsocial(&yahooContact, origDsocialContact, dsocialUserId) contacts[i] = &Contact{ ExternalServiceId: p.ServiceId(), ExternalUserId: externalUserId, ExternalContactId: externalContactId, DsocialUserId: dsocialUserId, DsocialContactId: dsocialContactId, Value: dsocialContact, } } return contacts, nil, useErr }
func (p *YahooContactService) RetrieveContact(client oauth2_client.OAuth2Client, ds DataStoreService, dsocialUserId string, contactId string) (*Contact, error) { resp, err := yahoo.RetrieveContact(client, contactId, nil) if resp == nil || err != nil { return nil, err } yahooContact := &resp.Contact externalServiceId := p.ServiceId() userInfo, err := client.RetrieveUserInfo() externalUserId := userInfo.Guid() useErr := err dsocialContactId := "" var origDsocialContact *dm.Contact = nil var externalContactId string if yahooContact.Id > 0 { externalContactId = strconv.FormatInt(yahooContact.Id, 10) } 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, yahooContact) } } dsocialContact := dm.YahooContactToDsocial(yahooContact, origDsocialContact, dsocialUserId) contact := &Contact{ ExternalServiceId: p.ServiceId(), ExternalUserId: externalUserId, ExternalContactId: externalContactId, DsocialUserId: dsocialUserId, DsocialContactId: dsocialContactId, Value: dsocialContact, } return contact, useErr }