"google.golang.org/appengine/log"
)
-
func oauthConfig() *oauth2.Config {
return &oauth2.Config{
ClientID: app.Config.FitbitClientID,
if res.StatusCode >= 400 && res.StatusCode != http.StatusConflict {
data, _ := ioutil.ReadAll(res.Body)
- log.Errorf(ctx, "creating subscription failed: status %d %q", res.StatusCode, data)
- return fmt.Errorf("creating subscription failed")
+ log.Errorf(ctx, "creating %q subscription failed: status %d %q", collection, res.StatusCode, data)
+ return fmt.Errorf("creating %q subscription failed", collection)
}
return nil
}
-func (c *Client) Unsubscribe(ctx context.Context) error {
+func (c *Client) Unsubscribe(ctx context.Context, collection string) error {
subscriberID, err := c.appUser.ID(ctx)
if err != nil {
return err
}
- url := fmt.Sprintf("https://api.fitbit.com/1/user/%s/apiSubscriptions/%s.json",
- c.fitbitUserID, subscriberID)
+ url := fmt.Sprintf("https://api.fitbit.com/1/user/%s/%s/apiSubscriptions/%s.json",
+ c.fitbitUserID, collection, subscriberID)
req, err := http.NewRequest(http.MethodDelete, url, nil)
if err != nil {
return err
if res.StatusCode >= 400 && res.StatusCode != http.StatusConflict {
data, _ := ioutil.ReadAll(res.Body)
- log.Errorf(ctx, "creating subscription failed: status %d %q", res.StatusCode, data)
- return fmt.Errorf("deleting subscription failed")
+ log.Errorf(ctx, "deleting %q subscription failed: status %d %q", collection, res.StatusCode, data)
+ return fmt.Errorf("deleting %q subscription failed", collection)
}
return nil
}
var errs appengine.MultiError
- if err := c.Unsubscribe(ctx); err != nil {
- errs = append(errs, fmt.Errorf("Unsubscribe() = %v", err))
+
+ for _, collection := range []string{"activities", "sleep"} {
+ if err := c.Unsubscribe(ctx, collection); err != nil {
+ errs = append(errs, fmt.Errorf("Unsubscribe(%q) = %v", collection, err))
+ }
+ log.Infof(ctx, "Successfully unsubscribed from %q", collection)
}
if err := c.DeleteToken(ctx); err != nil {