Skip to content

Commit 7c84729

Browse files
committed
Remove appName requirement
This isn't needed as the token is registered with an app or user.
1 parent fe9b70a commit 7c84729

File tree

5 files changed

+12
-50
lines changed

5 files changed

+12
-50
lines changed

README.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ go get -u 'github.com/lildude/runalyze'
1616

1717
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).
1818

19-
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!
20-
21-
With your token and application name, you can then access the API using approach similar to this:
19+
With your token, you can then access the API using approach similar to this:
2220

2321
```go
2422
package main
@@ -36,11 +34,7 @@ import (
3634
func main() {
3735
godotenv.Load(".env")
3836
ctx := context.Background()
39-
cfg := runalyze.Configuration{
40-
AppName: "My Cool App/3.2.1",
41-
Token: os.Getenv("RUNALYZE_ACCESS_TOKEN"),
42-
}
43-
cl := runalyze.NewClient(cfg)
37+
cl := runalyze.NewClient(os.Getenv("RUNALYZE_ACCESS_TOKEN"))
4438

4539
startSleep, _ := time.Parse(time.RFC3339, "2020-11-07T23:00:00Z")
4640
sleep := runalyze.Sleep{

client.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import (
1717
var (
1818
// BaseURLV1 is Runalyze's v1 API endpoint
1919
BaseURLV1 = "https://runalyze.com/api/v1/"
20-
version = "dev"
21-
userAgent = fmt.Sprintf("go-runalyze/%s", version)
20+
userAgent = "go-runalyze"
2221
)
2322

2423
// Client holds configuration items for the Runalyze client and provides methods that interact with the Runalyze API.
@@ -29,19 +28,12 @@ type Client struct {
2928
client *http.Client
3029
}
3130

32-
// Configuration holds the client information used when initialising the client
33-
type Configuration struct {
34-
AppName string
35-
Token string
36-
}
37-
3831
// NewClient returns a new Runalyze API client.
39-
func NewClient(cfg Configuration) *Client {
32+
func NewClient(token string) *Client {
4033
cc := http.DefaultClient
4134
baseURL, _ := url.Parse(BaseURLV1)
42-
ua := fmt.Sprintf("%s (%s)", cfg.AppName, userAgent)
4335

44-
c := &Client{baseURL: baseURL, UserAgent: ua, apiToken: cfg.Token, client: cc}
36+
c := &Client{baseURL: baseURL, UserAgent: userAgent, apiToken: token, client: cc}
4537
return c
4638
}
4739

client_test.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,18 @@ import (
1616
// TestNewClient confirms that a client can be created with the default baseURL
1717
// and default User-Agent.
1818
func TestNewClient(t *testing.T) {
19-
cfg := Configuration{
20-
AppName: "Testing/0.0.1",
21-
Token: "123456",
22-
}
23-
c := NewClient(cfg)
19+
c := NewClient("123456")
2420

2521
assert.Equal(t, BaseURLV1, c.baseURL.String(), "should configure the client to use the default url")
26-
assert.Equal(t, fmt.Sprintf("Testing/0.0.1 (go-runalyze/%s)", version), c.UserAgent)
22+
assert.Equal(t, "go-runalyze", c.UserAgent)
2723
assert.Equal(t, "123456", c.apiToken, "should configure the client to use the API token")
2824
}
2925

3026
// TestNewRequest confirms that NewRequest returns an API request with the
3127
// correct URL, a correctly encoded body and the correct User-Agent and
3228
// Content-Type headers set.
3329
func TestNewRequest(t *testing.T) {
34-
cfg := Configuration{
35-
AppName: "Testing/0.0.1",
36-
Token: "123456",
37-
}
38-
c := NewClient(cfg)
30+
c := NewClient("123456")
3931

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

@@ -214,11 +206,7 @@ func setup() (client *Client, mux *http.ServeMux, serverURL string, teardown fun
214206
mux = http.NewServeMux()
215207
server := httptest.NewServer(mux)
216208

217-
cfg := Configuration{
218-
AppName: "Testing/0.0.1",
219-
Token: "123456",
220-
}
221-
c := NewClient(cfg)
209+
c := NewClient("123456")
222210
url, _ := url.Parse(server.URL + "/")
223211
c.baseURL = url
224212

doc.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ different functions of the Runalyze API. All of the API calls require an access
1010
token which should be passed when initialising the client. For example:
1111
1212
ctx := context.Background()
13-
cfg := runalyze.Configuration{
14-
AppName: "My Cool App/3.2.1",
15-
Token: "RUNALYZE_ACCESS_TOKEN",
16-
}
17-
client := runalyze.NewClient(cfg)
13+
client := runalyze.NewClient(os.Getenv("RUNALYZE_ACCESS_TOKEN"))
1814
1915
// Create a new sleep entry
2016
startSleep, _ := time.Parse(time.RFC3339, "2020-11-07T23:00:00Z")

example_test.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ import (
1717
func Example_sleep() {
1818
godotenv.Load(".env")
1919
ctx := context.Background()
20-
cfg := runalyze.Configuration{
21-
AppName: "go-runalyze Testing",
22-
Token: os.Getenv("RUNALYZE_ACCESS_TOKEN"),
23-
}
24-
cl := runalyze.NewClient(cfg)
20+
cl := runalyze.NewClient(os.Getenv("RUNALYZE_ACCESS_TOKEN"))
2521

2622
startSleep, _ := time.Parse(time.RFC3339, "2020-11-07T23:00:00Z")
2723
sleep := runalyze.Sleep{
@@ -43,11 +39,7 @@ func Example_sleep() {
4339
func Example_bloodPressure() {
4440
godotenv.Load(".env")
4541
ctx := context.Background()
46-
cfg := runalyze.Configuration{
47-
AppName: "go-runalyze Testing",
48-
Token: os.Getenv("RUNALYZE_ACCESS_TOKEN"),
49-
}
50-
cl := runalyze.NewClient(cfg)
42+
cl := runalyze.NewClient(os.Getenv("RUNALYZE_ACCESS_TOKEN"))
5143

5244
date, _ := time.Parse(time.RFC3339, "2020-11-07T23:00:00Z")
5345
bp := runalyze.BloodPressure{

0 commit comments

Comments
 (0)