From 7c84729809a351f83df2f1ac1f6db40cf2d84efe Mon Sep 17 00:00:00 2001 From: Colin Seymour Date: Tue, 22 Dec 2020 11:11:32 +0000 Subject: [PATCH] Remove appName requirement This isn't needed as the token is registered with an app or user. --- README.md | 10 ++-------- client.go | 14 +++----------- client_test.go | 20 ++++---------------- doc.go | 6 +----- example_test.go | 12 ++---------- 5 files changed, 12 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index e6d1454..39ed139 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,7 @@ go get -u 'github.com/lildude/runalyze' You will need an access token to query the API. You can generate tokens in your account at [Personal API](https://runalyze.com/settings/personal-api). -When using the client, you will also need to supply a name of your application. This is used in the user agent when querying the API and is used to identify applications that are accessing the API and enable Runalyze to contact the application author if there are problems. So pick a name that stands out! - -With your token and application name, you can then access the API using approach similar to this: +With your token, you can then access the API using approach similar to this: ```go package main @@ -36,11 +34,7 @@ import ( func main() { godotenv.Load(".env") ctx := context.Background() - cfg := runalyze.Configuration{ - AppName: "My Cool App/3.2.1", - Token: os.Getenv("RUNALYZE_ACCESS_TOKEN"), - } - cl := runalyze.NewClient(cfg) + cl := runalyze.NewClient(os.Getenv("RUNALYZE_ACCESS_TOKEN")) startSleep, _ := time.Parse(time.RFC3339, "2020-11-07T23:00:00Z") sleep := runalyze.Sleep{ diff --git a/client.go b/client.go index d4067d0..2964f47 100644 --- a/client.go +++ b/client.go @@ -17,8 +17,7 @@ import ( var ( // BaseURLV1 is Runalyze's v1 API endpoint BaseURLV1 = "https://runalyze.com/api/v1/" - version = "dev" - userAgent = fmt.Sprintf("go-runalyze/%s", version) + userAgent = "go-runalyze" ) // Client holds configuration items for the Runalyze client and provides methods that interact with the Runalyze API. @@ -29,19 +28,12 @@ type Client struct { client *http.Client } -// Configuration holds the client information used when initialising the client -type Configuration struct { - AppName string - Token string -} - // NewClient returns a new Runalyze API client. -func NewClient(cfg Configuration) *Client { +func NewClient(token string) *Client { cc := http.DefaultClient baseURL, _ := url.Parse(BaseURLV1) - ua := fmt.Sprintf("%s (%s)", cfg.AppName, userAgent) - c := &Client{baseURL: baseURL, UserAgent: ua, apiToken: cfg.Token, client: cc} + c := &Client{baseURL: baseURL, UserAgent: userAgent, apiToken: token, client: cc} return c } diff --git a/client_test.go b/client_test.go index 8dcf1d5..f6f937f 100644 --- a/client_test.go +++ b/client_test.go @@ -16,14 +16,10 @@ import ( // TestNewClient confirms that a client can be created with the default baseURL // and default User-Agent. func TestNewClient(t *testing.T) { - cfg := Configuration{ - AppName: "Testing/0.0.1", - Token: "123456", - } - c := NewClient(cfg) + c := NewClient("123456") 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-runalyze/%s)", version), c.UserAgent) + assert.Equal(t, "go-runalyze", c.UserAgent) assert.Equal(t, "123456", c.apiToken, "should configure the client to use the API token") } @@ -31,11 +27,7 @@ func TestNewClient(t *testing.T) { // correct URL, a correctly encoded body and the correct User-Agent and // Content-Type headers set. func TestNewRequest(t *testing.T) { - cfg := Configuration{ - AppName: "Testing/0.0.1", - Token: "123456", - } - c := NewClient(cfg) + c := NewClient("123456") t.Run("valid request", func(tc *testing.T) { @@ -214,11 +206,7 @@ func setup() (client *Client, mux *http.ServeMux, serverURL string, teardown fun mux = http.NewServeMux() server := httptest.NewServer(mux) - cfg := Configuration{ - AppName: "Testing/0.0.1", - Token: "123456", - } - c := NewClient(cfg) + c := NewClient("123456") url, _ := url.Parse(server.URL + "/") c.baseURL = url diff --git a/doc.go b/doc.go index eb85405..4c05e73 100644 --- a/doc.go +++ b/doc.go @@ -10,11 +10,7 @@ different functions of the Runalyze API. All of the API calls require an access token which should be passed when initialising the client. For example: ctx := context.Background() - cfg := runalyze.Configuration{ - AppName: "My Cool App/3.2.1", - Token: "RUNALYZE_ACCESS_TOKEN", - } - client := runalyze.NewClient(cfg) + client := runalyze.NewClient(os.Getenv("RUNALYZE_ACCESS_TOKEN")) // Create a new sleep entry startSleep, _ := time.Parse(time.RFC3339, "2020-11-07T23:00:00Z") diff --git a/example_test.go b/example_test.go index a8043b6..780a1e4 100644 --- a/example_test.go +++ b/example_test.go @@ -17,11 +17,7 @@ import ( func Example_sleep() { godotenv.Load(".env") ctx := context.Background() - cfg := runalyze.Configuration{ - AppName: "go-runalyze Testing", - Token: os.Getenv("RUNALYZE_ACCESS_TOKEN"), - } - cl := runalyze.NewClient(cfg) + cl := runalyze.NewClient(os.Getenv("RUNALYZE_ACCESS_TOKEN")) startSleep, _ := time.Parse(time.RFC3339, "2020-11-07T23:00:00Z") sleep := runalyze.Sleep{ @@ -43,11 +39,7 @@ func Example_sleep() { func Example_bloodPressure() { godotenv.Load(".env") ctx := context.Background() - cfg := runalyze.Configuration{ - AppName: "go-runalyze Testing", - Token: os.Getenv("RUNALYZE_ACCESS_TOKEN"), - } - cl := runalyze.NewClient(cfg) + cl := runalyze.NewClient(os.Getenv("RUNALYZE_ACCESS_TOKEN")) date, _ := time.Parse(time.RFC3339, "2020-11-07T23:00:00Z") bp := runalyze.BloodPressure{