mirror of
https://github.com/trafficlunar/api.git
synced 2026-06-27 22:24:08 +00:00
feat: roblox likes route
This commit is contained in:
parent
fea1c9ced9
commit
a2a99a8dcc
7 changed files with 81 additions and 1 deletions
36
internal/service/roblox.go
Normal file
36
internal/service/roblox.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"api/internal/model"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func GetRobloxGrowARobloxianLikesCount() int {
|
||||
url := fmt.Sprintf("https://games.roblox.com/v1/games/votes?universeIds=%s", os.Getenv("GROWAROBLOXIAN_UNIVERSE_ID"))
|
||||
res, err := http.Get(url)
|
||||
if err != nil {
|
||||
slog.Error("Error requesting Roblox votes API", slog.Any("error", err))
|
||||
return 0
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
slog.Error("Error reading body", slog.Any("error", err))
|
||||
return 0
|
||||
}
|
||||
|
||||
var apiData model.RobloxGameVotesAPI
|
||||
|
||||
err = json.Unmarshal(body, &apiData)
|
||||
if err != nil {
|
||||
slog.Error("Error unmarshalling JSON", slog.Any("error", err))
|
||||
return 0
|
||||
}
|
||||
|
||||
return apiData.Data[0].Upvotes
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue