+
+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/%s/apiSubscriptions/%s.json",
+ c.fitbitUserID, collection, subscriberID)
+ req, err := http.NewRequest(http.MethodDelete, url, nil)
+ if err != nil {
+ return err
+ }
+
+ res, err := c.client.Do(req.WithContext(ctx))
+ if err != nil {
+ return err
+ }
+ defer res.Body.Close()
+
+ if res.StatusCode >= 400 && res.StatusCode != http.StatusConflict {
+ data, _ := ioutil.ReadAll(res.Body)
+ log.Errorf(ctx, "deleting %q subscription failed: status %d %q", collection, res.StatusCode, data)
+ return fmt.Errorf("deleting %q subscription failed", collection)
+ }
+
+ return nil
+}
+
+func (c *Client) DeleteToken(ctx context.Context) error {
+ return c.appUser.DeleteToken(ctx, "Fitbit")
+}
+
+type Profile struct {
+ Name string
+ Timezone *time.Location
+}
+
+func (c *Client) Profile(ctx context.Context) (*Profile, error) {
+ res, err := c.client.Get("https://api.fitbit.com/1/user/-/profile.json")
+ if err != nil {
+ return nil, err
+ }
+ defer res.Body.Close()
+
+ if res.StatusCode >= 400 {
+ data, _ := ioutil.ReadAll(res.Body)
+ log.Errorf(ctx, "reading profile failed: %s", data)
+ return nil, fmt.Errorf("HTTP %d error", res.StatusCode)
+ }
+
+ var data struct {
+ User struct {
+ FullName string
+ OffsetFromUTCMillis int
+ Timezone string
+ }
+ }
+ if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
+ return nil, err
+ }
+
+ loc, err := time.LoadLocation(data.User.Timezone)
+ if err != nil {
+ loc = time.FixedZone("Fitbit preference", data.User.OffsetFromUTCMillis/1000)
+ }
+
+ return &Profile{
+ Name: data.User.FullName,
+ Timezone: loc,
+ }, nil
+}