Skip to content

Commit

Permalink
add GetUserSummary
Browse files Browse the repository at this point in the history
  • Loading branch information
joshraphael committed Nov 17, 2024
1 parent dd81388 commit d684187
Show file tree
Hide file tree
Showing 12 changed files with 461 additions and 190 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ For convenience, the API docs and examples can be found in the tables below
|`GetUserPoints()`|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()`|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)|
|`GetUserRecentlyPlayedGames()`|Get a list of games a user has recently played.|[docs](https://api-docs.retroachievements.org/v1/get-user-recently-played-games.html) \| [example](examples/user/getuserrecentlyplayedgames/getuserrecentlyplayedgames.go)|
|`GetUserSummary()`|Get a user's profile metadata.|[docs](https://api-docs.retroachievements.org/v1/get-user-summary.html) \| [example](examples/user/getusersummary/getusersummary.go)|

<h3>Game</h3>

Expand Down
32 changes: 32 additions & 0 deletions examples/user/getusersummary/getusersummary.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Package getusersummary provides an example for a users summary info
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 getusersummary.go`
*/
func main() {
secret := os.Getenv("RA_API_KEY")

client := retroachievements.NewClient(secret)

games := 10
achievements := 10
resp, err := client.GetUserSummary(models.GetUserSummaryParameters{
Username: "jamiras",
GamesCount: &games,
AchievementsCount: &achievements,
})
if err != nil {
panic(err)
}

fmt.Printf("%+v\n", resp)
}
20 changes: 10 additions & 10 deletions http/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ func IDs(ids []int) RequestDetail {
})
}

// GameID adds a target game id to the query parameters
func GameID(gameId int) RequestDetail {
// Game adds a target game id to the query parameters
func Game(game int) RequestDetail {
return requestDetailFn(func(r *Request) {
r.Params["g"] = strconv.Itoa(gameId)
r.Params["g"] = strconv.Itoa(game)
})
}

Expand All @@ -120,14 +120,14 @@ func Offset(offset int) RequestDetail {
})
}

// AwardMetadata adds a target game id to the query parameters
func AwardMetadata(awardMetadata bool) RequestDetail {
// Achievement adds a achievement number query parameter
func Achievement(achievement int) RequestDetail {
return requestDetailFn(func(r *Request) {
a := "0"
if awardMetadata {
a = "1"
}
r.Params["a"] = a
// a := "0"
// if awardMetadata {
// a = "1"
// }
r.Params["a"] = strconv.Itoa(achievement)
})
}

Expand Down
4 changes: 2 additions & 2 deletions http/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func TestNewRequest(t *testing.T) {
raHttp.To(later.Unix()),
raHttp.Date(now),
raHttp.IDs([]int{2837, 4535}),
raHttp.GameID(345),
raHttp.AwardMetadata(true),
raHttp.Game(345),
raHttp.Achievement(1),
raHttp.Count(20),
raHttp.Offset(34),
)
Expand Down
71 changes: 0 additions & 71 deletions models/achievements.go

This file was deleted.

13 changes: 0 additions & 13 deletions models/awards.go

This file was deleted.

10 changes: 0 additions & 10 deletions models/claims.go

This file was deleted.

58 changes: 0 additions & 58 deletions models/old_game.go

This file was deleted.

20 changes: 0 additions & 20 deletions models/profile.go

This file was deleted.

97 changes: 97 additions & 0 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,100 @@ type GetUserRecentlyPlayedGames struct {
LastPlayed DateTime `json:"LastPlayed"`
AchievementsTotal int `json:"AchievementsTotal"`
}

type GetUserSummaryParameters struct {
// The target username
Username string

// [Optional] The number of recent games to return (default: 0).
GamesCount *int

// [Optional] The number of recent achievements to return (default: 10)
AchievementsCount *int
}

type GetUserSummary struct {
User string `json:"User"`
UserPic string `json:"UserPic"`
TotalRanked int `json:"TotalRanked"`
Status string `json:"Status"`
RichPresenceMsg string `json:"RichPresenceMsg"`
LastGameID int `json:"LastGameID"`
ContribCount int `json:"ContribCount"`
ContribYield int `json:"ContribYield"`
TotalPoints int `json:"TotalPoints"`
TotalSoftcorePoints int `json:"TotalSoftcorePoints"`
TotalTruePoints int `json:"TotalTruePoints"`
Permissions int `json:"Permissions"`
Untracked int `json:"Untracked"`
ID int `json:"ID"`
UserWallActive int `json:"UserWallActive"`
Motto string `json:"Motto"`
RecentlyPlayedCount int `json:"RecentlyPlayedCount"`
Rank *int `json:"Rank"`
MemberSince DateTime `json:"MemberSince"`
LastActivity GetUserSummaryLastActivity `json:"LastActivity"`
RecentlyPlayed []GetUserSummaryRecentlyPlayed `json:"RecentlyPlayed"`
Awarded map[string]GetUserSummaryAwarded `json:"Awarded"`
RecentAchievements map[string]map[string]GetUserSummaryRecentAchievements `json:"RecentAchievements"`
LastGame GetUserSummaryLastGame `json:"LastGame"`
}

type GetUserSummaryLastActivity struct {
ID int `json:"ID"`
User string `json:"User"`
}

type GetUserSummaryRecentlyPlayed struct {
GameID int `json:"GameID"`
ConsoleID int `json:"ConsoleID"`
ConsoleName string `json:"ConsoleName"`
Title string `json:"Title"`
ImageIcon string `json:"ImageIcon"`
ImageTitle string `json:"ImageTitle"`
ImageIngame string `json:"ImageIngame"`
ImageBoxArt string `json:"ImageBoxArt"`
LastPlayed DateTime `json:"LastPlayed"`
AchievementsTotal int `json:"AchievementsTotal"`
}

type GetUserSummaryAwarded struct {
NumPossibleAchievements int `json:"NumPossibleAchievements"`
PossibleScore int `json:"PossibleScore"`
NumAchieved int `json:"NumAchieved"`
ScoreAchieved int `json:"ScoreAchieved"`
NumAchievedHardcore int `json:"NumAchievedHardcore"`
ScoreAchievedHardcore int `json:"ScoreAchievedHardcore"`
}

type GetUserSummaryRecentAchievements struct {
ID int `json:"ID"`
GameID int `json:"GameID"`
GameTitle string `json:"GameTitle"`
Title string `json:"Title"`
Description string `json:"Description"`
Points int `json:"Points"`
Type *string `json:"Type"`
BadgeName string `json:"BadgeName"`
IsAwarded string `json:"IsAwarded"`
DateAwarded DateTime `json:"DateAwarded"`
HardcoreAchieved int `json:"HardcoreAchieved"`
}

type GetUserSummaryLastGame struct {
ID int `json:"ID"`
Title string `json:"Title"`
ConsoleID int `json:"ConsoleID"`
ConsoleName string `json:"ConsoleName"`
ForumTopicID int `json:"ForumTopicID"`
Flags int `json:"Flags"`
ImageIcon string `json:"ImageIcon"`
ImageTitle string `json:"ImageTitle"`
ImageIngame string `json:"ImageIngame"`
ImageBoxArt string `json:"ImageBoxArt"`
Publisher string `json:"Publisher"`
Developer string `json:"Developer"`
Genre string `json:"Genre"`
Released LongMonthDate `json:"Released"`
IsFinal int `json:"IsFinal"`
}
Loading

0 comments on commit d684187

Please sign in to comment.