X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=gfit%2Fgfit.go;h=8f3fbacbc452e0a9c40d0c54a131cdce6d0dbe36;hb=95db19974a6809fc619b70146b6ec3372938412a;hp=ea41b95df86fcce6357b3624908e93084e44813e;hpb=4b89d270e3125a5184896db627520b915ffec635;p=kraftakt.git diff --git a/gfit/gfit.go b/gfit/gfit.go index ea41b95..8f3fbac 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{ @@ -212,6 +240,9 @@ func (c *Client) updateCumulative(ctx context.Context, dataSource *fitness.DataS endOfDay := startOfDay.Add(24 * time.Hour).Add(-1 * time.Nanosecond) currValue, startTime, err := c.readCumulative(ctx, dataSource, startOfDay, endOfDay) + if err != nil { + return err + } var diffValue fitness.Value if dataSource.DataType.Field[0].Format == "integer" {