+ log.Debugf(ctx, "GET %s -> %s", url, data)
+
+ if res.StatusCode >= 400 {
+ return nil, fmt.Errorf("Get(%q) = %d", url, res.StatusCode)
+ }
+
+ var parsed struct {
+ Subscriptions []Subscription `json:"apiSubscriptions"`
+ }
+ if err := json.Unmarshal(data, &parsed); err != nil {
+ return nil, err
+ }
+
+ var errs appengine.MultiError
+ var ret []Subscription
+ for _, sub := range parsed.Subscriptions {
+ if sub.CollectionType != collection {
+ errs = append(errs, fmt.Errorf("unexpected collection type: got %q, want %q", sub.CollectionType, collection))
+ continue
+ }
+ if sub.SubscriptionID == "" {
+ errs = append(errs, fmt.Errorf("missing subscription ID: %+v", sub))
+ continue
+ }
+ if sub.OwnerID == "" {
+ sub.OwnerID = c.fitbitUserID
+ }
+ ret = append(ret, sub)
+ }
+
+ if len(ret) == 0 && len(errs) != 0 {
+ return nil, errs
+ }