feat: roblox likes route
This commit is contained in:
parent
fea1c9ced9
commit
a2a99a8dcc
7 changed files with 81 additions and 1 deletions
|
|
@ -14,4 +14,7 @@ GITHUB_PROJECTS="trafficlunar/options-profiles,trafficlunar/blockmatic"
|
||||||
GITHUB_TOKEN="API_KEY_GOES_HERE"
|
GITHUB_TOKEN="API_KEY_GOES_HERE"
|
||||||
|
|
||||||
# The password for the computer WebSocket
|
# The password for the computer WebSocket
|
||||||
WEBSOCKET_PASSWORD="PASSWORD_GOES_HERE"
|
WEBSOCKET_PASSWORD="PASSWORD_GOES_HERE"
|
||||||
|
|
||||||
|
# Roblox
|
||||||
|
GROWAROBLOXIAN_UNIVERSE_ID=7778892933
|
||||||
12
internal/handler/roblox.go
Normal file
12
internal/handler/roblox.go
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"api/internal/worker"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func HandleGetGrowARobloxianLikesCount(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
json.NewEncoder(w).Encode(worker.GrowARobloxianLikes)
|
||||||
|
}
|
||||||
9
internal/model/roblox.go
Normal file
9
internal/model/roblox.go
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
package model
|
||||||
|
|
||||||
|
type RobloxGameVotesAPI struct {
|
||||||
|
Data []struct {
|
||||||
|
Id int `json:"id"`
|
||||||
|
Upvotes int `json:"upVotes"`
|
||||||
|
Downvotes int `json:"downVotes"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
|
@ -57,6 +57,7 @@ func NewRouter() {
|
||||||
r.Get("/projects", handler.HandleGetProjects)
|
r.Get("/projects", handler.HandleGetProjects)
|
||||||
r.Get("/computer", handler.HandleComputerGraphData)
|
r.Get("/computer", handler.HandleComputerGraphData)
|
||||||
r.Get("/computer/ws", handler.HandleComputerWebSocket)
|
r.Get("/computer/ws", handler.HandleComputerWebSocket)
|
||||||
|
r.Get("/roblox/grow-a-robloxian/likes", handler.HandleGetGrowARobloxianLikesCount)
|
||||||
|
|
||||||
port := os.Getenv("PORT")
|
port := os.Getenv("PORT")
|
||||||
if len(port) == 0 {
|
if len(port) == 0 {
|
||||||
|
|
|
||||||
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
|
||||||
|
}
|
||||||
18
internal/worker/roblox.go
Normal file
18
internal/worker/roblox.go
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
package worker
|
||||||
|
|
||||||
|
import (
|
||||||
|
"api/internal/service"
|
||||||
|
"log/slog"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var GrowARobloxianLikes int
|
||||||
|
|
||||||
|
func StartRobloxWorker() {
|
||||||
|
slog.Info("Starting Roblox worker...")
|
||||||
|
GrowARobloxianLikes = service.GetRobloxGrowARobloxianLikesCount()
|
||||||
|
|
||||||
|
for range time.Tick(1 * time.Minute) {
|
||||||
|
GrowARobloxianLikes = service.GetRobloxGrowARobloxianLikesCount()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,4 +5,5 @@ func StartWorkers() {
|
||||||
go StartLastFMWorker()
|
go StartLastFMWorker()
|
||||||
go StartGitHubWorker()
|
go StartGitHubWorker()
|
||||||
go StartComputerWorker()
|
go StartComputerWorker()
|
||||||
|
go StartRobloxWorker()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue