diff --git a/examples/user/getuserrecentlyplayedgames/getuserrecentlyplayedgames.go b/examples/user/getuserrecentlyplayedgames/getuserrecentlyplayedgames.go index 63e8b58..eb6aace 100644 --- a/examples/user/getuserrecentlyplayedgames/getuserrecentlyplayedgames.go +++ b/examples/user/getuserrecentlyplayedgames/getuserrecentlyplayedgames.go @@ -1,4 +1,4 @@ -// Package getuserrecentachievements provides an example for a users achievements in the last X minutes +// Package getuserrecentlyplayedgames provides an example for a users recently played games package main import ( @@ -9,7 +9,7 @@ import ( ) /* -Test script, add RA_API_KEY to your env and use `go run getuserrecentachievements.go` +Test script, add RA_API_KEY to your env and use `go run getuserrecentlyplayedgames.go` */ func main() { secret := os.Getenv("RA_API_KEY") diff --git a/models/user.go b/models/user.go new file mode 100644 index 0000000..6e42da1 --- /dev/null +++ b/models/user.go @@ -0,0 +1,99 @@ +package models + +// GetUserProfile describes elements of a users profile +type GetUserProfile struct { + // Username of the profile + User string `json:"User"` + + // URL resource to the image of the profile avatar + UserPic string `json:"UserPic"` + + // Date the user joined + MemberSince DateTime `json:"MemberSince"` + + // Last game played rich presence text + RichPresenceMsg string `json:"RichPresenceMsg"` + + // ID of last game played + LastGameID int `json:"LastGameID"` + + // Number of achievements unlocked by players + ContribCount int `json:"ContribCount"` + + // Number of points awarded to players + ContribYield int `json:"ContribYield"` + + // Number of points awarded on this profile + TotalPoints int `json:"TotalPoints"` + + // Number of softcore points awarded on this profile + TotalSoftcorePoints int `json:"TotalSoftcorePoints"` + + // Number of RetroPoints awarded on this profile + TotalTruePoints int `json:"TotalTruePoints"` + + // Site permissions (0 = Normal, 1 = Jr. Dev, 2 = Developer, 3 = Moderator, 4 = Admin) + Permissions int `json:"Permissions"` + + // "1" if the user is untracked, otherwise "0" + Untracked int `json:"Untracked"` + + // ID of the profile + ID int `json:"ID"` + + // Allows other users to comment on their profile wall + UserWallActive bool `json:"UserWallActive"` + + // Custom status message displayed on profile + Motto string `json:"Motto"` +} + +type GetUserRecentAchievements struct { + // Title of the achievement + Title string `json:"Title"` + + // Description of the achievement + Description string `json:"Description"` + + // Points awarded + Points int `json:"Points"` + + // Ratio of points the achievemnet is worth + TrueRatio int `json:"TrueRatio"` + + // Username of the author of the achievement + Author string `json:"Author"` + + // The date the achievement was unlocked + Date DateTime `json:"Date"` + + // Mode the achievement was unlocked in: 1 if in hardcore mode, 0 if not + HardcoreMode int `json:"HardcoreMode"` + + // The ID of the achievement + AchievementID int `json:"AchievementID"` + + // Name of the padge resource + BadgeName string `json:"BadgeName"` + + // Type of achievement (standard, missable, progression, win_condition) + Type string `json:"Type"` + + // Title of the game + GameTitle string `json:"GameTitle"` + + // URL resource of the game icon + GameIcon string `json:"GameIcon"` + + // ID of the game + GameID int `json:"GameID"` + + // Common name of the console + ConsoleName string `json:"ConsoleName"` + + // URL resource to the image used for the achievment badge + BadgeURL string `json:"BadgeURL"` + + // URL resource to the game page + GameURL string `json:"GameURL"` +} diff --git a/user.go b/user.go index 6d2f702..5c8bff4 100644 --- a/user.go +++ b/user.go @@ -10,7 +10,7 @@ import ( ) // GetUserProfile get a user's basic profile information. -func (c *Client) GetUserProfile(username string) (*models.Profile, error) { +func (c *Client) GetUserProfile(username string) (*models.GetUserProfile, error) { resp, err := c.do( raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetUserProfile.php"), @@ -20,7 +20,7 @@ func (c *Client) GetUserProfile(username string) (*models.Profile, error) { if err != nil { return nil, fmt.Errorf("calling endpoint: %w", err) } - profile, err := raHttp.ResponseObject[models.Profile](resp) + profile, err := raHttp.ResponseObject[models.GetUserProfile](resp) if err != nil { return nil, fmt.Errorf("parsing response object: %w", err) } @@ -28,7 +28,7 @@ func (c *Client) GetUserProfile(username string) (*models.Profile, error) { } // GetUserRecentAchievements get a list of achievements recently earned by the user. -func (c *Client) GetUserRecentAchievements(username string, lookbackMinutes int) ([]models.UnlockedAchievement, error) { +func (c *Client) GetUserRecentAchievements(username string, lookbackMinutes int) ([]models.GetUserRecentAchievements, error) { resp, err := c.do( raHttp.Method(http.MethodGet), raHttp.Path("/API/API_GetUserRecentAchievements.php"), @@ -39,7 +39,7 @@ func (c *Client) GetUserRecentAchievements(username string, lookbackMinutes int) if err != nil { return nil, fmt.Errorf("calling endpoint: %w", err) } - achievements, err := raHttp.ResponseList[models.UnlockedAchievement](resp) + achievements, err := raHttp.ResponseList[models.GetUserRecentAchievements](resp) if err != nil { return nil, fmt.Errorf("parsing response list: %w", err) } diff --git a/user_test.go b/user_test.go index 94518cf..14a8fdb 100644 --- a/user_test.go +++ b/user_test.go @@ -20,10 +20,10 @@ func TestGetUserProfile(tt *testing.T) { username string modifyURL func(url string) string responseCode int - responseMessage models.Profile + responseMessage models.GetUserProfile responseError models.ErrorResponse response func(messageBytes []byte, errorBytes []byte) []byte - assert func(t *testing.T, profile *models.Profile, err error) + assert func(t *testing.T, profile *models.GetUserProfile, err error) }{ { name: "fail to call endpoint", @@ -45,7 +45,7 @@ func TestGetUserProfile(tt *testing.T) { response: func(messageBytes []byte, errorBytes []byte) []byte { return errorBytes }, - assert: func(t *testing.T, profile *models.Profile, err error) { + assert: func(t *testing.T, profile *models.GetUserProfile, err error) { require.Nil(t, profile) require.EqualError(t, err, "calling endpoint: Get \"/API/API_GetUserProfile.php?u=Test&y=some_secret\": unsupported protocol scheme \"\"") }, @@ -70,7 +70,7 @@ func TestGetUserProfile(tt *testing.T) { response: func(messageBytes []byte, errorBytes []byte) []byte { return errorBytes }, - assert: func(t *testing.T, profile *models.Profile, err error) { + assert: func(t *testing.T, profile *models.GetUserProfile, err error) { require.Nil(t, profile) require.EqualError(t, err, "parsing response object: error responses: [401] Not Authorized") }, @@ -82,7 +82,7 @@ func TestGetUserProfile(tt *testing.T) { return url }, responseCode: http.StatusOK, - responseMessage: models.Profile{ + responseMessage: models.GetUserProfile{ User: "xXxSnip3rxXx", UserPic: "/some/resource.png", MemberSince: models.DateTime{ @@ -104,7 +104,7 @@ func TestGetUserProfile(tt *testing.T) { response: func(messageBytes []byte, errorBytes []byte) []byte { return messageBytes }, - assert: func(t *testing.T, profile *models.Profile, err error) { + assert: func(t *testing.T, profile *models.GetUserProfile, err error) { require.NoError(t, err) require.NotNil(t, profile) require.Equal(t, "xXxSnip3rxXx", profile.User) @@ -162,10 +162,10 @@ func TestGetUserRecentAchievements(tt *testing.T) { lookbackMinutes int modifyURL func(url string) string responseCode int - responseMessage []models.UnlockedAchievement + responseMessage []models.GetUserRecentAchievements responseError models.ErrorResponse response func(messageBytes []byte, errorBytes []byte) []byte - assert func(t *testing.T, achievements []models.UnlockedAchievement, err error) + assert func(t *testing.T, achievements []models.GetUserRecentAchievements, err error) }{ { name: "fail to call endpoint", @@ -188,7 +188,7 @@ func TestGetUserRecentAchievements(tt *testing.T) { response: func(messageBytes []byte, errorBytes []byte) []byte { return errorBytes }, - assert: func(t *testing.T, achievements []models.UnlockedAchievement, err error) { + assert: func(t *testing.T, achievements []models.GetUserRecentAchievements, err error) { require.Nil(t, achievements) require.EqualError(t, err, "calling endpoint: Get \"/API/API_GetUserRecentAchievements.php?m=60&u=Test&y=some_secret\": unsupported protocol scheme \"\"") }, @@ -214,7 +214,7 @@ func TestGetUserRecentAchievements(tt *testing.T) { response: func(messageBytes []byte, errorBytes []byte) []byte { return errorBytes }, - assert: func(t *testing.T, achievements []models.UnlockedAchievement, err error) { + assert: func(t *testing.T, achievements []models.GetUserRecentAchievements, err error) { require.Nil(t, achievements) require.EqualError(t, err, "parsing response list: error responses: [401] Not Authorized") }, @@ -227,15 +227,13 @@ func TestGetUserRecentAchievements(tt *testing.T) { return url }, responseCode: http.StatusOK, - responseMessage: []models.UnlockedAchievement{ + responseMessage: []models.GetUserRecentAchievements{ { - Achievement: models.Achievement{ - Title: "Beat Level 1", - Description: "Finish level 1", - Points: 10, - TrueRatio: 234, - Author: "jamiras", - }, + Title: "Beat Level 1", + Description: "Finish level 1", + Points: 10, + TrueRatio: 234, + Author: "jamiras", Date: models.DateTime{ Time: now, }, @@ -254,7 +252,7 @@ func TestGetUserRecentAchievements(tt *testing.T) { response: func(messageBytes []byte, errorBytes []byte) []byte { return messageBytes }, - assert: func(t *testing.T, achievements []models.UnlockedAchievement, err error) { + assert: func(t *testing.T, achievements []models.GetUserRecentAchievements, err error) { require.NotNil(t, achievements) require.Len(t, achievements, 1) require.Equal(t, models.DateTime{