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

Commit

Permalink
Remove appName requirement
Browse files Browse the repository at this point in the history
This isn't needed as the OAuth token is registered with an app name.
  • Loading branch information
lildude committed Dec 22, 2020
1 parent 39fc641 commit ecdd8f2
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 15 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ Depending on your requirements, you will need an access token to query the API.

See the section on Authentication in the [Oura Cloud API Docs](https://cloud.ouraring.com/docs) for more information the authentication methods.

You will need to provide an application name as a string when initialising the client. This is used in the user agent when querying the API and is used to identify applications that are accessing the API and enable Oura to contact the application author if there are problems. So pick a name that stands out!

The simplest approach for accessing your own data is to use a personal access token like this:

```go
Expand All @@ -41,7 +39,7 @@ func main() {
ctx := context.Background()
tc := oauth2.NewClient(ctx, ts)

cl := oura.NewClient(tc, "My Cool App/3.2.1")
cl := oura.NewClient(tc)

userInfo, _, _err_ := cl.UserInfo(ctx)
if err != nil {
Expand Down
8 changes: 3 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import (
var (
// BaseURLV1 is Oura's v1 API endpoint
BaseURLV1 = "https://api.ouraring.com/v1/"
version = "dev"
userAgent = fmt.Sprintf("go-oura/%s", version)
userAgent = "go-oura"
)

// Client holds configuration items for the Oura client and provides methods that interact with the Oura API.
Expand All @@ -34,14 +33,13 @@ type Client struct {
// authentication, provide an http.Client that will perform the authentication
// for you (such as that provided by the golang.org/x/oauth2 library).
// Inspiration: https://github.com/google/go-github/blob/master/github/github.go
func NewClient(cc *http.Client, appName string) *Client {
func NewClient(cc *http.Client) *Client {
if cc == nil {
cc = http.DefaultClient
}
baseURL, _ := url.Parse(BaseURLV1)
ua := fmt.Sprintf("%s (%s)", appName, userAgent)

c := &Client{baseURL: baseURL, UserAgent: ua, client: cc}
c := &Client{baseURL: baseURL, UserAgent: userAgent, client: cc}
return c
}

Expand Down
8 changes: 4 additions & 4 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ import (
// TestNewClient confirms that a client can be created with the default baseURL
// and default User-Agent.
func TestNewClient(t *testing.T) {
c := NewClient(nil, "Testing/0.0.1")
c := NewClient(nil)

assert.Equal(t, BaseURLV1, c.baseURL.String(), "should configure the client to use the default url")
assert.Equal(t, fmt.Sprintf("Testing/0.0.1 (go-oura/%s)", version), c.UserAgent, "should configure the client to use the default user-agent")
assert.Equal(t, "go-oura", c.UserAgent, "should configure the client to use the default user-agent")
}

// TestNewRequest confirms that NewRequest returns an API request with the
// correct URL, a correctly encoded body and the correct User-Agent and
// Content-Type headers set.
func TestNewRequest(t *testing.T) {
c := NewClient(nil, "Testing/0.0.1")
c := NewClient(nil)

t.Run("valid request", func(tc *testing.T) {

Expand Down Expand Up @@ -210,7 +210,7 @@ func setup() (client *Client, mux *http.ServeMux, serverURL string, teardown fun
mux = http.NewServeMux()
server := httptest.NewServer(mux)

c := NewClient(nil, "Testing/0.0.1")
c := NewClient(nil)
url, _ := url.Parse(server.URL + "/")
c.baseURL = url

Expand Down
4 changes: 2 additions & 2 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Usage:
Construct a new Oura client, then call various methods on the API to access
different functions of the Oura API. For example:
client := oura.NewClient(nil, "My Cool App/3.2.1")
client := oura.NewClient(nil)
// retrieve the user information for the current user
user, _, err := client.UserInfo(ctx, nil)
Expand All @@ -21,7 +21,7 @@ All of the API calls will require you to pass in an access token:
ctx := context.Background()
tc := oauth2.NewClient(ctx, ts)
client := oura.NewClient(tc, My Cool App/3.2.1)
client := oura.NewClient(tc)
The Oura API documentation is available at https://cloud.ouraring.com/docs.
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func Example() {
ctx := context.Background()
tc := oauth2.NewClient(ctx, ts)

cl := oura.NewClient(tc, "go-oura Testing")
cl := oura.NewClient(tc)

userInfo, _, _ := cl.GetUserInfo(ctx)
fmt.Println(userInfo.Age, userInfo.Gender, userInfo.Weight, userInfo.Email)
Expand Down

0 comments on commit ecdd8f2

Please sign in to comment.