aboutsummaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2019-04-01 10:05:03 -0700
committerChristine Dodrill <me@christine.website>2019-04-01 10:05:28 -0700
commitf06f021f402270951f849dde7bee3f3340b8a1d5 (patch)
treebaee337aab524f162b349d254d21c2d8f2716d44 /web
parentba91a17859267201b1d1f0e71da465b1464d940f (diff)
downloadx-f06f021f402270951f849dde7bee3f3340b8a1d5.tar.xz
x-f06f021f402270951f849dde7bee3f3340b8a1d5.zip
reorg
Diffstat (limited to 'web')
-rw-r--r--web/ponyapi/doc.go5
-rw-r--r--web/ponyapi/episode.go18
-rw-r--r--web/ponyapi/get.go114
3 files changed, 0 insertions, 137 deletions
diff --git a/web/ponyapi/doc.go b/web/ponyapi/doc.go
deleted file mode 100644
index 4ee2abf..0000000
--- a/web/ponyapi/doc.go
+++ /dev/null
@@ -1,5 +0,0 @@
-/*
-Package ponyapi provides glue for applications written in Go
-that want to use PonyAPI for getting information.
-*/
-package ponyapi
diff --git a/web/ponyapi/episode.go b/web/ponyapi/episode.go
deleted file mode 100644
index a3e9443..0000000
--- a/web/ponyapi/episode.go
+++ /dev/null
@@ -1,18 +0,0 @@
-package ponyapi
-
-// Episode is an episode of My Little Pony: Friendship is Magic.
-type Episode struct {
- AirDate int `json:"air_date"`
- Episode int `json:"episode"`
- IsMovie bool `json:"is_movie"`
- Name string `json:"name"`
- Season int `json:"season"`
-}
-
-type episodeWrapper struct {
- Episode *Episode `json:"episode"`
-}
-
-type episodes struct {
- Episodes []Episode `json:"episodes"`
-}
diff --git a/web/ponyapi/get.go b/web/ponyapi/get.go
deleted file mode 100644
index 6211dd6..0000000
--- a/web/ponyapi/get.go
+++ /dev/null
@@ -1,114 +0,0 @@
-package ponyapi
-
-import (
- "encoding/json"
- "fmt"
- "io/ioutil"
- "net/http"
- "net/url"
-)
-
-const (
- endpoint = "https://ponyapi.apps.xeserv.us/"
-)
-
-func getJSON(fragment string) *http.Request {
- req, err := http.NewRequest(http.MethodGet, endpoint+fragment, nil)
- if err != nil {
- panic(err)
- }
- req.Header.Set("Accept", "application/json")
- return req
-}
-
-func readData(resp *http.Response) ([]byte, error) {
- if resp.StatusCode%100 != 2 {
- return nil, fmt.Errorf("status code: %d", resp.StatusCode)
- }
-
- data, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- return nil, err
- }
- defer resp.Body.Close()
- return data, nil
-}
-
-// ReadEpisode reads information about an invididual episode from an HTTP response.
-func ReadEpisode(resp *http.Response) (*Episode, error) {
- if resp.StatusCode != 200 {
- return nil, fmt.Errorf("status code: %d", resp.StatusCode)
- }
-
- var ewr episodeWrapper
- err := json.NewDecoder(resp.Body).Decode(&ewr)
- if err != nil {
- return nil, err
- }
- defer resp.Body.Close()
-
- return ewr.Episode, nil
-}
-
-// ReadEpisodes reads a slice of episode information out of a HTTP response.
-func ReadEpisodes(resp *http.Response) ([]Episode, error) {
- if resp.StatusCode != 200 {
- return nil, fmt.Errorf("status code: %d", resp.StatusCode)
- }
-
- var eswr episodes
- err := json.NewDecoder(resp.Body).Decode(&eswr)
- if err != nil {
- return nil, err
- }
- defer resp.Body.Close()
-
- return eswr.Episodes, nil
-}
-
-// Newest returns information on the newest episode or an error.
-func Newest() *http.Request {
- return getJSON("/newest")
-}
-
-// LastAired returns information on the most recently aried episode
-// or an error.
-func LastAired() *http.Request {
- return getJSON("/last_aired")
-}
-
-// Random returns information on a random episode.
-func Random() *http.Request {
- return getJSON("/random")
-}
-
-// GetEpisode gets information about season x episode y or an error.
-func GetEpisode(season, episode int) *http.Request {
- return getJSON(fmt.Sprintf("/season/%d/episode/%d", season, episode))
-}
-
-// AllEpisodes gets all information on all episodes or returns an error.
-func AllEpisodes() *http.Request {
- return getJSON("/all")
-}
-
-// GetSeason returns all information on season x or returns an error.
-func GetSeason(season int) *http.Request {
- return getJSON(fmt.Sprintf("/season/%d", season))
-}
-
-// Search takes the give search terms and uses that to search the
-// list of episodes.
-func Search(query string) *http.Request {
- path, err := url.Parse("/search")
- if err != nil {
- panic(err)
- }
-
- q := path.Query()
- q.Set("q", query)
-
- path.RawQuery = q.Encode()
-
- return getJSON(path.String())
-}