diff --git a/README.md b/README.md index 0a242b6..f53092e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,32 @@ #

![ra_gopher](assets/ra_gopher_small.png "Retro Achievements Gopher")
go-retroachievements

-## https://api-docs.retroachievements.org/ +

+ A Golang library that lets you get achievement, user, and game data from RetroAchievements. +

-[![pipeline](https://github.com/joshraphael/go-retroachievements/actions/workflows/ci.yaml/badge.svg)](https://github.com/joshraphael/go-retroachievements/actions) \ No newline at end of file +

+ Documentation: Get Started +

+ +
+
+ +[![pipeline](https://github.com/joshraphael/go-retroachievements/actions/workflows/ci.yaml/badge.svg)](https://github.com/joshraphael/go-retroachievements/actions) + +## Installation +Use go get to install the latest version of the library. +```sh +go get github.com/joshraphael/go-retroachievements@latest +``` +Then include it in your application: +```go +import "github.com/joshraphael/go-retroachievements" +``` + +## Usage + +Construct a new Retro Achievement client using your personal web API key + +```go +raClient := client.DefaultClient("") +``` \ No newline at end of file diff --git a/client/client.go b/client/client.go index d816b89..ca614c1 100644 --- a/client/client.go +++ b/client/client.go @@ -9,12 +9,22 @@ import ( raHttp "github.com/joshraphael/go-retroachievements/http" ) +const ( + RetroAchievementHost = "https://retroachievements.org" +) + type Client struct { host string secret string HttpClient *http.Client } +// DefaultClient makes a new client using the default retroachievement host +func DefaultClient(secret string) *Client { + return New(RetroAchievementHost, secret) +} + +// New creates a new client for a given hostname func New(host string, secret string) *Client { return &Client{ host: host, diff --git a/examples/game/getgame/getgame.go b/examples/game/getgame/getgame.go index a77c33c..d376dc1 100644 --- a/examples/game/getgame/getgame.go +++ b/examples/game/getgame/getgame.go @@ -12,10 +12,9 @@ import ( Test script for getting user profile. Add RA_API_KEY to your env and use `go run getgame.go` */ func main() { - host := "https://retroachievements.org" secret := os.Getenv("RA_API_KEY") - raClient := client.New(host, secret) + raClient := client.DefaultClient(secret) resp, err := raClient.GetGame(293) if err != nil { diff --git a/examples/user/getachievementsearnedbetween/getachievementsearnedbetween.go b/examples/user/getachievementsearnedbetween/getachievementsearnedbetween.go index 9eef608..f2baaa7 100644 --- a/examples/user/getachievementsearnedbetween/getachievementsearnedbetween.go +++ b/examples/user/getachievementsearnedbetween/getachievementsearnedbetween.go @@ -13,10 +13,9 @@ import ( Test script for getting user profile. Add RA_API_KEY to your env and use `go run getachievementsearnedbetween.go` */ func main() { - host := "https://retroachievements.org" secret := os.Getenv("RA_API_KEY") - raClient := client.New(host, secret) + raClient := client.DefaultClient(secret) now, err := time.Parse(time.DateTime, "2024-03-02 17:27:03") if err != nil { diff --git a/examples/user/getachievementsearnedonday/getachievementsearnedonday.go b/examples/user/getachievementsearnedonday/getachievementsearnedonday.go index c1cf1a7..911ad66 100644 --- a/examples/user/getachievementsearnedonday/getachievementsearnedonday.go +++ b/examples/user/getachievementsearnedonday/getachievementsearnedonday.go @@ -13,10 +13,9 @@ import ( Test script for getting user profile. Add RA_API_KEY to your env and use `go run getachievementsearnedonday.go` */ func main() { - host := "https://retroachievements.org" secret := os.Getenv("RA_API_KEY") - raClient := client.New(host, secret) + raClient := client.DefaultClient(secret) now, err := time.Parse(time.DateTime, "2024-03-02 17:27:03") if err != nil { diff --git a/examples/user/getuserprofile/getuserprofile.go b/examples/user/getuserprofile/getuserprofile.go index 71301ff..78106eb 100644 --- a/examples/user/getuserprofile/getuserprofile.go +++ b/examples/user/getuserprofile/getuserprofile.go @@ -12,10 +12,9 @@ import ( Test script for getting user profile. Add RA_API_KEY to your env and use `go run getuserprofile.go` */ func main() { - host := "https://retroachievements.org" secret := os.Getenv("RA_API_KEY") - raClient := client.New(host, secret) + raClient := client.DefaultClient(secret) resp, err := raClient.GetUserProfile("jamiras") if err != nil { diff --git a/examples/user/getuserrecentachievements/getuserrecentachievements.go b/examples/user/getuserrecentachievements/getuserrecentachievements.go index d7ae0b4..c84deb4 100644 --- a/examples/user/getuserrecentachievements/getuserrecentachievements.go +++ b/examples/user/getuserrecentachievements/getuserrecentachievements.go @@ -12,10 +12,9 @@ import ( Test script for getting user profile. Add RA_API_KEY to your env and use `go run getuserrecentachievements.go` */ func main() { - host := "https://retroachievements.org" secret := os.Getenv("RA_API_KEY") - raClient := client.New(host, secret) + raClient := client.DefaultClient(secret) resp, err := raClient.GetUserRecentAchievements("jamiras", 1000) if err != nil {