diff --git a/achievement.go b/achievement.go index ca6458a..ef840f7 100644 --- a/achievement.go +++ b/achievement.go @@ -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), diff --git a/comment.go b/comment.go index c69962b..7c80456 100644 --- a/comment.go +++ b/comment.go @@ -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()), diff --git a/event.go b/event.go index 45283b6..ec9fc3b 100644 --- a/event.go +++ b/event.go @@ -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), ) diff --git a/feed.go b/feed.go index 80f8913..070de4d 100644 --- a/feed.go +++ b/feed.go @@ -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), } @@ -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), ) @@ -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), } @@ -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), ) diff --git a/game.go b/game.go index 8bec116..ec34c91 100644 --- a/game.go +++ b/game.go @@ -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)}), @@ -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)}), @@ -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)}), @@ -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)}), @@ -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)}), @@ -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), diff --git a/http/request.go b/http/request.go index c3679f6..294feb1 100644 --- a/http/request.go +++ b/http/request.go @@ -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 }) } diff --git a/http/request_test.go b/http/request_test.go index fc2d417..6cd8f3c 100644 --- a/http/request_test.go +++ b/http/request_test.go @@ -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"), diff --git a/leaderboards.go b/leaderboards.go index c012db0..028867f 100644 --- a/leaderboards.go +++ b/leaderboards.go @@ -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)}), @@ -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)}), diff --git a/system.go b/system.go index 4db2941..6f8edc3 100644 --- a/system.go +++ b/system.go @@ -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), } @@ -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)}), diff --git a/ticket.go b/ticket.go index 10b5c5e..450519e 100644 --- a/ticket.go +++ b/ticket.go @@ -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{ @@ -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), @@ -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), } @@ -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), @@ -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), @@ -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), diff --git a/user.go b/user.go index 6b7a296..75c51f3 100644 --- a/user.go +++ b/user.go @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -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),