Added GetMovie and related structs

This commit is contained in:
2025-02-23 15:20:45 +11:00
parent d8d2307859
commit 725038009a
3 changed files with 94 additions and 0 deletions

35
tmdb/movie.go Normal file
View File

@@ -0,0 +1,35 @@
package tmdb
import (
"encoding/json"
"fmt"
"io"
"net/http"
"github.com/pkg/errors"
)
func GetMovie(id int32, token string) (*Movie, error) {
url := fmt.Sprintf("https://api.themoviedb.org/3/movie/%v?language=en-US", id)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, errors.Wrap(err, "http.NewRequest")
}
req.Header.Add("accept", "application/json")
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
res, err := http.DefaultClient.Do(req)
if err != nil {
return nil, errors.Wrap(err, "http.DefaultClient.Do")
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, errors.Wrap(err, "io.ReadAll")
}
movie := Movie{}
json.Unmarshal(body, &movie)
return &movie, nil
}