diff --git a/README.md b/README.md index a8988e5..e8860bb 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,10 @@ primary feature development still in progress, see below for current status: * Checklist * File * Get Devices +* Get Contacts ### Todo : * Set User preferences -* Contacts * Subscriptions * Web Sockets * Upload Requests (upload files) diff --git a/gopushbullet.go b/gopushbullet.go index de60738..d33d4e5 100644 --- a/gopushbullet.go +++ b/gopushbullet.go @@ -88,6 +88,11 @@ type Contact struct { Active bool `json:"active"` } +//ContactList describes an array of contacts +type ContactList struct { + Contacts []Contact `json:"contacts"` +} + //Subscription describes a channel subscription. type Subscription struct { ID string `json:"iden"` @@ -363,6 +368,21 @@ func (c *Client) GetDevices() (DeviceList, error) { return d, nil } +//GetContacts obtains a list of your contacts +func (c *Client) GetContacts() (ContactList, error) { + var l ContactList + res, apiError, err := c.makeCall("GET", "contacts", nil) + if err != nil { + log.Println("Failed to get contacts: ", err, apiError.String()) + return l, err + } + err = json.Unmarshal(res, &l) + if err != nil { + return l, err + } + return l, err +} + 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 {