Exemple #1
0
func (p *GoogleContactService) ConvertToDsocialGroup(externalGroup interface{}, originalDsocialGroup *dm.Group, dsocialUserId string) (dsocialGroup *dm.Group) {
	if externalGroup == nil {
		return
	}
	if extGroup, ok := externalGroup.(*google.ContactGroup); ok && extGroup != nil {
		dsocialGroup = dm.GoogleGroupToDsocial(extGroup, originalDsocialGroup, dsocialUserId)
	}
	return
}
Exemple #2
0
func (p *GoogleContactService) RetrieveGroup(client oauth2_client.OAuth2Client, ds DataStoreService, dsocialUserId string, groupId string) (*Group, os.Error) {
	resp, err := google.RetrieveGroup(client, groupId, nil)
	if resp == nil || resp.Entry == nil || err != nil {
		return nil, err
	}
	googleGroup := resp.Entry
	externalServiceId := p.ServiceId()
	userInfo, err := client.RetrieveUserInfo()
	externalUserId := userInfo.Guid()
	useErr := err
	externalGroupId := googleGroup.GroupId()
	dsocialGroupId := ""
	var origDsocialGroup *dm.Group = nil
	if len(externalGroupId) > 0 {
		dsocialGroupId, err = ds.DsocialIdForExternalGroupId(externalServiceId, externalUserId, dsocialUserId, externalGroupId)
		if err != nil {
			if useErr == nil {
				useErr = err
			}
		}
		if dsocialGroupId != "" {
			origDsocialGroup, _, err = ds.RetrieveDsocialGroupForExternalGroup(externalServiceId, externalUserId, externalGroupId, dsocialUserId)
			if err != nil && useErr == nil {
				useErr = err
			}
		} else {
			ds.StoreExternalGroup(externalServiceId, externalUserId, dsocialUserId, externalGroupId, googleGroup)
		}
	}
	var dsocialGroup *dm.Group = dm.GoogleGroupToDsocial(googleGroup, origDsocialGroup, dsocialUserId)
	group := &Group{
		ExternalServiceId: p.ServiceId(),
		ExternalUserId:    externalUserId,
		ExternalGroupId:   externalGroupId,
		DsocialUserId:     dsocialUserId,
		DsocialGroupId:    dsocialGroupId,
		Value:             dsocialGroup,
	}
	return group, useErr
}
Exemple #3
0
func (p *GoogleContactService) RetrieveGroups(client oauth2_client.OAuth2Client, ds DataStoreService, dsocialUserId string, next NextToken) ([]*Group, NextToken, os.Error) {
	var m url.Values
	if next == nil {
	} else if s, ok := next.(string); ok {
		if s != "" {
			if strings.HasPrefix(s, "https://www.google.com/") {
				uri, err := url.Parse(s)
				if err == nil {
					q, err := url.ParseQuery(uri.RawQuery)
					if err == nil {
						m = q
					}
				}
			}
			if m == nil {
				m = make(url.Values)
				m.Add("q", s)
			}
		}
	} else if maxResults, ok := next.(int); ok {
		m = make(url.Values)
		m.Add("max-results", strconv.Itoa(maxResults))
	} else if maxResults, ok := next.(int64); ok {
		m = make(url.Values)
		m.Add("max-results", strconv.Itoa64(maxResults))
	} else if gq, ok := next.(*google.GroupQuery); ok {
		m = make(url.Values)
		if gq.Alt != "" {
			m.Add("alt", gq.Alt)
		}
		if gq.Q != "" {
			m.Add("q", gq.Q)
		}
		if gq.MaxResults > 0 {
			m.Add("max-results", strconv.Itoa64(gq.MaxResults))
		}
		if gq.StartIndex > 0 {
			m.Add("start-index", strconv.Itoa64(gq.StartIndex))
		}
		if gq.UpdatedMin != "" {
			m.Add("updated-min", gq.UpdatedMin)
		}
		if gq.OrderBy != "" {
			m.Add("orderby", gq.OrderBy)
		}
		if gq.ShowDeleted {
			m.Add("showdeleted", "true")
		}
		if gq.RequireAllDeleted {
			m.Add("requirealldeleted", "true")
		}
		if gq.SortOrder != "" {
			m.Add("sortorder", gq.SortOrder)
		}
	}
	resp, err := google.RetrieveGroups(client, m)
	var theNextToken NextToken = nil
	if resp != nil && resp.Feed != nil && resp.Feed.Links != nil && len(resp.Feed.Links) > 0 {
		for _, link := range resp.Feed.Links {
			if link.Rel == "next" {
				theNextToken = link.Href
			}
		}
	}
	if resp == nil || resp.Feed == nil || resp.Feed.Entries == nil || len(resp.Feed.Entries) == 0 || err != nil {
		return make([]*Group, 0), theNextToken, err
	}
	groups := make([]*Group, len(resp.Feed.Entries))
	externalServiceId := p.ServiceId()
	userInfo, err := client.RetrieveUserInfo()
	externalUserId := userInfo.Guid()
	var useErr os.Error = nil
	for i, googleGroup := range resp.Feed.Entries {
		externalGroupId := googleGroup.GroupId()
		var origDsocialGroup *dm.Group = nil
		dsocialGroupId := ""
		if len(externalGroupId) > 0 {
			dsocialGroupId, err = ds.DsocialIdForExternalGroupId(externalServiceId, externalUserId, dsocialUserId, externalGroupId)
			if err != nil {
				if useErr == nil {
					useErr = err
				}
				continue
			}
			if dsocialGroupId != "" {
				origDsocialGroup, _, err = ds.RetrieveDsocialGroupForExternalGroup(externalServiceId, externalUserId, externalGroupId, dsocialUserId)
				if err != nil {
					if useErr == nil {
						useErr = err
					}
					continue
				}
			} else {
				ds.StoreExternalGroup(externalServiceId, externalUserId, dsocialUserId, externalGroupId, &googleGroup)
			}
		}
		var dsocialGroup *dm.Group = dm.GoogleGroupToDsocial(&googleGroup, origDsocialGroup, dsocialUserId)
		groups[i] = &Group{
			ExternalServiceId: p.ServiceId(),
			ExternalUserId:    googleGroup.GroupUserId(),
			ExternalGroupId:   googleGroup.GroupId(),
			DsocialUserId:     dsocialUserId,
			DsocialGroupId:    dsocialGroupId,
			Value:             dsocialGroup,
		}
	}
	return groups, theNextToken, useErr
}