From 622eecc955d8515489a7a81ed1316971832c6ce2 Mon Sep 17 00:00:00 2001 From: Joshua Raphael Date: Fri, 22 Nov 2024 10:05:01 -0700 Subject: [PATCH] add GetConsoleIDs endpoint --- README.md | 8 +- .../system/getconsoleids/getconsoleids.go | 26 ++++ game.go | 38 +++-- game_test.go | 8 +- http/request.go | 70 ++++----- http/request_test.go | 22 +-- leaderboards.go | 12 +- models/game.go | 4 +- models/system.go | 17 +++ system.go | 41 +++++ system_test.go | 142 ++++++++++++++++++ user.go | 64 ++++---- user_test.go | 10 -- 13 files changed, 344 insertions(+), 118 deletions(-) create mode 100644 examples/system/getconsoleids/getconsoleids.go create mode 100644 models/system.go create mode 100644 system.go create mode 100644 system_test.go diff --git a/README.md b/README.md index 18d4f66..647ecc1 100644 --- a/README.md +++ b/README.md @@ -81,4 +81,10 @@ For convenience, the API docs and examples can be found in the tables below |Function|Description|Links| |-|-|-| |`GetGameLeaderboards()`|Gets a given games's list of leaderboards.|[docs](https://api-docs.retroachievements.org/v1/get-game-leaderboards.html) \| [example](examples/leaderboards/getgameleaderboards/getgameleaderboards.go)| -|`GetLeaderboardEntries()`|Gets a given leadboard's entires|[docs](https://api-docs.retroachievements.org/v1/get-leaderboard-entries.html) \| [example](examples/leaderboards/getleaderboardentries/getleaderboardentries.go)| \ No newline at end of file +|`GetLeaderboardEntries()`|Gets a given leadboard's entries|[docs](https://api-docs.retroachievements.org/v1/get-leaderboard-entries.html) \| [example](examples/leaderboards/getleaderboardentries/getleaderboardentries.go)| + +

System

+ +|Function|Description|Links| +|-|-|-| +|`GetConsoleIDs()`|Gets the complete list of all system ID and name pairs on the site.|[docs](https://api-docs.retroachievements.org/v1/get-console-ids.html) \| [example](examples/system/getconsoleids/getconsoleids.go)| \ No newline at end of file diff --git a/examples/system/getconsoleids/getconsoleids.go b/examples/system/getconsoleids/getconsoleids.go new file mode 100644 index 0000000..64de4fc --- /dev/null +++ b/examples/system/getconsoleids/getconsoleids.go @@ -0,0 +1,26 @@ +// Package getconsoleids provides an example for getting the complete list of all system ID and name pairs on the site. +package main + +import ( + "fmt" + "os" + + "github.com/joshraphael/go-retroachievements" + "github.com/joshraphael/go-retroachievements/models" +) + +/* +Test script, add RA_API_KEY to your env and use `go run getconsoleids.go` +*/ +func main() { + secret := os.Getenv("RA_API_KEY") + + client := retroachievements.NewClient(secret) + + resp, err := client.GetConsoleIDs(models.GetConsoleIDsParameters{}) + if err != nil { + panic(err) + } + + fmt.Printf("%+v\n", resp) +} diff --git a/game.go b/game.go index 6b03b32..87c943c 100644 --- a/game.go +++ b/game.go @@ -14,7 +14,7 @@ func (c *Client) GetGame(params models.GetGameParameters) (*models.GetGame, erro raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetGame.php"), raHttp.APIToken(c.Secret), - raHttp.IDs([]int{params.GameID}), + raHttp.I([]int{params.GameID}), ) if err != nil { return nil, fmt.Errorf("calling endpoint: %w", err) @@ -32,10 +32,14 @@ func (c *Client) GetGameExtended(params models.GetGameExtentedParameters) (*mode raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetGameExtended.php"), raHttp.APIToken(c.Secret), - raHttp.IDs([]int{params.GameID}), + raHttp.I([]int{params.GameID}), } - if params.Unofficial { - details = append(details, raHttp.From(int64(5))) + if params.Unofficial != nil { + f := 3 + if *params.Unofficial { + f = 5 + } + details = append(details, raHttp.F(f)) } r, err := c.do(details...) if err != nil { @@ -54,7 +58,7 @@ func (c *Client) GetGameHashes(params models.GetGameHashesParameters) (*models.G raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetGameHashes.php"), raHttp.APIToken(c.Secret), - raHttp.IDs([]int{params.GameID}), + raHttp.I([]int{params.GameID}), ) if err != nil { return nil, fmt.Errorf("calling endpoint: %w", err) @@ -72,7 +76,7 @@ func (c *Client) GetAchievementCount(params models.GetAchievementCountParameters raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetAchievementCount.php"), raHttp.APIToken(c.Secret), - raHttp.IDs([]int{params.GameID}), + raHttp.I([]int{params.GameID}), ) if err != nil { return nil, fmt.Errorf("calling endpoint: %w", err) @@ -90,17 +94,21 @@ func (c *Client) GetAchievementDistribution(params models.GetAchievementDistribu raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetAchievementDistribution.php"), raHttp.APIToken(c.Secret), - raHttp.IDs([]int{params.GameID}), + raHttp.I([]int{params.GameID}), } if params.Unofficial != nil { + f := 3 if *params.Unofficial { - details = append(details, raHttp.From(int64(5))) - } else { - details = append(details, raHttp.From(int64(3))) + f = 5 } + details = append(details, raHttp.F(f)) } if params.Hardcore != nil { - details = append(details, raHttp.Hardcore(*params.Hardcore)) + h := 0 + if *params.Hardcore { + h = 1 + } + details = append(details, raHttp.H(h)) } r, err := c.do(details...) if err != nil { @@ -119,14 +127,14 @@ func (c *Client) GetGameRankAndScore(params models.GetGameRankAndScoreParameters raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetGameRankAndScore.php"), raHttp.APIToken(c.Secret), - raHttp.Game(params.GameID), + raHttp.G(params.GameID), } if params.LatestMasters != nil { + t := 0 if *params.LatestMasters { - details = append(details, raHttp.To(1)) - } else { - details = append(details, raHttp.To(0)) + t = 1 } + details = append(details, raHttp.T(t)) } r, err := c.do(details...) if err != nil { diff --git a/game_test.go b/game_test.go index fef896b..b400ec0 100644 --- a/game_test.go +++ b/game_test.go @@ -181,6 +181,7 @@ func TestGetGameExtended(tt *testing.T) { require.NoError(tt, err) created, err := time.Parse(time.DateTime, "2022-09-28 00:36:26") require.NoError(tt, err) + unofficial := true tests := []struct { name string params models.GetGameExtentedParameters @@ -195,7 +196,7 @@ func TestGetGameExtended(tt *testing.T) { name: "fail to call endpoint", params: models.GetGameExtentedParameters{ GameID: 2991, - Unofficial: true, + Unofficial: &unofficial, }, modifyURL: func(url string) string { return "" @@ -400,7 +401,6 @@ func TestGetGameExtended(tt *testing.T) { require.Equal(t, num, len(resp)) })) defer server.Close() - client := retroachievements.New(test.modifyURL(server.URL), "go-retroachievements/v0.0.0", "some_secret") resp, err := client.GetGameExtended(test.params) test.assert(t, resp, err) @@ -521,7 +521,6 @@ func TestGetGameHashes(tt *testing.T) { require.Equal(t, num, len(resp)) })) defer server.Close() - client := retroachievements.New(test.modifyURL(server.URL), "go-retroachievements/v0.0.0", "some_secret") resp, err := client.GetGameHashes(test.params) test.assert(t, resp, err) @@ -657,7 +656,6 @@ func TestGetAchievementCount(tt *testing.T) { require.Equal(t, num, len(resp)) })) defer server.Close() - client := retroachievements.New(test.modifyURL(server.URL), "go-retroachievements/v0.0.0", "some_secret") resp, err := client.GetAchievementCount(test.params) test.assert(t, resp, err) @@ -828,7 +826,6 @@ func TestGetAchievementDistribution(tt *testing.T) { require.Equal(t, num, len(resp)) })) defer server.Close() - client := retroachievements.New(test.modifyURL(server.URL), "go-retroachievements/v0.0.0", "some_secret") resp, err := client.GetAchievementDistribution(test.params) test.assert(t, resp, err) @@ -963,7 +960,6 @@ func TestGetGameRankAndScore(tt *testing.T) { require.Equal(t, num, len(resp)) })) defer server.Close() - client := retroachievements.New(test.modifyURL(server.URL), "go-retroachievements/v0.0.0", "some_secret") resp, err := client.GetGameRankAndScore(test.params) test.assert(t, resp, err) diff --git a/http/request.go b/http/request.go index ca57c0f..27f73d7 100644 --- a/http/request.go +++ b/http/request.go @@ -60,45 +60,45 @@ func UserAgent() RequestDetail { }) } -// Username adds the username to the query parameters -func Username(username string) RequestDetail { +// M adds a 'u' string to the query parameters +func U(u string) RequestDetail { return requestDetailFn(func(r *Request) { - r.Params["u"] = username + r.Params["u"] = u }) } -// LookbackMinutes adds the lookback minutes to the query parameters -func LookbackMinutes(minutes int) RequestDetail { +// M adds a 'm' number to the query parameters +func M(m int) RequestDetail { return requestDetailFn(func(r *Request) { - r.Params["m"] = strconv.Itoa(minutes) + r.Params["m"] = strconv.Itoa(m) }) } -// From adds a start time to the query parameters in unix seconds -func From(t int64) RequestDetail { +// F adds a 'f' number to the query parameters +func F(f int) RequestDetail { return requestDetailFn(func(r *Request) { - r.Params["f"] = strconv.Itoa(int(t)) + r.Params["f"] = strconv.Itoa(f) }) } -// To adds a end time to the query parameters in unix seconds -func To(t int64) RequestDetail { +// T adds a 't' number to the query parameters +func T(t int) RequestDetail { return requestDetailFn(func(r *Request) { - r.Params["t"] = strconv.Itoa(int(t)) + r.Params["t"] = strconv.Itoa(t) }) } -// Date adds a string date (ignoring timestamp) to the query parameters -func Date(t time.Time) RequestDetail { +// D adds a 'd' date to the query parameters +func D(d time.Time) RequestDetail { return requestDetailFn(func(r *Request) { - r.Params["d"] = t.UTC().Format(time.DateOnly) + r.Params["d"] = d.UTC().Format(time.DateOnly) }) } -// IDs adds the target game ids to the query parameters -func IDs(ids []int) RequestDetail { +// I adds a 'i' number list to the query parameters +func I(is []int) RequestDetail { var strIDs []string - for _, i := range ids { + for _, i := range is { strIDs = append(strIDs, strconv.Itoa(i)) } return requestDetailFn(func(r *Request) { @@ -106,42 +106,38 @@ func IDs(ids []int) RequestDetail { }) } -// Game adds a target game id to the query parameters -func Game(game int) RequestDetail { +// G adds a 'g' number to the query parameters +func G(g int) RequestDetail { return requestDetailFn(func(r *Request) { - r.Params["g"] = strconv.Itoa(game) + r.Params["g"] = strconv.Itoa(g) }) } -// Count adds a count to the query parameters -func Count(count int) RequestDetail { +// C adds a 'c' number to the query parameters +func C(c int) RequestDetail { return requestDetailFn(func(r *Request) { - r.Params["c"] = strconv.Itoa(count) + r.Params["c"] = strconv.Itoa(c) }) } -// Offset adds a offset to the query parameters -func Offset(offset int) RequestDetail { +// O adds a 'o' number to the query parameters +func O(o int) RequestDetail { return requestDetailFn(func(r *Request) { - r.Params["o"] = strconv.Itoa(offset) + r.Params["o"] = strconv.Itoa(o) }) } -// Achievement adds a achievement number query parameter -func Achievement(achievement int) RequestDetail { +// A adds a 'a' number to the query parameters +func A(a int) RequestDetail { return requestDetailFn(func(r *Request) { - r.Params["a"] = strconv.Itoa(achievement) + r.Params["a"] = strconv.Itoa(a) }) } -// Hardcore adds a Hardcore boolean query parameter -func Hardcore(hardcore bool) RequestDetail { - numHardcore := 0 - if hardcore { - numHardcore = 1 - } +// H adds a 'h' number to the query parameters +func H(h int) RequestDetail { return requestDetailFn(func(r *Request) { - r.Params["h"] = strconv.Itoa(numHardcore) + r.Params["h"] = strconv.Itoa(h) }) } diff --git a/http/request_test.go b/http/request_test.go index 97ddca3..2fdbf80 100644 --- a/http/request_test.go +++ b/http/request_test.go @@ -20,17 +20,17 @@ func TestNewRequest(t *testing.T) { raHttp.UserAgent(), raHttp.APIToken("secret_token"), raHttp.BearerToken("secret_bearer"), - raHttp.Username("myUsername"), - raHttp.LookbackMinutes(10), - raHttp.From(now.Unix()), - raHttp.To(later.Unix()), - raHttp.Date(now), - raHttp.IDs([]int{2837, 4535}), - raHttp.Game(345), - raHttp.Achievement(1), - raHttp.Count(20), - raHttp.Offset(34), - raHttp.Hardcore(true), + raHttp.U("myUsername"), + raHttp.M(10), + raHttp.F(int(now.Unix())), + raHttp.T(int(later.Unix())), + raHttp.D(now), + raHttp.I([]int{2837, 4535}), + raHttp.G(345), + raHttp.A(1), + raHttp.C(20), + raHttp.O(34), + raHttp.H(1), ) expected := &raHttp.Request{ diff --git a/leaderboards.go b/leaderboards.go index 9d57cea..10392e2 100644 --- a/leaderboards.go +++ b/leaderboards.go @@ -14,13 +14,13 @@ func (c *Client) GetGameLeaderboards(params models.GetGameLeaderboardsParameters raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetGameLeaderboards.php"), raHttp.APIToken(c.Secret), - raHttp.IDs([]int{params.GameID}), + raHttp.I([]int{params.GameID}), } if params.Count != nil { - details = append(details, raHttp.Count(*params.Count)) + details = append(details, raHttp.C(*params.Count)) } if params.Offset != nil { - details = append(details, raHttp.Offset(*params.Offset)) + details = append(details, raHttp.O(*params.Offset)) } r, err := c.do(details...) if err != nil { @@ -39,13 +39,13 @@ func (c *Client) GetLeaderboardEntries(params models.GetLeaderboardEntriesParame raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetLeaderboardEntries.php"), raHttp.APIToken(c.Secret), - raHttp.IDs([]int{params.LeaderboardID}), + raHttp.I([]int{params.LeaderboardID}), } if params.Count != nil { - details = append(details, raHttp.Count(*params.Count)) + details = append(details, raHttp.C(*params.Count)) } if params.Offset != nil { - details = append(details, raHttp.Offset(*params.Offset)) + details = append(details, raHttp.O(*params.Offset)) } r, err := c.do(details...) if err != nil { diff --git a/models/game.go b/models/game.go index be85417..0a997d2 100644 --- a/models/game.go +++ b/models/game.go @@ -32,8 +32,8 @@ type GetGameExtentedParameters struct { // The target game ID GameID int - // Get unofficial achievements - Unofficial bool + // [Optional] Get unofficial achievements (default: false) + Unofficial *bool } type GetGameExtented struct { diff --git a/models/system.go b/models/system.go new file mode 100644 index 0000000..269ecf2 --- /dev/null +++ b/models/system.go @@ -0,0 +1,17 @@ +package models + +type GetConsoleIDsParameters struct { + // [Optional] Get only active systems, use false for all systems (default: false) + OnlyActive *bool + + // [Optional] Get only active systems, use false for all system types (Events, Hubs, etc) (default: false) + OnlyGameSystems *bool +} + +type GetConsoleIDs struct { + ID int `json:"ID"` + Name string `json:"Name"` + IconURL string `json:"IconURL"` + Active bool `json:"Active"` + IsGameSystem bool `json:"IsGameSystem"` +} diff --git a/system.go b/system.go new file mode 100644 index 0000000..fcca8ff --- /dev/null +++ b/system.go @@ -0,0 +1,41 @@ +package retroachievements + +import ( + "fmt" + "net/http" + + raHttp "github.com/joshraphael/go-retroachievements/http" + "github.com/joshraphael/go-retroachievements/models" +) + +// GetConsoleIDs gets the complete list of all system ID and name pairs on the site. +func (c *Client) GetConsoleIDs(params models.GetConsoleIDsParameters) ([]models.GetConsoleIDs, error) { + details := []raHttp.RequestDetail{ + raHttp.Method(http.MethodGet), + raHttp.Path("/API/API_GetConsoleIDs.php"), + raHttp.APIToken(c.Secret), + } + if params.OnlyActive != nil { + active := 0 + if *params.OnlyActive { + active = 1 + } + details = append(details, raHttp.A(active)) + } + if params.OnlyGameSystems != nil { + g := 0 + if *params.OnlyGameSystems { + g = 1 + } + details = append(details, raHttp.G(g)) + } + r, err := c.do(details...) + if err != nil { + return nil, fmt.Errorf("calling endpoint: %w", err) + } + resp, err := raHttp.ResponseList[models.GetConsoleIDs](r) + if err != nil { + return nil, fmt.Errorf("parsing response list: %w", err) + } + return resp, nil +} diff --git a/system_test.go b/system_test.go new file mode 100644 index 0000000..daf72f2 --- /dev/null +++ b/system_test.go @@ -0,0 +1,142 @@ +package retroachievements_test + +import ( + "encoding/json" + "net/http" + "net/http/httptest" + "testing" + + "github.com/joshraphael/go-retroachievements" + "github.com/joshraphael/go-retroachievements/models" + "github.com/stretchr/testify/require" +) + +func TestGetConsoleIDs(tt *testing.T) { + active := true + gameSystems := true + tests := []struct { + name string + params models.GetConsoleIDsParameters + modifyURL func(url string) string + responseCode int + responseMessage []models.GetConsoleIDs + responseError models.ErrorResponse + response func(messageBytes []byte, errorBytes []byte) []byte + assert func(t *testing.T, resp []models.GetConsoleIDs, err error) + }{ + { + name: "fail to call endpoint", + params: models.GetConsoleIDsParameters{ + OnlyActive: &active, + OnlyGameSystems: &gameSystems, + }, + modifyURL: func(url string) string { + return "" + }, + responseCode: http.StatusOK, + response: func(messageBytes []byte, errorBytes []byte) []byte { + return messageBytes + }, + assert: func(t *testing.T, resp []models.GetConsoleIDs, err error) { + require.Nil(t, resp) + require.EqualError(t, err, "calling endpoint: Get \"/API/API_GetConsoleIDs.php?a=1&g=1&y=some_secret\": unsupported protocol scheme \"\"") + }, + }, + { + name: "error response", + params: models.GetConsoleIDsParameters{ + OnlyActive: &active, + OnlyGameSystems: &gameSystems, + }, + modifyURL: func(url string) string { + return url + }, + responseCode: http.StatusUnauthorized, + responseError: models.ErrorResponse{ + Message: "test", + Errors: []models.ErrorDetail{ + { + Status: http.StatusUnauthorized, + Code: "unauthorized", + Title: "Not Authorized", + }, + }, + }, + response: func(messageBytes []byte, errorBytes []byte) []byte { + return errorBytes + }, + assert: func(t *testing.T, resp []models.GetConsoleIDs, err error) { + require.Nil(t, resp) + require.EqualError(t, err, "parsing response list: error responses: [401] Not Authorized") + }, + }, + { + name: "success", + params: models.GetConsoleIDsParameters{ + OnlyActive: &active, + OnlyGameSystems: &gameSystems, + }, + modifyURL: func(url string) string { + return url + }, + responseCode: http.StatusOK, + responseMessage: []models.GetConsoleIDs{ + { + ID: 1, + Name: "Genesis/Mega Drive", + IconURL: "https://static.retroachievements.org/assets/images/system/md.png", + Active: true, + IsGameSystem: true, + }, + { + ID: 2, + Name: "Nintendo 64", + IconURL: "https://static.retroachievements.org/assets/images/system/n64.png", + Active: true, + IsGameSystem: true, + }, + }, + response: func(messageBytes []byte, errorBytes []byte) []byte { + return messageBytes + }, + assert: func(t *testing.T, resp []models.GetConsoleIDs, err error) { + require.NotNil(t, resp) + require.Len(t, resp, 2) + require.Equal(t, 1, resp[0].ID) + require.Equal(t, "Genesis/Mega Drive", resp[0].Name) + require.Equal(t, "https://static.retroachievements.org/assets/images/system/md.png", resp[0].IconURL) + require.True(t, resp[0].Active) + require.True(t, resp[0].IsGameSystem) + require.Equal(t, 2, resp[1].ID) + require.Equal(t, "Nintendo 64", resp[1].Name) + require.Equal(t, "https://static.retroachievements.org/assets/images/system/n64.png", resp[1].IconURL) + require.True(t, resp[1].Active) + require.True(t, resp[1].IsGameSystem) + require.NoError(t, err) + }, + }, + } + for _, test := range tests { + tt.Run(test.name, func(t *testing.T) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + expectedPath := "/API/API_GetConsoleIDs.php" + if r.URL.Path != expectedPath { + t.Errorf("Expected to request '%s', got: %s", expectedPath, r.URL.Path) + } + w.WriteHeader(test.responseCode) + messageBytes, err := json.Marshal(test.responseMessage) + require.NoError(t, err) + errBytes, err := json.Marshal(test.responseError) + require.NoError(t, err) + resp := test.response(messageBytes, errBytes) + num, err := w.Write(resp) + require.NoError(t, err) + require.Equal(t, num, len(resp)) + })) + defer server.Close() + client := retroachievements.New(test.modifyURL(server.URL), "go-retroachievements/v0.0.0", "some_secret") + resp, err := client.GetConsoleIDs(test.params) + test.assert(t, resp, err) + }) + } +} diff --git a/user.go b/user.go index 3947d1b..039aeb4 100644 --- a/user.go +++ b/user.go @@ -14,7 +14,7 @@ func (c *Client) GetUserProfile(params models.GetUserProfileParameters) (*models raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetUserProfile.php"), raHttp.APIToken(c.Secret), - raHttp.Username(params.Username), + raHttp.U(params.Username), ) if err != nil { return nil, fmt.Errorf("calling endpoint: %w", err) @@ -32,10 +32,10 @@ func (c *Client) GetUserRecentAchievements(params models.GetUserRecentAchievemen raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetUserRecentAchievements.php"), raHttp.APIToken(c.Secret), - raHttp.Username(params.Username), + raHttp.U(params.Username), } if params.LookbackMinutes != nil { - details = append(details, raHttp.LookbackMinutes(*params.LookbackMinutes)) + details = append(details, raHttp.M(*params.LookbackMinutes)) } resp, err := c.do(details...) if err != nil { @@ -54,9 +54,9 @@ func (c *Client) GetAchievementsEarnedBetween(params models.GetAchievementsEarne raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetAchievementsEarnedBetween.php"), raHttp.APIToken(c.Secret), - raHttp.Username(params.Username), - raHttp.From(params.From.Unix()), - raHttp.To(params.To.Unix()), + raHttp.U(params.Username), + raHttp.F(int(params.From.Unix())), + raHttp.T(int(params.To.Unix())), ) if err != nil { return nil, fmt.Errorf("calling endpoint: %w", err) @@ -74,8 +74,8 @@ func (c *Client) GetAchievementsEarnedOnDay(params models.GetAchievementsEarnedO raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetAchievementsEarnedOnDay.php"), raHttp.APIToken(c.Secret), - raHttp.Username(params.Username), - raHttp.Date(params.Date), + raHttp.U(params.Username), + raHttp.D(params.Date), ) if err != nil { return nil, fmt.Errorf("calling endpoint: %w", err) @@ -93,11 +93,15 @@ func (c *Client) GetGameInfoAndUserProgress(params models.GetGameInfoAndUserProg raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetGameInfoAndUserProgress.php"), raHttp.APIToken(c.Secret), - raHttp.Username(params.Username), - raHttp.Game(params.GameID), + raHttp.U(params.Username), + raHttp.G(params.GameID), } - if params.IncludeAwardMetadata != nil && *params.IncludeAwardMetadata { - details = append(details, raHttp.Achievement(1)) + if params.IncludeAwardMetadata != nil { + a := 0 + if *params.IncludeAwardMetadata { + a = 1 + } + details = append(details, raHttp.A(a)) } resp, err := c.do(details...) if err != nil { @@ -116,7 +120,7 @@ func (c *Client) GetUserCompletionProgress(params models.GetUserCompletionProgre raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetUserCompletionProgress.php"), raHttp.APIToken(c.Secret), - raHttp.Username(params.Username), + raHttp.U(params.Username), ) if err != nil { return nil, fmt.Errorf("calling endpoint: %w", err) @@ -134,7 +138,7 @@ func (c *Client) GetUserAwards(params models.GetUserAwardsParameters) (*models.G raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetUserAwards.php"), raHttp.APIToken(c.Secret), - raHttp.Username(params.Username), + raHttp.U(params.Username), ) if err != nil { return nil, fmt.Errorf("calling endpoint: %w", err) @@ -152,7 +156,7 @@ func (c *Client) GetUserClaims(params models.GetUserClaimsParameters) ([]models. raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetUserClaims.php"), raHttp.APIToken(c.Secret), - raHttp.Username(params.Username), + raHttp.U(params.Username), ) if err != nil { return nil, fmt.Errorf("calling endpoint: %w", err) @@ -170,8 +174,8 @@ func (c *Client) GetUserGameRankAndScore(params models.GetUserGameRankAndScorePa raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetUserGameRankAndScore.php"), raHttp.APIToken(c.Secret), - raHttp.Username(params.Username), - raHttp.Game(params.GameID), + raHttp.U(params.Username), + raHttp.G(params.GameID), ) if err != nil { return nil, fmt.Errorf("calling endpoint: %w", err) @@ -189,7 +193,7 @@ func (c *Client) GetUserPoints(params models.GetUserPointsParameters) (*models.G raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetUserPoints.php"), raHttp.APIToken(c.Secret), - raHttp.Username(params.Username), + raHttp.U(params.Username), ) if err != nil { return nil, fmt.Errorf("calling endpoint: %w", err) @@ -207,8 +211,8 @@ func (c *Client) GetUserProgress(params models.GetUserProgressParameters) (*map[ raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetUserProgress.php"), raHttp.APIToken(c.Secret), - raHttp.Username(params.Username), - raHttp.IDs(params.GameIDs), + raHttp.U(params.Username), + raHttp.I(params.GameIDs), ) if err != nil { return nil, fmt.Errorf("calling endpoint: %w", err) @@ -226,13 +230,13 @@ func (c *Client) GetUserRecentlyPlayedGames(params models.GetUserRecentlyPlayedG raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetUserRecentlyPlayedGames.php"), raHttp.APIToken(c.Secret), - raHttp.Username(params.Username), + raHttp.U(params.Username), } if params.Count != nil { - details = append(details, raHttp.Count(*params.Count)) + details = append(details, raHttp.C(*params.Count)) } if params.Offset != nil { - details = append(details, raHttp.Offset(*params.Offset)) + details = append(details, raHttp.O(*params.Offset)) } resp, err := c.do(details...) if err != nil { @@ -251,13 +255,13 @@ func (c *Client) GetUserSummary(params models.GetUserSummaryParameters) (*models raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetUserSummary.php"), raHttp.APIToken(c.Secret), - raHttp.Username(params.Username), + raHttp.U(params.Username), } if params.GamesCount != nil { - details = append(details, raHttp.Game(*params.GamesCount)) + details = append(details, raHttp.G(*params.GamesCount)) } if params.AchievementsCount != nil { - details = append(details, raHttp.Achievement(*params.AchievementsCount)) + details = append(details, raHttp.A(*params.AchievementsCount)) } resp, err := c.do(details...) if err != nil { @@ -276,7 +280,7 @@ func (c *Client) GetUserCompletedGames(params models.GetUserCompletedGamesParame raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetUserCompletedGames.php"), raHttp.APIToken(c.Secret), - raHttp.Username(params.Username), + raHttp.U(params.Username), ) if err != nil { return nil, fmt.Errorf("calling endpoint: %w", err) @@ -294,13 +298,13 @@ func (c *Client) GetUserWantToPlayList(params models.GetUserWantToPlayListParame raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetUserWantToPlayList.php"), raHttp.APIToken(c.Secret), - raHttp.Username(params.Username), + raHttp.U(params.Username), } if params.Count != nil { - details = append(details, raHttp.Count(*params.Count)) + details = append(details, raHttp.C(*params.Count)) } if params.Offset != nil { - details = append(details, raHttp.Offset(*params.Offset)) + details = append(details, raHttp.O(*params.Offset)) } resp, err := c.do(details...) if err != nil { diff --git a/user_test.go b/user_test.go index 1d7d8fe..4b49d08 100644 --- a/user_test.go +++ b/user_test.go @@ -151,7 +151,6 @@ func TestGetUserProfile(tt *testing.T) { require.Equal(t, num, len(resp)) })) defer server.Close() - client := retroachievements.New(test.modifyURL(server.URL), "go-retroachievements/v0.0.0", "some_secret") profile, err := client.GetUserProfile(test.params) test.assert(t, profile, err) @@ -305,7 +304,6 @@ func TestGetUserRecentAchievements(tt *testing.T) { require.Equal(t, num, len(resp)) })) defer server.Close() - client := retroachievements.New(test.modifyURL(server.URL), "go-retroachievements/v0.0.0", "some_secret") achievements, err := client.GetUserRecentAchievements(test.params) test.assert(t, achievements, err) @@ -464,7 +462,6 @@ func TestGetAchievementsEarnedBetween(tt *testing.T) { require.Equal(t, num, len(resp)) })) defer server.Close() - client := retroachievements.New(test.modifyURL(server.URL), "go-retroachievements/v0.0.0", "some_secret") achievements, err := client.GetAchievementsEarnedBetween(test.params) test.assert(t, achievements, err) @@ -619,7 +616,6 @@ func TestGetAchievementsEarnedOnDay(tt *testing.T) { require.Equal(t, num, len(resp)) })) defer server.Close() - client := retroachievements.New(test.modifyURL(server.URL), "go-retroachievements/v0.0.0", "some_secret") achievements, err := client.GetAchievementsEarnedOnDay(test.params) test.assert(t, achievements, err) @@ -849,7 +845,6 @@ func TestGetGameInfoAndUserProgress(tt *testing.T) { require.Equal(t, num, len(resp)) })) defer server.Close() - client := retroachievements.New(test.modifyURL(server.URL), "go-retroachievements/v0.0.0", "some_secret") gameProgress, err := client.GetGameInfoAndUserProgress(test.params) test.assert(t, gameProgress, err) @@ -998,7 +993,6 @@ func TestGetUserCompletionProgress(tt *testing.T) { require.Equal(t, num, len(resp)) })) defer server.Close() - client := retroachievements.New(test.modifyURL(server.URL), "go-retroachievements/v0.0.0", "some_secret") userCompletionProgress, err := client.GetUserCompletionProgress(test.params) test.assert(t, userCompletionProgress, err) @@ -1159,7 +1153,6 @@ func TestGetUserAwards(tt *testing.T) { require.Equal(t, num, len(resp)) })) defer server.Close() - client := retroachievements.New(test.modifyURL(server.URL), "go-retroachievements/v0.0.0", "some_secret") userAwards, err := client.GetUserAwards(test.params) test.assert(t, userAwards, err) @@ -1317,7 +1310,6 @@ func TestGetUserClaims(tt *testing.T) { require.Equal(t, num, len(resp)) })) defer server.Close() - client := retroachievements.New(test.modifyURL(server.URL), "go-retroachievements/v0.0.0", "some_secret") userClaims, err := client.GetUserClaims(test.params) test.assert(t, userClaims, err) @@ -1446,7 +1438,6 @@ func TestGetUserGameRankAndScore(tt *testing.T) { require.Equal(t, num, len(resp)) })) defer server.Close() - client := retroachievements.New(test.modifyURL(server.URL), "go-retroachievements/v0.0.0", "some_secret") userGameRankScore, err := client.GetUserGameRankAndScore(test.params) test.assert(t, userGameRankScore, err) @@ -1561,7 +1552,6 @@ func TestGetUserPoints(tt *testing.T) { require.Equal(t, num, len(resp)) })) defer server.Close() - client := retroachievements.New(test.modifyURL(server.URL), "go-retroachievements/v0.0.0", "some_secret") points, err := client.GetUserPoints(test.params) test.assert(t, points, err)