Esempio n. 1
0
func DeleteContact(client oauth2_client.OAuth2Client, userId, contactId string) (err error) {
	if userId == "" {
		userId = "me"
	}
	var useUserId string
	if len(userId) <= 0 {
		useUserId = YAHOO_DEFAULT_USER_ID
	} else {
		useUserId = url.QueryEscape(userId)
	}
	uri := YAHOO_SOCIAL_API_ENDPOINT
	scope := "user"
	resourceName := "contact"
	resourceId := contactId
	for _, s := range []string{scope, useUserId, resourceName, resourceId} {
		if len(s) > 0 {
			if uri[len(uri)-1] != '/' {
				uri += "/"
			}
			uri += s
		}
	}
	headers := make(http.Header)
	headers.Set("Accept", "application/json")
	resp, _, err := oauth2_client.AuthorizedDeleteRequest(client, headers, uri, nil)
	if err != nil {
		return err
	}
	if resp != nil {
		if resp.StatusCode >= 400 {
			e := new(ErrorResponse)
			b, _ := ioutil.ReadAll(resp.Body)
			json.Unmarshal(b, e)
			if len(e.ErrorField.Description) > 0 {
				err = e
			} else {
				err = errors.New(string(b))
			}
		}
	}
	return err
}
Esempio n. 2
0
func DeleteGroup(client oauth2_client.OAuth2Client, userId, projection string, original *ContactGroup) (err error) {
	var useUserId string
	if len(userId) <= 0 {
		useUserId = GOOGLE_DEFAULT_USER_ID
	} else {
		useUserId = url.QueryEscape(userId)
	}
	if len(projection) <= 0 {
		projection = GOOGLE_DEFAULT_PROJECTION
	}
	headers := make(http.Header)
	headers.Set("GData-Version", "3.0")
	headers.Set("If-Match", original.Etag)
	m := make(url.Values)
	if len(m.Get(CONTACTS_ALT_PARAM)) <= 0 {
		m.Set(CONTACTS_ALT_PARAM, "json")
	}
	uri := GOOGLE_GROUPS_API_ENDPOINT
	for _, s := range []string{useUserId, projection, original.GroupId()} {
		if len(s) > 0 {
			if uri[len(uri)-1] != '/' {
				uri += "/"
			}
			uri += s
		}
	}
	resp, _, err := oauth2_client.AuthorizedDeleteRequest(client, headers, uri, nil)
	if err != nil {
		return
	}
	if resp != nil {
		if resp.StatusCode >= 400 {
			b, _ := ioutil.ReadAll(resp.Body)
			err = errors.New(string(b))
		}
	}
	return
}