Skip to content

Commit

Permalink
add User-Agent header
Browse files Browse the repository at this point in the history
  • Loading branch information
joshraphael committed Nov 25, 2024
1 parent bf688d6 commit 3a53732
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions achievement.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
func (c *Client) GetAchievementUnlocks(params models.GetAchievementUnlocksParameters) (*models.GetAchievementUnlocks, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetAchievementUnlocks.php"),
raHttp.APIToken(c.Secret),
raHttp.A(params.AchievementID),
Expand Down
1 change: 1 addition & 0 deletions comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
func (c *Client) GetComments(params models.GetCommentsParameters) (*models.GetComments, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetComments.php"),
raHttp.APIToken(c.Secret),
raHttp.T(params.Type.GetCommentsType()),
Expand Down
1 change: 1 addition & 0 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
func (c *Client) GetAchievementOfTheWeek(params models.GetAchievementOfTheWeekParameters) (*models.GetAchievementOfTheWeek, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetAchievementOfTheWeek.php"),
raHttp.APIToken(c.Secret),
)
Expand Down
4 changes: 4 additions & 0 deletions feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
func (c *Client) GetRecentGameAwards(params models.GetRecentGameAwardsParameters) (*models.GetRecentGameAwards, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetRecentGameAwards.php"),
raHttp.APIToken(c.Secret),
}
Expand Down Expand Up @@ -64,6 +65,7 @@ func (c *Client) GetRecentGameAwards(params models.GetRecentGameAwardsParameters
func (c *Client) GetActiveClaims(params models.GetActiveClaimsParameters) ([]models.GetActiveClaims, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetActiveClaims.php"),
raHttp.APIToken(c.Secret),
)
Expand All @@ -81,6 +83,7 @@ func (c *Client) GetActiveClaims(params models.GetActiveClaimsParameters) ([]mod
func (c *Client) GetClaims(params models.GetClaimsParameters) ([]models.GetClaims, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetClaims.php"),
raHttp.APIToken(c.Secret),
}
Expand All @@ -104,6 +107,7 @@ func (c *Client) GetClaims(params models.GetClaimsParameters) ([]models.GetClaim
func (c *Client) GetTopTenUsers(params models.GetTopTenUsersParameters) ([]models.GetTopTenUsers, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetTopTenUsers.php"),
raHttp.APIToken(c.Secret),
)
Expand Down
6 changes: 6 additions & 0 deletions game.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
func (c *Client) GetGame(params models.GetGameParameters) (*models.GetGame, error) {
resp, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetGame.php"),
raHttp.APIToken(c.Secret),
raHttp.I([]string{strconv.Itoa(params.GameID)}),
Expand All @@ -31,6 +32,7 @@ func (c *Client) GetGame(params models.GetGameParameters) (*models.GetGame, erro
func (c *Client) GetGameExtended(params models.GetGameExtentedParameters) (*models.GetGameExtented, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetGameExtended.php"),
raHttp.APIToken(c.Secret),
raHttp.I([]string{strconv.Itoa(params.GameID)}),
Expand All @@ -57,6 +59,7 @@ func (c *Client) GetGameExtended(params models.GetGameExtentedParameters) (*mode
func (c *Client) GetGameHashes(params models.GetGameHashesParameters) (*models.GetGameHashes, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetGameHashes.php"),
raHttp.APIToken(c.Secret),
raHttp.I([]string{strconv.Itoa(params.GameID)}),
Expand All @@ -75,6 +78,7 @@ func (c *Client) GetGameHashes(params models.GetGameHashesParameters) (*models.G
func (c *Client) GetAchievementCount(params models.GetAchievementCountParameters) (*models.GetAchievementCount, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetAchievementCount.php"),
raHttp.APIToken(c.Secret),
raHttp.I([]string{strconv.Itoa(params.GameID)}),
Expand All @@ -93,6 +97,7 @@ func (c *Client) GetAchievementCount(params models.GetAchievementCountParameters
func (c *Client) GetAchievementDistribution(params models.GetAchievementDistributionParameters) (*models.GetAchievementDistribution, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetAchievementDistribution.php"),
raHttp.APIToken(c.Secret),
raHttp.I([]string{strconv.Itoa(params.GameID)}),
Expand Down Expand Up @@ -126,6 +131,7 @@ func (c *Client) GetAchievementDistribution(params models.GetAchievementDistribu
func (c *Client) GetGameRankAndScore(params models.GetGameRankAndScoreParameters) ([]models.GetGameRankAndScore, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetGameRankAndScore.php"),
raHttp.APIToken(c.Secret),
raHttp.G(params.GameID),
Expand Down
4 changes: 2 additions & 2 deletions http/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ func BearerToken(token string) RequestDetail {
}

// UserAgent adds an User-Agent header with the package version
func UserAgent() RequestDetail {
func UserAgent(userAgent string) RequestDetail {
return requestDetailFn(func(r *Request) {
r.Headers["User-Agent"] = "go-retroachievements/v0.0.0"
r.Headers["User-Agent"] = userAgent
})
}

Expand Down
2 changes: 1 addition & 1 deletion http/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestNewRequest(t *testing.T) {
"http://localhost",
raHttp.Path("/api/v1/some_resource"),
raHttp.Method(http.MethodPost),
raHttp.UserAgent(),
raHttp.UserAgent("go-retroachievements/v0.0.0"),
raHttp.APIToken("secret_token"),
raHttp.BearerToken("secret_bearer"),
raHttp.U("myUsername"),
Expand Down
2 changes: 2 additions & 0 deletions leaderboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
func (c *Client) GetGameLeaderboards(params models.GetGameLeaderboardsParameters) (*models.GetGameLeaderboards, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetGameLeaderboards.php"),
raHttp.APIToken(c.Secret),
raHttp.I([]string{strconv.Itoa(params.GameID)}),
Expand All @@ -38,6 +39,7 @@ func (c *Client) GetGameLeaderboards(params models.GetGameLeaderboardsParameters
func (c *Client) GetLeaderboardEntries(params models.GetLeaderboardEntriesParameters) (*models.GetLeaderboardEntries, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetLeaderboardEntries.php"),
raHttp.APIToken(c.Secret),
raHttp.I([]string{strconv.Itoa(params.LeaderboardID)}),
Expand Down
2 changes: 2 additions & 0 deletions system.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
func (c *Client) GetConsoleIDs(params models.GetConsoleIDsParameters) ([]models.GetConsoleIDs, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetConsoleIDs.php"),
raHttp.APIToken(c.Secret),
}
Expand Down Expand Up @@ -45,6 +46,7 @@ func (c *Client) GetConsoleIDs(params models.GetConsoleIDsParameters) ([]models.
func (c *Client) GetGameList(params models.GetGameListParameters) ([]models.GetGameList, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetGameList.php"),
raHttp.APIToken(c.Secret),
raHttp.I([]string{strconv.Itoa(params.SystemID)}),
Expand Down
6 changes: 6 additions & 0 deletions ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
func (c *Client) GetTicketByID(params models.GetTicketByIDParameters) (*models.GetTicketByID, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetTicketData.php"),
raHttp.APIToken(c.Secret),
raHttp.I([]string{
Expand All @@ -33,6 +34,7 @@ func (c *Client) GetTicketByID(params models.GetTicketByIDParameters) (*models.G
func (c *Client) GetMostTicketedGames(params models.GetMostTicketedGamesParameters) (*models.GetMostTicketedGames, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetTicketData.php"),
raHttp.APIToken(c.Secret),
raHttp.F(1),
Expand All @@ -58,6 +60,7 @@ func (c *Client) GetMostTicketedGames(params models.GetMostTicketedGamesParamete
func (c *Client) GetMostRecentTickets(params models.GetMostRecentTicketsParameters) (*models.GetMostRecentTickets, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetTicketData.php"),
raHttp.APIToken(c.Secret),
}
Expand All @@ -82,6 +85,7 @@ func (c *Client) GetMostRecentTickets(params models.GetMostRecentTicketsParamete
func (c *Client) GetGameTicketStats(params models.GetGameTicketStatsParameters) (*models.GetGameTicketStats, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetTicketData.php"),
raHttp.APIToken(c.Secret),
raHttp.G(params.GameID),
Expand All @@ -107,6 +111,7 @@ func (c *Client) GetGameTicketStats(params models.GetGameTicketStatsParameters)
func (c *Client) GetDeveloperTicketStats(params models.GetDeveloperTicketStatsParameters) (*models.GetDeveloperTicketStats, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetTicketData.php"),
raHttp.APIToken(c.Secret),
raHttp.U(params.Username),
Expand All @@ -125,6 +130,7 @@ func (c *Client) GetDeveloperTicketStats(params models.GetDeveloperTicketStatsPa
func (c *Client) GetAchievementTicketStats(params models.GetAchievementTicketStatsParameters) (*models.GetAchievementTicketStats, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetTicketData.php"),
raHttp.APIToken(c.Secret),
raHttp.A(params.AchievementID),
Expand Down
15 changes: 15 additions & 0 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
func (c *Client) GetUserProfile(params models.GetUserProfileParameters) (*models.GetUserProfile, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserProfile.php"),
raHttp.APIToken(c.Secret),
raHttp.U(params.Username),
Expand All @@ -32,6 +33,7 @@ func (c *Client) GetUserProfile(params models.GetUserProfileParameters) (*models
func (c *Client) GetUserRecentAchievements(params models.GetUserRecentAchievementsParameters) ([]models.GetUserRecentAchievements, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserRecentAchievements.php"),
raHttp.APIToken(c.Secret),
raHttp.U(params.Username),
Expand All @@ -54,6 +56,7 @@ func (c *Client) GetUserRecentAchievements(params models.GetUserRecentAchievemen
func (c *Client) GetAchievementsEarnedBetween(params models.GetAchievementsEarnedBetweenParameters) ([]models.GetAchievementsEarnedBetween, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetAchievementsEarnedBetween.php"),
raHttp.APIToken(c.Secret),
raHttp.U(params.Username),
Expand All @@ -74,6 +77,7 @@ func (c *Client) GetAchievementsEarnedBetween(params models.GetAchievementsEarne
func (c *Client) GetAchievementsEarnedOnDay(params models.GetAchievementsEarnedOnDayParameters) ([]models.GetAchievementsEarnedOnDay, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetAchievementsEarnedOnDay.php"),
raHttp.APIToken(c.Secret),
raHttp.U(params.Username),
Expand All @@ -93,6 +97,7 @@ func (c *Client) GetAchievementsEarnedOnDay(params models.GetAchievementsEarnedO
func (c *Client) GetGameInfoAndUserProgress(params models.GetGameInfoAndUserProgressParameters) (*models.GetGameInfoAndUserProgress, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetGameInfoAndUserProgress.php"),
raHttp.APIToken(c.Secret),
raHttp.U(params.Username),
Expand Down Expand Up @@ -120,6 +125,7 @@ func (c *Client) GetGameInfoAndUserProgress(params models.GetGameInfoAndUserProg
func (c *Client) GetUserCompletionProgress(params models.GetUserCompletionProgressParameters) (*models.GetUserCompletionProgress, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserCompletionProgress.php"),
raHttp.APIToken(c.Secret),
raHttp.U(params.Username),
Expand All @@ -138,6 +144,7 @@ func (c *Client) GetUserCompletionProgress(params models.GetUserCompletionProgre
func (c *Client) GetUserAwards(params models.GetUserAwardsParameters) (*models.GetUserAwards, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserAwards.php"),
raHttp.APIToken(c.Secret),
raHttp.U(params.Username),
Expand All @@ -156,6 +163,7 @@ func (c *Client) GetUserAwards(params models.GetUserAwardsParameters) (*models.G
func (c *Client) GetUserClaims(params models.GetUserClaimsParameters) ([]models.GetUserClaims, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserClaims.php"),
raHttp.APIToken(c.Secret),
raHttp.U(params.Username),
Expand All @@ -174,6 +182,7 @@ func (c *Client) GetUserClaims(params models.GetUserClaimsParameters) ([]models.
func (c *Client) GetUserGameRankAndScore(params models.GetUserGameRankAndScoreParameters) ([]models.GetUserGameRankAndScore, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserGameRankAndScore.php"),
raHttp.APIToken(c.Secret),
raHttp.U(params.Username),
Expand All @@ -193,6 +202,7 @@ func (c *Client) GetUserGameRankAndScore(params models.GetUserGameRankAndScorePa
func (c *Client) GetUserPoints(params models.GetUserPointsParameters) (*models.GetUserPoints, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserPoints.php"),
raHttp.APIToken(c.Secret),
raHttp.U(params.Username),
Expand All @@ -215,6 +225,7 @@ func (c *Client) GetUserProgress(params models.GetUserProgressParameters) (*map[
}
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserProgress.php"),
raHttp.APIToken(c.Secret),
raHttp.U(params.Username),
Expand All @@ -234,6 +245,7 @@ func (c *Client) GetUserProgress(params models.GetUserProgressParameters) (*map[
func (c *Client) GetUserRecentlyPlayedGames(params models.GetUserRecentlyPlayedGamesParameters) ([]models.GetUserRecentlyPlayedGames, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserRecentlyPlayedGames.php"),
raHttp.APIToken(c.Secret),
raHttp.U(params.Username),
Expand All @@ -259,6 +271,7 @@ func (c *Client) GetUserRecentlyPlayedGames(params models.GetUserRecentlyPlayedG
func (c *Client) GetUserSummary(params models.GetUserSummaryParameters) (*models.GetUserSummary, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserSummary.php"),
raHttp.APIToken(c.Secret),
raHttp.U(params.Username),
Expand All @@ -284,6 +297,7 @@ func (c *Client) GetUserSummary(params models.GetUserSummaryParameters) (*models
func (c *Client) GetUserCompletedGames(params models.GetUserCompletedGamesParameters) ([]models.GetUserCompletedGames, error) {
r, err := c.do(
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserCompletedGames.php"),
raHttp.APIToken(c.Secret),
raHttp.U(params.Username),
Expand All @@ -302,6 +316,7 @@ func (c *Client) GetUserCompletedGames(params models.GetUserCompletedGamesParame
func (c *Client) GetUserWantToPlayList(params models.GetUserWantToPlayListParameters) (*models.GetUserWantToPlayList, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetUserWantToPlayList.php"),
raHttp.APIToken(c.Secret),
raHttp.U(params.Username),
Expand Down

0 comments on commit 3a53732

Please sign in to comment.