Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Switch to private
Browse files Browse the repository at this point in the history
  • Loading branch information
lildude committed Apr 10, 2022
1 parent 340e11a commit fbced69
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (c *Client) GetActivities(ctx context.Context, start string, end string) (*
}

var activities *Activities
resp, err := c.Do(ctx, req, &activities)
resp, err := c.do(ctx, req, &activities)
if err != nil {
return activities, resp, err
}
Expand Down
2 changes: 1 addition & 1 deletion bedtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (c *Client) GetBedtime(ctx context.Context, start string, end string) (*Ide
}

var bedtimes *IdealBedtimes
resp, err := c.Do(ctx, req, &bedtimes)
resp, err := c.do(ctx, req, &bedtimes)
if err != nil {
return bedtimes, resp, err
}
Expand Down
40 changes: 20 additions & 20 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,6 @@ type Client struct {
client *http.Client
}

// TimeSeriesData is time series data used by various other methods.
type TimeSeriesData struct {
Interval float32 `json:"interval"`
Items []float32 `json:"items"`
Timestamp time.Time `json:"timestamp"`
}

func (e *ErrorDetail) Error() string {
return e.Detail
}

// ErrorDetail holds the details of an error message
type ErrorDetail struct {
Status int `json:"status,omitempty"`
Title string `json:"title,omitempty"`
Detail string `json:"detail"`
}

// NewClient returns a new Oura API client. If a nil httpClient is
// provided, http.DefaultClient will be used. To use API methods which require
// authentication, provide an http.Client that will perform the authentication
Expand Down Expand Up @@ -101,7 +83,7 @@ func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Requ
// Do sends a request and returns the response. An error is returned if the request cannot
// be sent or if the API returns an error. If a response is received, the body response body
// is decoded and stored in the value pointed to by v.
func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*http.Response, error) {
func (c *Client) do(ctx context.Context, req *http.Request, v interface{}) (*http.Response, error) {
req = req.WithContext(ctx)
resp, err := c.client.Do(req)
if err != nil {
Expand All @@ -116,7 +98,7 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*htt

// Anything other than a HTTP 2xx response code is treated as an error.
if resp.StatusCode >= 300 {
e := ErrorDetail{}
e := errorDetail{}
err := json.Unmarshal(data, &e)
if err != nil {
return resp, err
Expand All @@ -140,6 +122,24 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*htt
return resp, err
}

// timeSeriesData is time series data used by various other methods.
type timeSeriesData struct {
Interval float32 `json:"interval"`
Items []float32 `json:"items"`
Timestamp time.Time `json:"timestamp"`
}

func (e *errorDetail) Error() string {
return e.Detail
}

// errorDetail holds the details of an error message
type errorDetail struct {
Status int `json:"status,omitempty"`
Title string `json:"title,omitempty"`
Detail string `json:"detail"`
}

// parametiseDate takes the arguments and URL encodes them into a string
// where the dates are ISO 8601 date strings without times.
func parametiseDate(path, start, end, next string) string {
Expand Down
14 changes: 7 additions & 7 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestDo(t *testing.T) {
got := new(foo)

req, _ := client.NewRequest("GET", ".", nil)
client.Do(context.Background(), req, got) //nolint:errcheck
client.do(context.Background(), req, got) //nolint:errcheck

assert.ObjectsAreEqual(want, got)
})
Expand All @@ -99,7 +99,7 @@ func TestDo(t *testing.T) {
})

req, _ := client.NewRequest("GET", ".", nil)
resp, err := client.Do(context.Background(), req, nil)
resp, err := client.do(context.Background(), req, nil)

assert.Equal(tc, http.StatusInternalServerError, resp.StatusCode)
assert.Error(tc, err, "should return an error")
Expand All @@ -118,7 +118,7 @@ func TestDo(t *testing.T) {

req, _ := client.NewRequest("GET", ".", nil)
got := new(foo)
resp, err := client.Do(context.Background(), req, got)
resp, err := client.do(context.Background(), req, got)

assert.Equal(tc, http.StatusOK, resp.StatusCode)
assert.Nil(tc, err, "should not return an error")
Expand Down Expand Up @@ -152,7 +152,7 @@ func TestDo(t *testing.T) {

req, _ := client.NewRequest("GET", ".", nil)
got := new(foo)
resp, err := client.Do(context.Background(), req, got)
resp, err := client.do(context.Background(), req, got)

assert.Equal(tc, http.StatusOK, resp.StatusCode)
assert.Error(tc, err, "should return an error")
Expand All @@ -170,7 +170,7 @@ func TestDo(t *testing.T) {
req, _ := client.NewRequest("GET", ".", nil)
ctx, cancel := context.WithCancel(context.Background())
cancel()
resp, err := client.Do(ctx, req, nil)
resp, err := client.do(ctx, req, nil)

assert.Error(tc, err, "should return an error")
assert.Nil(tc, resp, "should not return a response")
Expand All @@ -186,7 +186,7 @@ func TestDo(t *testing.T) {
})

req, _ := client.NewRequest("GET", ".", nil)
resp, err := client.Do(context.Background(), req, nil)
resp, err := client.do(context.Background(), req, nil)

assert.Equal(tc, http.StatusForbidden, resp.StatusCode)
assert.Error(tc, err, "should return an error")
Expand All @@ -206,7 +206,7 @@ func TestDo(t *testing.T) {
})

req, _ := client.NewRequest("GET", ".", nil)
resp, err := client.Do(context.Background(), req, nil)
resp, err := client.do(context.Background(), req, nil)

assert.Equal(tc, http.StatusBadRequest, resp.StatusCode)
assert.Error(tc, err, "should return an error")
Expand Down
4 changes: 2 additions & 2 deletions daily_activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type DailyActivity struct {
LowActivityTime int `json:"low_activity_time"`
MediumActivityMetMinutes int `json:"medium_activity_met_minutes"`
MediumActivityTime int `json:"medium_activity_time"`
Met TimeSeriesData `json:"met"`
Met timeSeriesData `json:"met"`
MetersToTarget int `json:"meters_to_target"`
NonWearTime int `json:"non_wear_time"`
RestingTime int `json:"resting_time"`
Expand Down Expand Up @@ -63,7 +63,7 @@ func (c *Client) DailyActivities(ctx context.Context, start_date, end_date, next
}

var data *DailyActivities
resp, err := c.Do(ctx, req, &data)
resp, err := c.do(ctx, req, &data)
if err != nil {
return data, resp, err
}
Expand Down
2 changes: 1 addition & 1 deletion heartrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (c *Client) Heartrates(ctx context.Context, start_datetime, end_datetime, n
}

var data *Heartrates
resp, err := c.Do(ctx, req, &data)
resp, err := c.do(ctx, req, &data)
if err != nil {
return data, resp, err
}
Expand Down
2 changes: 1 addition & 1 deletion personal_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (c *Client) PersonalInfo(ctx context.Context) (*PersonalInfo, *http.Respons
}

var data *PersonalInfo
resp, err := c.Do(ctx, req, &data)
resp, err := c.do(ctx, req, &data)
if err != nil {
return data, resp, err
}
Expand Down
2 changes: 1 addition & 1 deletion readiness.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (c *Client) GetReadiness(ctx context.Context, start string, end string) (*R
}

var readinessSummaries *ReadinessSummaries
resp, err := c.Do(ctx, req, &readinessSummaries)
resp, err := c.do(ctx, req, &readinessSummaries)
if err != nil {
return readinessSummaries, resp, err
}
Expand Down
8 changes: 4 additions & 4 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ type Session struct {
StartDatetime time.Time `json:"start_date"`
EndDatetime time.Time `json:"end_date"`
Type string `json:"type"`
Heartrate TimeSeriesData `json:"heart_rate"`
HeartrateVariability TimeSeriesData `json:"heart_rate_variability"`
Heartrate timeSeriesData `json:"heart_rate"`
HeartrateVariability timeSeriesData `json:"heart_rate_variability"`
Mood string `json:"mood"`
MotionCount TimeSeriesData `json:"motion_count"`
MotionCount timeSeriesData `json:"motion_count"`
}

// Sessions represents the data returned from the Oura API for a list of sessions.
Expand All @@ -36,7 +36,7 @@ func (c *Client) Sessions(ctx context.Context, start_date, end_date, next_token
}

var data *Sessions
resp, err := c.Do(ctx, req, &data)
resp, err := c.do(ctx, req, &data)
if err != nil {
return data, resp, err
}
Expand Down
2 changes: 1 addition & 1 deletion sleep.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (c *Client) GetSleep(ctx context.Context, start string, end string) (*Sleep
}

var sleepSummaries *Sleeps
resp, err := c.Do(ctx, req, &sleepSummaries)
resp, err := c.do(ctx, req, &sleepSummaries)
if err != nil {
return sleepSummaries, resp, err
}
Expand Down
2 changes: 1 addition & 1 deletion tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (c *Client) Tags(ctx context.Context, start_date, end_date, next_token stri
}

var data *Tags
resp, err := c.Do(ctx, req, &data)
resp, err := c.do(ctx, req, &data)
if err != nil {
return data, resp, err
}
Expand Down
2 changes: 1 addition & 1 deletion userinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (c *Client) GetUserInfo(ctx context.Context) (*UserInfo, *http.Response, er
}

var userInfo *UserInfo
resp, err := c.Do(ctx, req, &userInfo)
resp, err := c.do(ctx, req, &userInfo)
if err != nil {
return userInfo, resp, err
}
Expand Down
2 changes: 1 addition & 1 deletion workout.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (c *Client) Workouts(ctx context.Context, start_date, end_date, next_token
}

var data *Workouts
resp, err := c.Do(ctx, req, &data)
resp, err := c.do(ctx, req, &data)
if err != nil {
return data, resp, err
}
Expand Down

0 comments on commit fbced69

Please sign in to comment.