From 0c9cab98ef93b0eabbb29e308667e6b28d45d2f7 Mon Sep 17 00:00:00 2001 From: Hunter Horsman Date: Thu, 5 Feb 2015 19:36:35 -0500 Subject: [PATCH] Update and delete contacts --- README.md | 3 ++- gopushbullet.go | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a7a27ea..b50ce91 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,10 @@ primary feature development still in progress, see below for current status: * Get Devices * Get Contacts * Create Contacts +* Update Contact +* Delete Contact ### Todo : -* Update Contact * Set User preferences * Subscriptions * Web Sockets diff --git a/gopushbullet.go b/gopushbullet.go index 4a00fa0..aa3bd16 100644 --- a/gopushbullet.go +++ b/gopushbullet.go @@ -396,6 +396,27 @@ func (c *Client) CreateContact(name, email string) error { return nil } +//UpdateContact creates a new contact with the specified name and email +func (c *Client) UpdateContact(contactID, name string) error { + u := url.Values{} + u.Add("name", name) + _, err := c.HTTPClient.PostForm(c.BaseURL+"contacts/"+contactID, u) + if err != nil { + return err + } + return nil +} + +//DeleteContact creates a new contact with the specified name and email +func (c *Client) DeleteContact(contactID string) error { + _, apiError, err := c.makeCall("DELETE", "contacts/"+contactID, nil) + if err != nil { + log.Println("Failed to delete contact: ", err, apiError.String()) + return err + } + return nil +} + func (c *Client) makeCall(method string, call string, data interface{}) (responseBody []byte, apiError *Error, err error) { // make sure API key seems ok if len(c.APIKey) == 0 {