Documentation ¶
Overview ¶
Package withings is UNOFFICIAL sdk of withings API for Go client.
Index ¶
- Constants
- Variables
- func AuthorizeOffline(conf *oauth2.Config) (*oauth2.Token, error)
- func GetClient(conf *oauth2.Config, token *oauth2.Token) *http.Client
- func GetNewConf(cid, secret, redirectURL string) oauth2.Config
- func ReadSettings(path2settings string) map[string]string
- type Activities
- type ActivityType
- type CatType
- type Client
- func (c *Client) Do(req *http.Request) (*http.Response, error)
- func (c *Client) GetActivity(startdate, enddate string, lastupdate int, offset int, atype ...ActivityType) (*Activities, error)
- func (c *Client) GetMeas(cattype CatType, startdate, enddate, lastupdate time.Time, offset int, ...) (*Measurement, error)
- func (c *Client) GetSleep(startdate, enddate time.Time, stype ...SleepType) (*Sleeps, error)
- func (c *Client) GetSleepSummary(startdate, enddate string, lastupdate int, sstype ...SleepSummariesType) (*SleepSummaries, error)
- func (c *Client) GetWorkouts(startdate, enddate string, lastupdate int, offset int, wtype ...WorkoutType) (*Workouts, error)
- func (c *Client) PrintConf()
- func (c *Client) PrintTimeout()
- func (c *Client) PrintToken()
- func (c *Client) ReadToken(path2file string) (*oauth2.Token, error)
- func (c *Client) RefreshToken() (*oauth2.Token, bool, error)
- func (c *Client) SaveToken(path2file string) error
- func (c *Client) SetScope(scopes ...string)
- func (c *Client) SetTimeout(timeout time.Duration)
- type ClientOption
- type FormParam
- type MeasType
- type MeasureData
- type Measurement
- type OAuthTransport
- type SerialzedMeas
- type SleepState
- type SleepSummaries
- type SleepSummariesType
- type SleepType
- type Sleeps
- type WorkoutCategory
- type WorkoutType
- type Workouts
Constants ¶
const ( ScopeActivity string = "user.activity" ScopeMetrics string = "user.metrics" ScopeInfo string = "user.info" )
scopes
const ( PPaction string = "action" PPmeastype string = "meastype" PPcategory string = "category" PPstartdate string = "startdate" PPenddate string = "enddate" PPstartdateymd string = "startdateymd" PPenddateymd string = "enddateymd" PPlastupdate string = "lastupdate" PPoffset string = "offset" PPdataFields string = "data_fields" )
form keys
const ( MeasureA string = "getmeas" ActivityA string = "getactivity" WorkoutsA string = "getworkouts" SleepA string = "get" SleepSA string = "getsummary" )
Service action
Variables ¶
OffsetBase is used to check whether lastupdate or startdate/enddate is used in GetMeas
Functions ¶
func AuthorizeOffline ¶
AuthorizeOffline provides oauth2 authorization for withings in CLI. See example/main.go to know the detail.
func GetNewConf ¶
GetNewConf returns oauth2.Config with client id, secret, and redirectURL
func ReadSettings ¶
ReadSettings read setting file which is yaml file and returns the settings.
Types ¶
type Activities ¶
type Activities struct { Status int `json:"status"` Body struct { Activities []struct { Date string `json:"date"` Timezone string `json:"timezone"` Deviceid string `json:"deviceid"` Brand int `json:"brand"` IsTracker bool `json:"is_tracker"` Steps int `json:"steps"` Distance int `json:"distance"` Elevation int `json:"elevation"` Soft int `json:"soft"` Moderate int `json:"moderate"` Intense int `json:"intense"` Active int `json:"active"` Calories float64 `json:"calories"` Totalcalories int `json:"totalcalories"` HrAverage int `json:"hr_average"` HrMin int `json:"hr_min"` HrMax int `json:"hr_max"` HrZone0 int `json:"hr_zone_0"` HrZone1 int `json:"hr_zone_1"` HrZone2 int `json:"hr_zone_2"` HrZone3 int `json:"hr_zone_3"` } `json:"activities"` More bool `json:"more"` Offset int `json:"offset"` } `json:"body"` }
Activities is raw data from Measure Activity API. See https://developer.withings.com/oauth2/#operation/measurev2-getactivity .
type ActivityType ¶
type ActivityType string
ActivityType is activity type
const ( Steps ActivityType = "steps" // Number of steps Distance ActivityType = "distance" // Distance travelled (in meters). Elevation ActivityType = "elevation" // Number of floors cliembed. Soft ActivityType = "soft" // Duration of soft activities (in seconds). Moderate ActivityType = "moderate" // Duration of moderate activities (in seconds). Intense ActivityType = "intense" // Duration of intense activities (in seconds). Active ActivityType = "active" // Sum of intense and moderate activity durations (in seconds). Calories ActivityType = "calories" // Active calories burned (in Kcal). TotalCalories ActivityType = "totalcalories" // Total calories burned (in Kcal). HrAverage ActivityType = "hr_average" // Average heart rate. HrMin ActivityType = "hr_min" // Minimal heart rate. HrMax ActivityType = "hr_max" // Maximal heart rate. HrZone0 ActivityType = "hr_zone_0" // Duration in seconds when heart rate was in a light zone. HrZone1 ActivityType = "hr_zone_1" // Duration in seconds when heart rate was in a moderate zone. HrZone2 ActivityType = "hr_zone_2" // Duration in seconds when heart rate was in an intense zone. HrZone3 ActivityType = "hr_zone_3" // Duration in seconds when heart rate was in maximal zone. )
Activity Type
type Client ¶
type Client struct { Client *http.Client Conf *oauth2.Config Token *oauth2.Token Timeout time.Duration MeasureURL string MeasureURLv2 string SleepURLv2 string }
Client type
func New ¶
func New(cid, secret, redirectURL string, options ...ClientOption) (*Client, error)
New returns new client. cid is client id, secret and redirectURL are parameters that you got them when you setup withings API.
func (*Client) GetActivity ¶
func (c *Client) GetActivity(startdate, enddate string, lastupdate int, offset int, atype ...ActivityType) (*Activities, error)
GetActivity call withings API Measure v2 - Getactivity. (https://developer.withings.com/oauth2/#operation/measurev2-getactivity) startdate/enddate: Activity result start date, end date. lastupdate : Timestamp for requesting data that were updated or created after this date. Use this instead of startdate+endate.
If lastupdate is set to a timestamp other than Offsetbase, getMeas will use lastupdate in preference to startdate/enddate.
offset: When a first call retuns more:1 and offset:XX, set value XX in this parameter to retrieve next available rows. atype: Acitivity Type. Set the activity type you want to get data. See ActivityType in enum.go.
func (*Client) GetMeas ¶
func (c *Client) GetMeas(cattype CatType, startdate, enddate, lastupdate time.Time, offset int, isOldToNew, isSerialized bool, mtype ...MeasType) (*Measurement, error)
GetMeas call withings API Measure - GetMeas. (https://developer.withings.com/oauth2/#operation/measure-getmeas) cattype: category, 1 for real measures, 2 for user objectives startdate, enddate: Measure's start date, end date. lastupdate : Timestamp for requesting data that were updated or created after this date. Use this instead of startdate+endate.
If lastupdate is set to a timestamp other than Offsetbase, getMeas will use lastupdate in preference to startdate/enddate.
offset: When a first call retuns more:1 and offset:XX, set value XX in this parameter to retrieve next available rows. isOldToNew: If true, results must be sorted by oldest to newest. If false, results must be sorted by newest to oldest. isSerialized: if true, results must be parsed to Measurement.SerializedData mtype: Measurement Type. Set the measurement type you want to get data. See MeasType in enum.go.
func (*Client) GetSleep ¶
GetSleep cal withings API Sleep v2 - Get. (https://developer.withings.com/oauth2/#operation/sleepv2-get) startdate/enddate: Measures' start date, end date. stype: Sleep Type. Set the sleep type you want to get data. See SleepType in enum.go.
func (*Client) GetSleepSummary ¶
func (c *Client) GetSleepSummary(startdate, enddate string, lastupdate int, sstype ...SleepSummariesType) (*SleepSummaries, error)
GetSleepSummary call withings API Sleep v2 - Getsummary. (https://developer.withings.com/oauth2/#operation/sleepv2-getsummary) startdate/enddate: Measurement result start date, end date. lastupdate : Timestamp for requesting data that were updated or created after this date. Use this instead of startdate+endate.
If lastupdate is set to a timestamp other than Offsetbase, getMeas will use lastupdate in preference to startdate/enddate.
stype: Sleep Summaries Type. Set the sleep summaries data you want to get. See SleepSummariesType in enum.go.
func (*Client) GetWorkouts ¶
func (c *Client) GetWorkouts(startdate, enddate string, lastupdate int, offset int, wtype ...WorkoutType) (*Workouts, error)
GetWorkouts call withings API Measure v2 - Getworkouts. (https://developer.withings.com/api-reference#operation/measurev2-getworkouts) startdate/enddate: Workouts result start date, end date. lastupdate : Timestamp for requesting data that were updated or created after this date. Use this instead of startdate+endate.
If lastupdate is set to a timestamp other than Offsetbase, GetWorkouts will use lastupdate in preference to startdate/enddate.
offset: When a first call retuns more:1 and offset:XX, set value XX in this parameter to retrieve next available rows. wtype: Workout Type. Set the workout type you want to get data. See WorkoutType in enum.go.
func (*Client) RefreshToken ¶
RefreshToken get new token if necessary.
func (*Client) SetTimeout ¶
SetTimeout sets timeout setting for http client.
type ClientOption ¶
ClientOption type for to customize http.Client
type FormParam ¶
type FormParam struct {
// contains filtered or unexported fields
}
FormParam is for http request parameter.
type MeasType ¶
type MeasType int
MeasType is Measurement Type
const ( Weight MeasType = 1 // Weight (kg) Height MeasType = 4 // Height (meter) FatFreeMass MeasType = 5 // Fat Free Mass (kg) FatRatio MeasType = 6 // Fat Ratio (%) FatMassWeight MeasType = 8 // Fat Mass Weight (kg) DiastolicBP MeasType = 9 // Diastolic Blood Pressure (mmHg) SystolicBP MeasType = 10 // Systolic Blood Pressure (mmHg) HeartPulse MeasType = 11 // Heart Pulse (bpm) Temp MeasType = 12 // Temperature (celsius) SPO2 MeasType = 54 // SPO2 (%) BodyTemp MeasType = 71 // Body Temperature (celsius) SkinTemp MeasType = 73 // Skin temperature (celsius) MuscleMass MeasType = 76 // Muscle Mass (kg) Hydration MeasType = 77 // Hydration (kg) BoneMass MeasType = 88 // Bone Mass (kg) PWaveVel MeasType = 91 // Pulse Wave Velocity (m/s) VO2 MeasType = 123 // VO2 max is a numerical measurement of your body’s ability to consume oxygen (ml/min/kg). )
Measurement Type
type MeasureData ¶
type MeasureData struct { GrpID int64 Date time.Time Value float64 Attrib int Category int DeviceID string }
MeasureData is used for parsed Measurement.
type Measurement ¶
type Measurement struct { Status int `json:"status"` Body struct { Updatetime int `json:"updatetime"` Timezone string `json:"timezone"` Measuregrps []struct { GrpID int64 `json:"grpid"` Attrib int `json:"attrib"` Date int `json:"date"` Created int `json:"created"` Category int `json:"category"` DeviceID string `json:"deviceid"` HashDeviceID string `json:"hash_deviceid"` Measures []struct { Value int `json:"value"` Type int `json:"type"` Unit int `json:"unit"` Algo int `json:"algo"` Fm int `json:"fm"` } `json:"measures"` Comment string `json:"comment"` } `json:"measuregrps"` More int `json:"more"` Offset int `json:"offset"` } `json:"body"` SerializedData *SerialzedMeas }
Measurement is raw data from Measure API. See https://developer.withings.com/oauth2/#operation/measure-getmeas .
type OAuthTransport ¶
type OAuthTransport struct{}
OAuthTransport is making custom request and response for withings api.
type SerialzedMeas ¶
type SerialzedMeas struct { Weights []MeasureData Heights []MeasureData FatFreeMass []MeasureData FatRatios []MeasureData FatMassWeights []MeasureData DiastolicBPs []MeasureData SystolicBPs []MeasureData HeartPulses []MeasureData Temps []MeasureData SPO2s []MeasureData BodyTemps []MeasureData SkinTemps []MeasureData MuscleMasses []MeasureData Hydration []MeasureData BoneMasses []MeasureData PWaveVel []MeasureData VO2s []MeasureData UnknowVals []MeasureData }
SerialzedMeas has parsed Measurements.
func SerialMeas ¶
func SerialMeas(mym *Measurement) (*SerialzedMeas, error)
SerialMeas will parse measurement results.
type SleepState ¶
type SleepState int
SleepState is Sleep state
const ( Awake SleepState = 0 LightSleep SleepState = 1 DeepSleep SleepState = 2 REM SleepState = 3 )
Sleep state
type SleepSummaries ¶
type SleepSummaries struct { Status int `json:"status"` Body struct { Series []struct { Timezone string `json:"timezone"` Model int `json:"model"` ModelID int `json:"model_id"` Startdate int64 `json:"startdate"` Enddate int64 `json:"enddate"` Date string `json:"date"` Created int64 `json:"created"` Modified int64 `json:"modified"` Data struct { BreathingDisturbancesIntensity int `json:"breathing_disturbances_intensity"` Deepsleepduration int `json:"deepsleepduration"` Durationtosleep int `json:"durationtosleep"` Durationtowakeup int `json:"durationtowakeup"` HrAverage int `json:"hr_average"` HrMax int `json:"hr_max"` HrMin int `json:"hr_min"` Lightsleepduration int `json:"lightsleepduration"` Remsleepduration int `json:"remsleepduration"` RrAverage int `json:"rr_average"` RrMax int `json:"rr_max"` RrMin int `json:"rr_min"` SleepScore int `json:"sleep_score"` Snoring int `json:"snoring"` Snoringepisodecount int `json:"snoringepisodecount"` Wakeupcount int `json:"wakeupcount"` Wakeupduration int `json:"wakeupduration"` } `json:"data"` } `json:"series"` More bool `json:"more"` Offset int `json:"offset"` } `json:"body"` }
SleepSummaries is raw data from Sleep Summaries API. See https://developer.withings.com/oauth2/#operation/sleepv2-getsummary .
type SleepSummariesType ¶
type SleepSummariesType string
SleepSummariesType is Sleep Summaries Type.
const ( SSBdi SleepSummariesType = "breathing_disturbances_intensity" // Intensity of breathing disturbances SSDsd SleepSummariesType = "deepsleepduration" // Duration in state deep sleep (in seconds). SSD2s SleepSummariesType = "durationtosleep" // Time to sleep (in seconds). SSD2w SleepSummariesType = "durationtowakeup" // Time to wake up (in seconds). SSHrAvr SleepSummariesType = "hr_average" // Average heart rate. SSHrMax SleepSummariesType = "hr_max" // Maximal heart rate. SSHrMin SleepSummariesType = "hr_min" // Minimal heart rate. SSLsd SleepSummariesType = "lightsleepduration" // Duration in state light sleep (in seconds). SSRsd SleepSummariesType = "remsleepduration" // Duration in state REM sleep (in seconds). SSRRAvr SleepSummariesType = "rr_average" // Average respiration rate. SSRRMax SleepSummariesType = "rr_max" // Maximal respiration rate. SSRRMin SleepSummariesType = "rr_min" // Minimal respiration rate. SSSS SleepSummariesType = "sleep_score" // Sleep score SSSng SleepSummariesType = "snoring" // Total snoring time SSSngEC SleepSummariesType = "snoringepisodecount" // Numbers of snoring episodes of at least one minute SSWupC SleepSummariesType = "wakeupcount" // Number of times the user woke up. SSWupD SleepSummariesType = "wakeupduration" // Time spent awake (in seconds). )
Sleep Summaries Types.
type Sleeps ¶
type Sleeps struct { Status int `json:"status"` Body struct { Series []struct { Startdate int64 `json:"startdate"` Enddate int64 `json:"enddate"` State int `json:"state"` Hr struct { Timestamp int `json:"timestamp"` } `json:"hr"` Rr struct { Timestamp int `json:"timestamp"` } `json:"rr"` Snoring struct { Timestamp int `json:"timestamp"` } `json:"snoring"` } `json:"series"` Model int `json:"model"` ModelID int `json:"model_id"` } `json:"body"` }
Sleeps is raw data from Sleep API. See https://developer.withings.com/oauth2/#tag/sleep .
type WorkoutCategory ¶
type WorkoutCategory int
WorkoutCategory is category of workout
const ( WCWalk WorkoutCategory = 1 WCRun WorkoutCategory = 2 WCHiking WorkoutCategory = 3 WCSkating WorkoutCategory = 4 WCBMX WorkoutCategory = 5 WCBicycling WorkoutCategory = 6 WCSwimming WorkoutCategory = 7 WCSurfing WorkoutCategory = 8 WCKitesurfing WorkoutCategory = 9 WCWindsurfing WorkoutCategory = 10 WCBodyboard WorkoutCategory = 11 WCTennis WorkoutCategory = 12 WCTableTennis WorkoutCategory = 13 WCSquash WorkoutCategory = 14 WCBadminton WorkoutCategory = 15 WCLiftWeights WorkoutCategory = 16 WCCalisthenics WorkoutCategory = 17 WCElliptical WorkoutCategory = 18 WCPilates WorkoutCategory = 19 WCBasketBall WorkoutCategory = 20 WCSoccer WorkoutCategory = 21 WCFootball WorkoutCategory = 22 WCRugby WorkoutCategory = 23 WCVolleyBall WorkoutCategory = 24 WCWaterpolo WorkoutCategory = 25 WCHorseRiding WorkoutCategory = 26 WCGolf WorkoutCategory = 27 WCYoga WorkoutCategory = 28 WCDancing WorkoutCategory = 29 WCBoxing WorkoutCategory = 30 WCFencing WorkoutCategory = 31 WCWrestling WorkoutCategory = 32 WCMartialArts WorkoutCategory = 33 WCSkiing WorkoutCategory = 34 WCSnowboarding WorkoutCategory = 35 WCOther WorkoutCategory = 36 WCNoActivity WorkoutCategory = 128 WCRowing WorkoutCategory = 187 WCZumba WorkoutCategory = 188 WCBaseball WorkoutCategory = 191 WCHandball WorkoutCategory = 192 WCHockey WorkoutCategory = 193 WCIceHockey WorkoutCategory = 194 WCClimbing WorkoutCategory = 195 WCIceSkating WorkoutCategory = 196 WCMultiSport WorkoutCategory = 272 WCIndoorRunning WorkoutCategory = 307 WCIndoorCycling WorkoutCategory = 308 )
Workout Category
type WorkoutType ¶
type WorkoutType string
WorkoutType is workout type
const ( WTCalories WorkoutType = "calories" // Active calories burned (in Kcal). WTEffduration WorkoutType = "effduration" // Effective duration. WTIntensity WorkoutType = "intensity" // Intensity. WTManualDistance WorkoutType = "manual_distance" // Distance travelled manually entered by user (in meters). WTManualCalories WorkoutType = "manual_calories" // Active calories burned manually entered by user (in Kcal). WTHrAverage WorkoutType = "hr_average" // Average heart rate. WTHrMin WorkoutType = "hr_min" // Minimal heart rate. WTHrMax WorkoutType = "hr_max" // Maximal heart rate. WTHrZone0 WorkoutType = "hr_zone_0" // Duration in seconds when heart rate was in a light zone (cf. Glossary). WTHrZone1 WorkoutType = "hr_zone_1" // Duration in seconds when heart rate was in a moderate zone (cf. Glossary). WTHrZone2 WorkoutType = "hr_zone_2" // Duration in seconds when heart rate was in an intense zone (cf. Glossary). WTHrZone3 WorkoutType = "hr_zone_3" // Duration in seconds when heart rate was in maximal zone (cf. Glossary). WTPauseDuration WorkoutType = "pause_duration" // Total pause time in second filled by user WTAlgoPauseDuration WorkoutType = "algo_pause_duration" // Total pause time in seconds detected by Withings device (swim only) WTSpo2Average WorkoutType = "spo2_average" // Average percent of SpO2 percent value during a workout WTSteps WorkoutType = "steps" // Number of steps. WTDistance WorkoutType = "distance" // Distance travelled (in meters). WTElevation WorkoutType = "elevation" // Number of floors climbed. WTPoolLaps WorkoutType = "pool_laps" // Number of pool laps. WTStrokes WorkoutType = "strokes" // Number of strokes. WTPoolLength WorkoutType = "pool_length" // Length of the pool. )
Workout Type
type Workouts ¶
type Workouts struct { Status int `json:"status"` Body struct { Series []struct { ID int64 `json:"id"` Category WorkoutCategory `json:"category"` Timezone string `json:"timezone"` Model int `json:"model"` Attrib int `json:"attrib"` Startdate int64 `json:"startdate"` Enddate int64 `json:"enddate"` Date string `json:"date"` Modified int64 `json:"modified"` DeviceID string `json:"deviceid"` Data struct { AlgoPauseDuration int `json:"algo_pause_duration"` Calories float64 `json:"calories"` Distance float64 `json:"distance"` Effduration int `json:"effduration"` Elevation int `json:"elevation"` HrAverage int `json:"hr_average"` HrMax int `json:"hr_max"` HrMin int `json:"hr_min"` HrZone0 int `json:"hr_zone_0"` HrZone1 int `json:"hr_zone_1"` HrZone2 int `json:"hr_zone_2"` HrZone3 int `json:"hr_zone_3"` Intensity int `json:"intensity"` ManualCalories int `json:"manual_calories"` ManualDistance int `json:"manual_distance"` PauseDuration int `json:"pause_duration"` PoolLaps int `json:"pool_laps"` PoolLength int `json:"pool_length"` Spo2Average int `json:"spo2_average"` Steps int `json:"steps"` Strokes int `json:"strokes"` } `json:"data"` } `json:"series"` More bool `json:"more"` Offset int `json:"offset"` } `json:"body"` }
Workouts is raw data from Measure Getworkouts API. See https://developer.withings.com/api-reference#operation/measurev2-getworkouts .