From 84287341e91c41560e7f3a913a936fbc6cc5b262 Mon Sep 17 00:00:00 2001 From: Hunter Horsman Date: Thu, 5 Feb 2015 20:07:05 -0500 Subject: [PATCH] Get subscriptions list --- gopushbullet.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gopushbullet.go b/gopushbullet.go index 30ce8df..a27160d 100644 --- a/gopushbullet.go +++ b/gopushbullet.go @@ -103,6 +103,11 @@ type Subscription struct { Channel Channel `json:"channel"` } +//SubscriptionList describes a list of subscribed channels +type SubscriptionList struct { + Subscriptions []Subscription `json:"subscriptions"` +} + //Channel describes a channel on a subscription. type Channel struct { ID string `json:"iden"` @@ -427,6 +432,20 @@ func (c *Client) SubscribeChannel(channel string) error { return nil } +//ListSubscriptions returns a list of channels to which the user is subscribed +func (c *Client) ListSubscriptions() (subscriptions SubscriptionList, err error) { + responseBody, apiError, err := c.makeCall("GET", "subscriptions", nil) + if err != nil { + log.Println("Failed to add subscription: ", err, apiError.String()) + return + } + err = json.Unmarshal(responseBody, &subscriptions) + if err != nil { + return + } + return +} + 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 {