-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTwist.go
47 lines (35 loc) · 1.23 KB
/
Twist.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package twist
import (
"errors"
"net/http"
"github.com/aerogo/http/client"
)
var endpointEpisodes = "https://twist.moe/feed/episodes"
var endpointAnime = "https://twist.moe/feed/anime"
// GetFeed queries a twist.moe feed by the twist.moe internal ID.
func GetFeed(twistID string) (*Feed, error) {
var anime *Feed
resp, err := client.Get(endpointEpisodes + "?format=json&animeId=" + twistID).EndStruct(&anime)
if resp.StatusCode() == http.StatusNotFound {
return nil, errors.New("Doesn't exist on twist.moe")
}
return anime, err
}
// GetFeedByKitsuID queries a twist.moe feed by the Kitsu ID.
func GetFeedByKitsuID(kitsuID string) (*Feed, error) {
var anime *Feed
resp, err := client.Get(endpointEpisodes + "?format=json&kitsuId=" + kitsuID).EndStruct(&anime)
if resp.StatusCode() == http.StatusNotFound {
return nil, errors.New("Doesn't exist on twist.moe")
}
return anime, err
}
// GetAnimeIndex queries information about all anime on twist.moe.
func GetAnimeIndex() (*AnimeIndex, error) {
var animeList *AnimeIndex
resp, err := client.Get(endpointAnime + "?format=json").EndStruct(&animeList)
if resp.StatusCode() == http.StatusNotFound {
return nil, errors.New("Doesn't exist on twist.moe")
}
return animeList, err
}