fitbit

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultHttpClient = &http.Client{Timeout: 30 * time.Second}
)
View Source
var (
	ErrRequestUnknown = errors.New("unknown error") // TODO put into other file
)

Functions

func AuthCodeURL

func AuthCodeURL(c *AuthConfig) string

AuthCodeURL returns the URL to fitibit auth page with authorization code grant flow. expires_in parameter is default 8hours.

func GetBodyFatLogsRequest

func GetBodyFatLogsRequest(ctx context.Context, param *BodyFatLogsParam) (*http.Request, error)

func GetDevicesRequest

func GetDevicesRequest(ctx context.Context) (*http.Request, error)

func GetHeartRateIntradayTimeSeriesRequest

func GetHeartRateIntradayTimeSeriesRequest(ctx context.Context, param *HeartRateParam) (*http.Request, error)

func GetProfileRequest

func GetProfileRequest(ctx context.Context) (*http.Request, error)

func GetSleepLogsRequest

func GetSleepLogsRequest(ctx context.Context, param *SleepLogsParam) (*http.Request, error)

func GetTokenStateRequest

func GetTokenStateRequest(ctx context.Context, access_token string) (*http.Request, error)

func GetWeightLogsRequest

func GetWeightLogsRequest(ctx context.Context, param *WeightLogsParam) (*http.Request, error)

func ImplicitURL

func ImplicitURL(c *AuthConfig, expires string) string

ImplicitURL returns the URL to fitbit auth page with implicit grant flow. Expires parameter can be one of 86400(1day) 604800(1week) 2592000(30days) 31536000(1year)

Types

type ActivitiesHeart

type ActivitiesHeart struct {
	DateTime string `json:"dateTime"`
	Value    struct {
		CustomHeartRateZones []interface{} `json:"customHeartRateZones"`
		HeartRateZones       []struct {
			CaloriesOut float64 `json:"caloriesOut"`
			Max         int     `json:"max"`
			Min         int     `json:"min"`
			Minutes     int     `json:"minutes"`
			Name        string  `json:"name"`
		} `json:"heartRateZones"`
		RestingHeartRate int `json:"restingHeartRate"`
	} `json:"value"`
}

type ActivitiesHeartIntraday

type ActivitiesHeartIntraday struct {
	Dataset []struct {
		Time  string `json:"time"`
		Value int    `json:"value"`
	} `json:"dataset"`
	DatasetInterval int    `json:"datasetInterval"`
	DatasetType     string `json:"datasetType"`
}

type Alarm

type Alarm struct {
	AlarmID        int           `json:"alarmId"`
	Deleted        bool          `json:"deleted"`
	Enabled        bool          `json:"enabled"`
	Recurring      bool          `json:"recurring"`
	SnoozeCount    int           `json:"snoozeCount"`
	SnoozeLength   int           `json:"snoozeLength"`
	SyncedToDevice bool          `json:"syncedToDevice"`
	Time           string        `json:"time"`
	Vibe           string        `json:"vibe"`
	WeekDays       []interface{} `json:"weekDays"`
}

type Alarms

type Alarms struct {
	TrackerAlarms []Alarm `json:"trackerAlarms"`
}

func GetAlarams

func GetAlarams(c *Client, param *GetAlarmsParam) (*Alarms, error)

func GetAlaramsContext

func GetAlaramsContext(ctx context.Context, c *Client, param *GetAlarmsParam) (*Alarms, error)

type AuthConfig

type AuthConfig struct {
	ClientID     string
	ClientSecret string
	RedirectURL  string
}

type BodyFat

type BodyFat struct {
	Date   string  `json:"date"`
	Fat    float64 `json:"fat"`
	LogID  int64   `json:"logId"`
	Source string  `json:"source"`
	Time   string  `json:"time"`
}

type BodyFatLogs

type BodyFatLogs struct {
	Fat []BodyFat `json:"fat"`
}

func GetBodyFatLogs

func GetBodyFatLogs(c *Client, param *BodyFatLogsParam) (*BodyFatLogs, error)

func GetBodyFatLogsContext

func GetBodyFatLogsContext(ctx context.Context, c *Client, param *BodyFatLogsParam) (*BodyFatLogs, error)

type BodyFatLogsParam

type BodyFatLogsParam struct {
	Date     string `validate:"len=0|datetime=2006-01-02"`
	Period   string `validate:"len=0|oneof=1d 7d 30d 1w 1m"`
	BaseDate string `validate:"len=0|datetime=2006-01-02"`
	EndDate  string `validate:"len=0|datetime=2006-01-02"`
}

GET https://api.fitbit.com/1/user/[user-id]/body/log/fat/date/[date].json GET https://api.fitbit.com/1/user/[user-id]/body/log/fat/date/[date]/[period].json GET https://api.fitbit.com/1/user/[user-id]/body/log/fat/date/[base-date]/[end-date].json

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(access_token string) *Client

func NewClient

func NewClient(httpClient *http.Client) *Client

func (*Client) Do

func (c *Client) Do(r *http.Request) (*Response, error)

Do returns raw response without processing Body responsed. The Caller must handle Body.Close() function

func (*Client) GetAlaramsContext

func (api *Client) GetAlaramsContext(ctx context.Context, param *GetAlarmsParam) (*Alarms, *Response, error)

func (*Client) GetAlarms

func (api *Client) GetAlarms(param *GetAlarmsParam) (*Alarms, *Response, error)

func (*Client) GetBodyFatLogs

func (api *Client) GetBodyFatLogs(param *BodyFatLogsParam) (*BodyFatLogs, *Response, error)

func (*Client) GetBodyFatLogsContext

func (api *Client) GetBodyFatLogsContext(ctx context.Context, param *BodyFatLogsParam) (*BodyFatLogs, *Response, error)

func (*Client) GetDevices

func (api *Client) GetDevices() (*Devices, *Response, error)

func (*Client) GetDevicesContext

func (api *Client) GetDevicesContext(ctx context.Context) (*Devices, *Response, error)

func (*Client) GetHeartRateIntradayTimeSeries

func (api *Client) GetHeartRateIntradayTimeSeries(param *HeartRateParam) (*HeartRateData, *Response, error)

func (*Client) GetHeartRateIntradayTimeSeriesContext

func (api *Client) GetHeartRateIntradayTimeSeriesContext(ctx context.Context, param *HeartRateParam) (*HeartRateData, *Response, error)

func (*Client) GetProfile

func (api *Client) GetProfile() (*Profile, *Response, error)

func (*Client) GetProfileContext

func (api *Client) GetProfileContext(ctx context.Context) (*Profile, *Response, error)

func (*Client) GetSleepLogs

func (api *Client) GetSleepLogs(param *SleepLogsParam) (*SleepLogs, *Response, error)

func (*Client) GetSleepLogsContext

func (api *Client) GetSleepLogsContext(ctx context.Context, param *SleepLogsParam) (*SleepLogs, *Response, error)

func (*Client) GetTokenState

func (api *Client) GetTokenState(access_token string) (*TokenState, *Response, error)

func (*Client) GetTokenStateContext

func (api *Client) GetTokenStateContext(ctx context.Context, access_token string) (*TokenState, *Response, error)

func (*Client) GetWeightLogs

func (api *Client) GetWeightLogs(param *WeightLogsParam) (*WeightLogs, *Response, error)

func (*Client) GetWeightLogsContext

func (api *Client) GetWeightLogsContext(ctx context.Context, param *WeightLogsParam) (*WeightLogs, *Response, error)

func (*Client) Token

func (c *Client) Token() (Token, error)

type Device

type Device struct {
	Battery       string        `json:"battery"`
	BatteryLevel  int           `json:"batteryLevel"`
	DeviceVersion string        `json:"deviceVersion"`
	Features      []interface{} `json:"features"`
	ID            string        `json:"id"`
	LastSyncTime  string        `json:"lastSyncTime"`
	Mac           string        `json:"mac"`
	Type          string        `json:"type"`
}

generated by json-to-go

type Devices

type Devices []Device

func GetDevices

func GetDevices(c *Client) (*Devices, error)

func GetDevicesContext

func GetDevicesContext(ctx context.Context, c *Client) (*Devices, error)

type ErrorResponse

type ErrorResponse struct {
	Errors []struct {
		ErrorType string `json:"errorType"`
		Message   string `json:"message"`
	} `json:"errors"`
	Success bool `json:"success"`
}

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

type GetAlarmsParam

type GetAlarmsParam struct {
	TrackerID string
}

type HeartRateData

type HeartRateData struct {
	ActivitiesHeart         []ActivitiesHeart       `json:"activities-heart"`
	ActivitiesHeartIntraday ActivitiesHeartIntraday `json:"activities-heart-intraday"`
}

func GetHeartRateIntradayTimeSeries

func GetHeartRateIntradayTimeSeries(c *Client, param *HeartRateParam) (*HeartRateData, error)

func GetHeartRateIntradayTimeSeriesContext

func GetHeartRateIntradayTimeSeriesContext(ctx context.Context, c *Client, param *HeartRateParam) (*HeartRateData, error)

type HeartRateParam

type HeartRateParam struct {
	Date        string `validate:"len=0|datetime=2006-01-02"`
	EndDate     string `validate:"len=0|datetime=2006-01-02"`
	DetailLevel string `validate:"oneof=1sec 1min"`
	StartTime   string `validate:"len=0|datetime=15:04"`
	EndTime     string `validate:"len=0|datetime=15:04"`
}

Get Heart Rate Intraday Time Series Personal App Type is requeired

GET https://api.fitbit.com/1/user/-/activities/heart/date/[date]/[end-date]/[detail-level].json GET https://api.fitbit.com/1/user/-/activities/heart/date/[date]/[end-date]/[detail-level]/time/[start-time]/[end-time].json GET https://api.fitbit.com/1/user/-/activities/heart/date/[date]/1d/[detail-level].json` GET https://api.fitbit.com/1/user/-/activities/heart/date/[date]/1d/[detail-level]/time/[start-time]/[end-time].json

type Profile

type Profile struct {
	User User `json:"user"`
}

func GetProfile

func GetProfile(c *Client) (*Profile, error)

func GetProfileContext

func GetProfileContext(ctx context.Context, c *Client) (*Profile, error)

type RateLimit

type RateLimit struct {
	Limit     int
	Remaining int
	Reset     int
}

type Response

type Response struct {
	*http.Response
	// contains filtered or unexported fields
}

Response is a wrapper for http.Response received from fitbit api

func (*Response) Decode

func (r *Response) Decode(v interface{}) error

func (*Response) Output

func (r *Response) Output(w io.Writer) error

func (*Response) OutputWithIndent

func (r *Response) OutputWithIndent(w io.Writer) error

TODO refactor

func (*Response) RateLimit

func (r *Response) RateLimit() RateLimit

type Sleep

type Sleep struct {
	DateOfSleep string `json:"dateOfSleep"`
	Duration    int    `json:"duration"`
	Efficiency  int    `json:"efficiency"`
	EndTime     string `json:"endTime"`
	InfoCode    int    `json:"infoCode"`
	IsMainSleep bool   `json:"isMainSleep"`
	Levels      struct {
		Data []struct {
			DateTime string `json:"dateTime"`
			Level    string `json:"level"`
			Seconds  int    `json:"seconds"`
		} `json:"data"`
		ShortData []struct {
			DateTime string `json:"dateTime"`
			Level    string `json:"level"`
			Seconds  int    `json:"seconds"`
		} `json:"shortData"`
		Summary struct {
			Deep struct {
				Count               int `json:"count"`
				Minutes             int `json:"minutes"`
				ThirtyDayAvgMinutes int `json:"thirtyDayAvgMinutes"`
			} `json:"deep"`
			Light struct {
				Count               int `json:"count"`
				Minutes             int `json:"minutes"`
				ThirtyDayAvgMinutes int `json:"thirtyDayAvgMinutes"`
			} `json:"light"`
			Rem struct {
				Count               int `json:"count"`
				Minutes             int `json:"minutes"`
				ThirtyDayAvgMinutes int `json:"thirtyDayAvgMinutes"`
			} `json:"rem"`
			Wake struct {
				Count               int `json:"count"`
				Minutes             int `json:"minutes"`
				ThirtyDayAvgMinutes int `json:"thirtyDayAvgMinutes"`
			} `json:"wake"`
		} `json:"summary"`
	} `json:"levels"`
	LogID               int64  `json:"logId"`
	MinutesAfterWakeup  int    `json:"minutesAfterWakeup"`
	MinutesAsleep       int    `json:"minutesAsleep"`
	MinutesAwake        int    `json:"minutesAwake"`
	MinutesToFallAsleep int    `json:"minutesToFallAsleep"`
	StartTime           string `json:"startTime"`
	TimeInBed           int    `json:"timeInBed"`
	Type                string `json:"type"`
}

type SleepLogs

type SleepLogs struct {
	Sleep   []Sleep `json:"sleep"`
	Summary Summary `json:"summary"`
}

func GetSleepLogs

func GetSleepLogs(c *Client, param *SleepLogsParam) (*SleepLogs, error)

func GetSleepLogsContext

func GetSleepLogsContext(ctx context.Context, c *Client, param *SleepLogsParam) (*SleepLogs, error)

type SleepLogsParam

type SleepLogsParam struct {
	Date      string `validate:"len=0|datetime=2006-01-02"`
	StartDate string `validate:"len=0|datetime=2006-01-02"`
	EndDate   string `validate:"len=0|datetime=2006-01-02"`
}

GET https://api.fitbit.com/1.2/user/[user-id]/sleep/date/[date].json GET https://api.fitbit.com/1.2/user/[user-id]/sleep/date/[startDate]/[endDate].json

type Summary

type Summary struct {
	Stages struct {
		Deep  int `json:"deep"`
		Light int `json:"light"`
		Rem   int `json:"rem"`
		Wake  int `json:"wake"`
	} `json:"stages"`
	TotalMinutesAsleep int `json:"totalMinutesAsleep"`
	TotalSleepRecords  int `json:"totalSleepRecords"`
	TotalTimeInBed     int `json:"totalTimeInBed"`
}

type Token

type Token struct {
	AccessToken  string    `json:"access_token"`
	RefreshToken string    `json:"refresh_token,omitempty"`
	Expiry       time.Time `json:"expiry,omitempty"`
}

func GenerateToken

func GenerateToken(c *AuthConfig, code string) (Token, error)

GenerateToken returns the Token generated by authorization code grant flow.

func (*Token) Client

func (t *Token) Client() *http.Client

func (*Token) ClientWithID

func (t *Token) ClientWithID(id, secret string) *http.Client

type TokenState

type TokenState struct {
	Active    bool   `json:"active"`
	Scope     string `json:"scope"`
	ClientID  string `json:"client_id"`
	UserID    string `json:"user_id"`
	TokenType string `json:"token_type"`
	Exp       int64  `json:"exp"`
	Iat       int64  `json:"iat"`
}

func GetTokenState

func GetTokenState(c *Client, access_token string) (*TokenState, error)

func GetTokenStateContext

func GetTokenStateContext(ctx context.Context, c *Client, access_token string) (*TokenState, error)

type User

type User struct {
	Age                    int    `json:"age"`
	Ambassador             bool   `json:"ambassador"`
	Avatar                 string `json:"avatar"`
	Avatar150              string `json:"avatar150"`
	Avatar640              string `json:"avatar640"`
	AverageDailySteps      int    `json:"averageDailySteps"`
	ChallengesBeta         bool   `json:"challengesBeta"`
	ClockTimeDisplayFormat string `json:"clockTimeDisplayFormat"`
	Corporate              bool   `json:"corporate"`
	CorporateAdmin         bool   `json:"corporateAdmin"`
	Country                string `json:"country"`
	DateOfBirth            string `json:"dateOfBirth"`
	DisplayName            string `json:"displayName"`
	DisplayNameSetting     string `json:"displayNameSetting"`
	DistanceUnit           string `json:"distanceUnit"`
	EncodedID              string `json:"encodedId"`
	Features               struct {
		ExerciseGoal bool `json:"exerciseGoal"`
	} `json:"features"`
	FoodsLocale              string  `json:"foodsLocale"`
	FullName                 string  `json:"fullName"`
	Gender                   string  `json:"gender"`
	GlucoseUnit              string  `json:"glucoseUnit"`
	Height                   float64 `json:"height"`
	HeightUnit               string  `json:"heightUnit"`
	IsBugReportEnabled       bool    `json:"isBugReportEnabled"`
	IsChild                  bool    `json:"isChild"`
	IsCoach                  bool    `json:"isCoach"`
	LanguageLocale           string  `json:"languageLocale"`
	LegalTermsAcceptRequired bool    `json:"legalTermsAcceptRequired"`
	Locale                   string  `json:"locale"`
	MemberSince              string  `json:"memberSince"`
	MfaEnabled               bool    `json:"mfaEnabled"`
	OffsetFromUTCMillis      int     `json:"offsetFromUTCMillis"`
	SdkDeveloper             bool    `json:"sdkDeveloper"`
	SleepTracking            string  `json:"sleepTracking"`
	StartDayOfWeek           string  `json:"startDayOfWeek"`
	StrideLengthRunning      float64 `json:"strideLengthRunning"`
	StrideLengthRunningType  string  `json:"strideLengthRunningType"`
	StrideLengthWalking      float64 `json:"strideLengthWalking"`
	StrideLengthWalkingType  string  `json:"strideLengthWalkingType"`
	SwimUnit                 string  `json:"swimUnit"`
	Timezone                 string  `json:"timezone"`
	TopBadges                []struct {
		BadgeGradientEndColor   string        `json:"badgeGradientEndColor"`
		BadgeGradientStartColor string        `json:"badgeGradientStartColor"`
		BadgeType               string        `json:"badgeType"`
		Category                string        `json:"category"`
		Cheers                  []interface{} `json:"cheers"`
		DateTime                string        `json:"dateTime"`
		Description             string        `json:"description"`
		EarnedMessage           string        `json:"earnedMessage"`
		EncodedID               string        `json:"encodedId"`
		Image100Px              string        `json:"image100px"`
		Image125Px              string        `json:"image125px"`
		Image300Px              string        `json:"image300px"`
		Image50Px               string        `json:"image50px"`
		Image75Px               string        `json:"image75px"`
		MarketingDescription    string        `json:"marketingDescription"`
		MobileDescription       string        `json:"mobileDescription"`
		Name                    string        `json:"name"`
		ShareImage640Px         string        `json:"shareImage640px"`
		ShareText               string        `json:"shareText"`
		ShortDescription        string        `json:"shortDescription"`
		ShortName               string        `json:"shortName"`
		TimesAchieved           int           `json:"timesAchieved"`
		Value                   int           `json:"value"`
		Unit                    string        `json:"unit,omitempty"`
	} `json:"topBadges"`
	WaterUnit     string  `json:"waterUnit"`
	WaterUnitName string  `json:"waterUnitName"`
	Weight        float64 `json:"weight"`
	WeightUnit    string  `json:"weightUnit"`
}

generated by json-to-go

type Weight

type Weight struct {
	Bmi  float64 `json:"bmi"`
	Date string  `json:"date"`
	// Fat    float64 `json:"fat"`  deplicated ?
	LogID  int64   `json:"logId"`
	Source string  `json:"source"`
	Time   string  `json:"time"`
	Weight float64 `json:"weight"`
}

type WeightLogs

type WeightLogs struct {
	Weight []Weight `json:"weight"`
}

func GetWeightLogs

func GetWeightLogs(c *Client, param *WeightLogsParam) (*WeightLogs, error)

func GetWeightLogsContext

func GetWeightLogsContext(ctx context.Context, c *Client, param *WeightLogsParam) (*WeightLogs, error)

type WeightLogsParam

type WeightLogsParam struct {
	Date     string `validate:"len=0|datetime=2006-01-02"`
	Period   string `validate:"len=0|oneof=1d 7d 30d 1w 1m"`
	BaseDate string `validate:"len=0|datetime=2006-01-02"`
	EndDate  string `validate:"len=0|datetime=2006-01-02"`
}

GET https://api.fitbit.com/1/user/[user-id]/body/log/weight/date/[date].json GET https://api.fitbit.com/1/user/[user-id]/body/log/weight/date/[base-date]/[period].json GET https://api.fitbit.com/1/user/[user-id]/body/log/weight/date/[base-date]/[end-date].json

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL