Created
July 5, 2020 20:57
-
-
Save florentsorel/f3e83a73ca369e8978cc177763a02b30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package betaseries | |
import ( | |
"errors" | |
"fmt" | |
) | |
type ShowService service | |
type ShowResponse struct { | |
Show Show `json:"show"` | |
Errors Errors `json:"errors"` | |
} | |
type ShowsResponse struct { | |
Shows []Show `json:"shows"` | |
Errors Errors `json:"errors"` | |
} | |
type SeasonsDetails struct { | |
Number int `json:"number"` | |
Episodes int `json:"episodes"` | |
} | |
type Showrunner struct { | |
ID string `json:"id"` | |
Name string `json:"name"` | |
Picture string `json:"picture"` | |
} | |
type Genres struct { | |
Adventure string `json:"Adventure"` | |
Drama string `json:"Drama"` | |
Fantasy string `json:"Fantasy"` | |
} | |
type Notes struct { | |
Total int `json:"total"` | |
Mean float64 `json:"mean"` | |
User int `json:"user"` | |
} | |
type Images struct { | |
Show string `json:"show"` | |
Banner string `json:"banner"` | |
Box string `json:"box"` | |
Poster string `json:"poster"` | |
} | |
type SocialLinks struct { | |
Type string `json:"type"` | |
ExternalID string `json:"external_id"` | |
} | |
type Next struct { | |
ID interface{} `json:"id"` | |
Code string `json:"code"` | |
Date interface{} `json:"date"` | |
Title interface{} `json:"title"` | |
Image interface{} `json:"image"` | |
} | |
type User struct { | |
Archived bool `json:"archived"` | |
Favorited bool `json:"favorited"` | |
Remaining int `json:"remaining"` | |
Status int `json:"status"` | |
Last string `json:"last"` | |
Tags interface{} `json:"tags"` | |
Next Next `json:"next"` | |
FriendsWatching []interface{} `json:"friends_watching"` | |
} | |
type Available struct { | |
Last int `json:"last"` | |
First int `json:"first"` | |
} | |
type Svod struct { | |
ID string `json:"id"` | |
LinkURL string `json:"link_url"` | |
Name string `json:"name"` | |
Available Available `json:"available"` | |
Logo string `json:"logo"` | |
} | |
type Platforms struct { | |
Svod Svod `json:"svod"` | |
} | |
type Show struct { | |
ID int `json:"id"` | |
ThetvdbID int `json:"thetvdb_id"` | |
ImdbID string `json:"imdb_id"` | |
Title string `json:"title"` | |
OriginalTitle string `json:"original_title"` | |
Description string `json:"description"` | |
Seasons string `json:"seasons"` | |
SeasonsDetails []SeasonsDetails `json:"seasons_details"` | |
Episodes string `json:"episodes"` | |
Followers string `json:"followers"` | |
Comments string `json:"comments"` | |
Similars string `json:"similars"` | |
Characters string `json:"characters"` | |
Creation string `json:"creation"` | |
Showrunner Showrunner `json:"showrunner"` | |
Genres Genres `json:"genres"` | |
Length string `json:"length"` | |
Network string `json:"network"` | |
Rating string `json:"rating"` | |
Status string `json:"status"` | |
Language string `json:"language"` | |
Notes Notes `json:"notes"` | |
InAccount bool `json:"in_account"` | |
Images Images `json:"images"` | |
Aliases map[int]string `json:"aliases"` | |
SocialLinks []SocialLinks `json:"social_links"` | |
User User `json:"user"` | |
NextTrailer string `json:"next_trailer"` | |
ResourceURL string `json:"resource_url"` | |
Platforms Platforms `json:"platforms"` | |
} | |
func (s *ShowService) Discover() ([]Show, error) { | |
url := fmt.Sprintf("shows/discover") | |
req, err := s.client.NewRequest("GET", url, nil) | |
if err != nil { | |
return nil, err | |
} | |
var shows *ShowsResponse | |
_, err = s.client.Do(req, &shows) | |
if err != nil { | |
return nil, err | |
} | |
if len(shows.Errors) > 0 { | |
var msg string | |
for _, e := range shows.Errors { | |
msg += fmt.Sprintf("\tCode: %d\n\tMessage: %s\n", e.Code, e.Message) | |
} | |
return nil, errors.New("API errors:\n" + msg) | |
} | |
return shows.Shows, nil | |
} | |
func (s *ShowService) Display(id int) (*Show, error) { | |
url := fmt.Sprintf("shows/display?id=%d", id) | |
req, err := s.client.NewRequest("GET", url, nil) | |
if err != nil { | |
return nil, err | |
} | |
var show *ShowResponse | |
_, err = s.client.Do(req, &show) | |
if err != nil { | |
return nil, err | |
} | |
if len(show.Errors) > 0 { | |
var msg string | |
for _, e := range show.Errors { | |
msg += fmt.Sprintf("\tCode: %d\n\tMessage: %s\n", e.Code, e.Message) | |
} | |
return nil, errors.New("API errors:\n" + msg) | |
} | |
return &show.Show, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment