X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=gfit%2Fgfit.go;h=581a9fe50e394bac3be89bb767f2a31727fd7ed3;hb=1830c80233b16dea15b5d07ddc6156ac1088887d;hp=33e5a664f69855806353be662b509933c6a3e179;hpb=3313c545eece0a29c49e7e1621e491d88f2f957b;p=kraftakt.git diff --git a/gfit/gfit.go b/gfit/gfit.go index 33e5a66..581a9fe 100644 --- a/gfit/gfit.go +++ b/gfit/gfit.go @@ -22,6 +22,7 @@ const ( userID = "me" dataTypeNameCalories = "com.google.calories.expended" + dataTypeNameDistance = "com.google.distance.delta" dataTypeNameSteps = "com.google.step_count.delta" dataTypeNameHeartrate = "com.google.heart_rate.summary" ) @@ -34,6 +35,7 @@ var oauthConfig = &oauth2.Config{ Scopes: []string{ fitness.FitnessActivityWriteScope, fitness.FitnessBodyWriteScope, + fitness.FitnessLocationWriteScope, }, } @@ -101,6 +103,10 @@ func DataStreamID(dataSource *fitness.DataSource) string { } } + if dataSource.DataStreamName != "" { + fields = append(fields, dataSource.DataStreamName) + } + return strings.Join(fields, ":") } @@ -146,6 +152,28 @@ func (c *Client) DataSetPatch(ctx context.Context, dataSourceID string, points [ return nil } +func (c *Client) SetDistance(ctx context.Context, meters float64, startOfDay time.Time) error { + return c.updateCumulative(ctx, + &fitness.DataSource{ + Application: Application(ctx), + DataType: &fitness.DataType{ + Field: []*fitness.DataTypeField{ + &fitness.DataTypeField{ + Name: "distance", + Format: "floatPoint", + }, + }, + Name: dataTypeNameDistance, + }, + Name: "Distance covered", + Type: "raw", + }, + &fitness.Value{ + FpVal: meters, + }, + startOfDay) +} + func (c *Client) SetSteps(ctx context.Context, totalSteps int, startOfDay time.Time) error { return c.updateCumulative(ctx, &fitness.DataSource{ @@ -343,7 +371,7 @@ func (c *Client) heartRate(ctx context.Context, dataSource *fitness.DataSource, return results, maxEndTime, nil } -func (c *Client) SetHeartRate(ctx context.Context, totalDurations []fitbit.HeartRateZone, startOfDay time.Time) error { +func (c *Client) SetHeartRate(ctx context.Context, totalDurations []fitbit.HeartRateZone, restingHeartRate int, startOfDay time.Time) error { dataSource := &fitness.DataSource{ Application: Application(ctx), DataType: &fitness.DataType{