Esempio n. 1
0
func dsocialDateTimeToGoogle(c *ContactDateTime, g *google.Event) {
	g.When.StartTime = dsocialDateTimeToGoogleString(c.Value)
	var label string
	var rel string
	switch c.Rel {
	case "":
		label = c.Label
	case REL_DATETIME_OTHER:
		rel = google.REL_EVENT_OTHER
	default:
		label = googleHandleUnknownRel(string(c.Rel))
	}
	if label == "" && rel == "" {
		rel = google.REL_SHORT_OTHER
	}
	g.Label = label
	g.Rel = rel
	return
}
Esempio n. 2
0
func DsocialContactToGoogle(c *Contact, o *google.Contact) *google.Contact {
	if c == nil {
		return nil
	}
	g := new(google.Contact)
	if o != nil {
		g.Id.Value = o.Id.Value
		g.Etag = o.Etag
	}
	// not supposed to specify title on output
	//g.Title.Value = c.DisplayName
	g.Content.Value = c.Notes
	g.Name.NamePrefix.Value, g.Name.GivenName.Value, g.Name.AdditionalName.Value, g.Name.FamilyName.Value, g.Name.NameSuffix.Value = c.Prefix, c.GivenName, c.MiddleName, c.Surname, c.Suffix
	g.Nickname.Value = c.Nickname
	g.MaidenName.Value = c.MaidenName
	g.Name.FullName.Value = c.DisplayName
	if c.Title != "" || c.Company != "" || c.Department != "" {
		g.Organizations = make([]google.Organization, 1)
		org := &g.Organizations[0]
		org.OrgTitle.Value = c.Title
		org.OrgName.Value = c.Company
		org.OrgDepartment.Value = c.Department
		org.Primary = "true"
	}
	switch c.Gender {
	case REL_GENDER_MALE:
		g.Gender.Value = google.GENDER_MALE
	case REL_GENDER_FEMALE:
		g.Gender.Value = google.GENDER_FEMALE
	}
	// skip for now
	currentWorkHistories := list.New()
	if c.WorkHistories != nil {
		for _, workhist := range c.WorkHistories {
			if workhist != nil && workhist.IsCurrent {
				currentWorkHistories.PushBack(workhist)
			}
		}
	}
	if currentWorkHistories.Len() > 0 {
		g.Organizations = make([]google.Organization, currentWorkHistories.Len())
		for i, iter := 0, currentWorkHistories.Front(); iter != nil; i, iter = i+1, iter.Next() {
			workhist := iter.Value.(*WorkHistory)
			org := &g.Organizations[i]
			org.OrgName.Value = workhist.Company
			if workhist.Positions != nil {
				for _, position := range workhist.Positions {
					if position != nil && position.IsCurrent {
						org.OrgTitle.Value = position.Title
						org.OrgDepartment.Value = position.Department
						break
					}
				}
			}
		}
	}
	g.Emails = make([]google.Email, len(c.EmailAddresses))
	for i, email := range c.EmailAddresses {
		dsocialEmailToGoogle(email, &g.Emails[i], c.PrimaryEmail)
	}
	g.PhoneNumbers = make([]google.PhoneNumber, len(c.PhoneNumbers))
	for i, ph := range c.PhoneNumbers {
		dsocialPhoneNumberToGoogle(ph, &g.PhoneNumbers[i], c.PrimaryPhoneNumber)
	}
	g.StructuredPostalAddresses = make([]google.StructuredPostalAddress, len(c.PostalAddresses))
	for i, addr := range c.PostalAddresses {
		dsocialPostalAddressToGoogle(addr, &g.StructuredPostalAddresses[i], c.PrimaryAddress)
	}
	g.Ims = make([]google.Im, len(c.Ims))
	for i, im := range c.Ims {
		dsocialImToGoogle(im, &g.Ims[i], c.PrimaryIm)
	}
	g.Birthday.When = dsocialDateToGoogleString(c.Birthday)

	events := list.New()
	if c.Anniversary != nil && !c.Anniversary.IsEmpty() {
		event := new(google.Event)
		event.Rel = google.REL_EVENT_ANNIVERSARY
		event.When.StartTime = dsocialDateToGoogleString(c.Anniversary)
		events.PushBack(event)
	}
	for _, thedate := range c.Dates {
		if thedate != nil {
			event := new(google.Event)
			dsocialDateToGoogle(thedate, event)
			events.PushBack(event)
		}
	}
	for _, thedatetime := range c.DateTimes {
		if thedatetime != nil {
			event := new(google.Event)
			dsocialDateTimeToGoogle(thedatetime, event)
			events.PushBack(event)
		}
	}
	n := events.Len()
	g.Events = make([]google.Event, n)
	for i, e := 0, events.Front(); e != nil; i, e = i+1, e.Next() {
		g.Events[i] = *(e.Value.(*google.Event))
	}
	// TODO group memberships
	g.Relationships = make([]google.Relation, len(c.Relationships))
	for i, relation := range c.Relationships {
		dsocialRelationshipToGoogle(relation, &g.Relationships[i])
	}
	g.Websites = make([]google.Website, len(c.Uris))
	for i, uri := range c.Uris {
		dsocialUriToGoogle(uri, &g.Websites[i])
	}
	return g
}