コード例 #1
0
ファイル: yahoo.go プロジェクト: pomack/dsocial.go
func (p *YahooContactService) ConvertToDsocialGroup(externalGroup interface{}, originalDsocialGroup *dm.Group, dsocialUserId string) (dsocialGroup *dm.Group) {
	if externalGroup == nil {
		return
	}
	if extGroup, ok := externalGroup.(*yahoo.Category); ok && extGroup != nil {
		dsocialGroup = dm.YahooCategoryToDsocial(extGroup, originalDsocialGroup, dsocialUserId)
	}
	return
}
コード例 #2
0
ファイル: yahoo.go プロジェクト: pomack/dsocial.go
func (p *YahooContactService) RetrieveGroups(client oauth2_client.OAuth2Client, ds DataStoreService, dsocialUserId string, next NextToken) ([]*Group, 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.RetrieveCategories(client, m)
	if resp == nil || resp.Categories.Categories == nil || len(resp.Categories.Categories) == 0 || err != nil {
		return make([]*Group, 0), nil, err
	}
	groups := make([]*Group, len(resp.Categories.Categories))
	externalServiceId := p.ServiceId()
	userInfo, err := client.RetrieveUserInfo()
	externalUserId := userInfo.Guid()
	var useErr error = nil
	for i, yahooGroup := range resp.Categories.Categories {
		var externalGroupId string
		if yahooGroup.Id > 0 {
			externalGroupId = strconv.FormatInt(yahooGroup.Id, 10)
		}
		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, &yahooGroup)
			}
		}
		var dsocialGroup *dm.Group = dm.YahooCategoryToDsocial(&yahooGroup, origDsocialGroup, dsocialUserId)
		groups[i] = &Group{
			ExternalServiceId: p.ServiceId(),
			ExternalUserId:    externalUserId,
			ExternalGroupId:   externalGroupId,
			DsocialUserId:     dsocialUserId,
			DsocialGroupId:    dsocialGroupId,
			Value:             dsocialGroup,
		}
	}
	return groups, nil, useErr
}
コード例 #3
0
ファイル: yahoo.go プロジェクト: pomack/dsocial.go
func (p *YahooContactService) RetrieveGroup(client oauth2_client.OAuth2Client, ds DataStoreService, dsocialUserId string, groupId string) (*Group, error) {
	resp, err := yahoo.RetrieveCategory(client, groupId, nil)
	if resp == nil || err != nil {
		return nil, err
	}
	yahooGroup := &resp.Category
	externalServiceId := p.ServiceId()
	userInfo, err := client.RetrieveUserInfo()
	externalUserId := userInfo.Guid()
	useErr := err
	var externalGroupId string
	if yahooGroup.Id > 0 {
		externalGroupId = strconv.FormatInt(yahooGroup.Id, 10)
	}
	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, yahooGroup)
		}
	}
	var dsocialGroup *dm.Group = dm.YahooCategoryToDsocial(yahooGroup, origDsocialGroup, dsocialUserId)
	group := &Group{
		ExternalServiceId: p.ServiceId(),
		ExternalUserId:    externalUserId,
		ExternalGroupId:   externalGroupId,
		DsocialUserId:     dsocialUserId,
		DsocialGroupId:    dsocialGroupId,
		Value:             dsocialGroup,
	}
	return group, useErr
}