Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
joshraphael committed Aug 14, 2024
1 parent 71fb929 commit f8fd5cb
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 12 deletions.
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# <p align="center">![ra_gopher](assets/ra_gopher_small.png "Retro Achievements Gopher")<br>go-retroachievements</p>

## https://api-docs.retroachievements.org/
<p align="center">
<i>A Golang library that lets you get achievement, user, and game data from RetroAchievements.</i>
</p>

[![pipeline](https://github.com/joshraphael/go-retroachievements/actions/workflows/ci.yaml/badge.svg)](https://github.com/joshraphael/go-retroachievements/actions)
<p align="center">
<a href="https://api-docs.retroachievements.org/getting-started.html"><strong>Documentation: Get Started</strong></a>
</p>

<br>
<hr />

[![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("<your web API key>")
```
10 changes: 10 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions examples/game/getgame/getgame.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions examples/user/getuserprofile/getuserprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f8fd5cb

Please sign in to comment.