diff --git a/README.md b/README.md index c248200..b7007f9 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ For convenience, the API docs and examples can be found in the tables below |`GetGameInfoAndUserProgress()`|Get metadata about a game as well as a user's progress on that game.|[docs](https://api-docs.retroachievements.org/v1/get-game-info-and-user-progress.html) \| [example](examples/user/getgameinfoanduserprogress/getgameinfoanduserprogress.go)| |`GetUserCompletionProgress()`|Get metadata about all the user's played games and any awards associated with them.|[docs](https://api-docs.retroachievements.org/v1/get-user-completion-progress.html) \| [example](examples/user/getusercompletionprogress/getusercompletionprogress.go)| |`GetUserAwards()`|Get a list of a user's site awards/badges.|[docs](https://api-docs.retroachievements.org/v1/get-user-awards.html) \| [example](examples/user/getuserawards/getuserawards.go)| -|`GetUserClaims(string)`|Get a list of set development claims made over the lifetime of a user.|[docs](https://api-docs.retroachievements.org/v1/get-user-claims.html) \| [example](examples/user/getuserclaims/getuserclaims.go)| +|`GetUserClaims()`|Get a list of set development claims made over the lifetime of a user.|[docs](https://api-docs.retroachievements.org/v1/get-user-claims.html) \| [example](examples/user/getuserclaims/getuserclaims.go)| |`GetUserGameRankAndScore(string,int)`|Get metadata about how a user has performed on a given game.|[docs](https://api-docs.retroachievements.org/v1/get-user-game-rank-and-score.html) \| [example](examples/user/getusergamerankandscore/getusergamerankandscore.go)| |`GetUserPoints(string)`|Get a user's total hardcore and softcore points.|[docs](https://api-docs.retroachievements.org/v1/get-user-points.html) \| [example](examples/user/getuserpoints/getuserpoints.go)| |`GetUserProgress(string,[]int)`|Get a user's progress on a list of specified games.|[docs](https://api-docs.retroachievements.org/v1/get-user-progress.html) \| [example](examples/user/getuserprogress/getuserprogress.go)| diff --git a/examples/user/getuserclaims/getuserclaims.go b/examples/user/getuserclaims/getuserclaims.go index 6a8dcf9..4dcb52d 100644 --- a/examples/user/getuserclaims/getuserclaims.go +++ b/examples/user/getuserclaims/getuserclaims.go @@ -6,6 +6,7 @@ import ( "os" "github.com/joshraphael/go-retroachievements" + "github.com/joshraphael/go-retroachievements/models" ) /* @@ -16,7 +17,9 @@ func main() { client := retroachievements.NewClient(secret) - resp, err := client.GetUserClaims("jamiras") + resp, err := client.GetUserClaims(models.GetUserClaimsParameters{ + Username: "jamiras", + }) if err != nil { panic(err) } diff --git a/models/claims.go b/models/claims.go index eae079d..2579efe 100644 --- a/models/claims.go +++ b/models/claims.go @@ -8,23 +8,3 @@ type Claim struct { Created DateTime `json:"Created"` Expiration DateTime `json:"Expiration"` } - -type UserClaims struct { - ID int `json:"ID"` - User string `json:"User"` - GameID int `json:"GameID"` - GameTitle string `json:"GameTitle"` - GameIcon string `json:"GameIcon"` - ConsoleID int `json:"ConsoleID"` - ConsoleName string `json:"ConsoleName"` - ClaimType int `json:"ClaimType"` - SetType int `json:"SetType"` - Status int `json:"Status"` - Extension int `json:"Extension"` - Special int `json:"Special"` - Created DateTime `json:"Created"` - DoneTime DateTime `json:"DoneTime"` - Updated DateTime `json:"Updated"` - UserIsJrDev int `json:"UserIsJrDev"` - MinutesLeft int `json:"MinutesLeft"` -} diff --git a/models/user.go b/models/user.go index fe1fa0b..5861c42 100644 --- a/models/user.go +++ b/models/user.go @@ -363,3 +363,29 @@ type Award struct { Flags *int `json:"Flags"` ImageIcon *string `json:"ImageIcon"` } + +// GetUserClaimsParameters contains the parameters needed for getting a users claims +type GetUserClaimsParameters struct { + // The target username + Username string +} + +type GetUserClaims struct { + ID int `json:"ID"` + User string `json:"User"` + GameID int `json:"GameID"` + GameTitle string `json:"GameTitle"` + GameIcon string `json:"GameIcon"` + ConsoleID int `json:"ConsoleID"` + ConsoleName string `json:"ConsoleName"` + ClaimType int `json:"ClaimType"` + SetType int `json:"SetType"` + Status int `json:"Status"` + Extension int `json:"Extension"` + Special int `json:"Special"` + Created DateTime `json:"Created"` + DoneTime DateTime `json:"DoneTime"` + Updated DateTime `json:"Updated"` + UserIsJrDev int `json:"UserIsJrDev"` + MinutesLeft int `json:"MinutesLeft"` +} diff --git a/user.go b/user.go index 15e29d3..88dc508 100644 --- a/user.go +++ b/user.go @@ -147,21 +147,21 @@ func (c *Client) GetUserAwards(params models.GetUserAwardsParameters) (*models.G } // GetUserClaims get a list of set development claims made over the lifetime of a user. -func (c *Client) GetUserClaims(username string) ([]models.UserClaims, error) { +func (c *Client) GetUserClaims(params models.GetUserClaimsParameters) ([]models.GetUserClaims, error) { resp, err := c.do( raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetUserClaims.php"), raHttp.APIToken(c.Secret), - raHttp.Username(username), + raHttp.Username(params.Username), ) if err != nil { return nil, fmt.Errorf("calling endpoint: %w", err) } - awards, err := raHttp.ResponseList[models.UserClaims](resp) + claims, err := raHttp.ResponseList[models.GetUserClaims](resp) if err != nil { return nil, fmt.Errorf("parsing response list: %w", err) } - return awards, nil + return claims, nil } // GetUserGameRankAndScore get metadata about how a user has performed on a given game. diff --git a/user_test.go b/user_test.go index 413a870..661f709 100644 --- a/user_test.go +++ b/user_test.go @@ -1178,17 +1178,19 @@ func TestGetUserClaims(tt *testing.T) { require.NoError(tt, err) tests := []struct { name string - username string + params models.GetUserClaimsParameters modifyURL func(url string) string responseCode int - responseMessage []models.UserClaims + responseMessage []models.GetUserClaims responseError models.ErrorResponse response func(messageBytes []byte, errorBytes []byte) []byte - assert func(t *testing.T, userClaims []models.UserClaims, err error) + assert func(t *testing.T, userClaims []models.GetUserClaims, err error) }{ { - name: "fail to call endpoint", - username: "Test", + name: "fail to call endpoint", + params: models.GetUserClaimsParameters{ + Username: "Test", + }, modifyURL: func(url string) string { return "" }, @@ -1206,14 +1208,16 @@ func TestGetUserClaims(tt *testing.T) { response: func(messageBytes []byte, errorBytes []byte) []byte { return errorBytes }, - assert: func(t *testing.T, userClaims []models.UserClaims, err error) { + assert: func(t *testing.T, userClaims []models.GetUserClaims, err error) { require.Nil(t, userClaims) require.EqualError(t, err, "calling endpoint: Get \"/API/API_GetUserClaims.php?u=Test&y=some_secret\": unsupported protocol scheme \"\"") }, }, { - name: "error response", - username: "Test", + name: "error response", + params: models.GetUserClaimsParameters{ + Username: "Test", + }, modifyURL: func(url string) string { return url }, @@ -1231,19 +1235,21 @@ func TestGetUserClaims(tt *testing.T) { response: func(messageBytes []byte, errorBytes []byte) []byte { return errorBytes }, - assert: func(t *testing.T, userClaims []models.UserClaims, err error) { + assert: func(t *testing.T, userClaims []models.GetUserClaims, err error) { require.Nil(t, userClaims) require.EqualError(t, err, "parsing response list: error responses: [401] Not Authorized") }, }, { - name: "success", - username: "Test", + name: "success", + params: models.GetUserClaimsParameters{ + Username: "Test", + }, modifyURL: func(url string) string { return url }, responseCode: http.StatusOK, - responseMessage: []models.UserClaims{ + responseMessage: []models.GetUserClaims{ { ID: 13657, User: "joshraphael", @@ -1273,7 +1279,7 @@ func TestGetUserClaims(tt *testing.T) { response: func(messageBytes []byte, errorBytes []byte) []byte { return messageBytes }, - assert: func(t *testing.T, userClaims []models.UserClaims, err error) { + assert: func(t *testing.T, userClaims []models.GetUserClaims, err error) { require.NotNil(t, userClaims) require.Len(t, userClaims, 1) require.Equal(t, 13657, userClaims[0].ID) @@ -1317,7 +1323,7 @@ func TestGetUserClaims(tt *testing.T) { defer server.Close() client := retroachievements.New(test.modifyURL(server.URL), "some_secret") - userClaims, err := client.GetUserClaims(test.username) + userClaims, err := client.GetUserClaims(test.params) test.assert(t, userClaims, err) }) }