Files
fnx_web/pixelapi/list.go

56 lines
1.3 KiB
Go
Raw Normal View History

2017-12-12 23:33:41 +01:00
package pixelapi
import (
"encoding/json"
"fornaxian.com/pixeldrain-web/conf"
2018-01-30 10:29:45 +01:00
)
// API error constants
const (
ListNotFoundError = "list_not_found"
2017-12-12 23:33:41 +01:00
)
// List information object from the pixeldrain API
type List struct {
2018-01-30 10:29:45 +01:00
Error *ErrorResponse
Success bool `json:"success"`
2017-12-12 23:33:41 +01:00
ID string `json:"id"`
Title string `json:"title"`
DateCreated int64 `json:"date_created"`
Files []ListFile
}
// ListFile information object from the pixeldrain API
type ListFile struct {
ID string `json:"id"`
DetailHREF string `json:"detail_href"`
FileName string `json:"file_name"`
Description string `json:"description"`
DateCreated int64 `json:"date_created"`
DateLastView int64 `json:"date_last_view"`
ListDescription string `json:"list_description"`
}
2018-01-30 10:29:45 +01:00
// GetList get a List from the pixeldrain API. Errors will be available through
// List.Error. Standard error checks apply.
2017-12-12 23:33:41 +01:00
func GetList(id string) *List {
2018-01-30 10:29:45 +01:00
var list = &List{}
2018-01-07 21:42:19 +01:00
body, err := getString(conf.ApiUrlInternal() + "/list/" + id)
2017-12-12 23:33:41 +01:00
if err != nil {
2018-01-30 10:29:45 +01:00
list.Error = errorResponseFromError(err)
return list
2017-12-12 23:33:41 +01:00
}
2018-01-30 10:29:45 +01:00
err = json.Unmarshal([]byte(body), list)
2017-12-12 23:33:41 +01:00
if err != nil {
2018-01-30 10:29:45 +01:00
list.Error = errorResponseFromError(err)
return list
}
if !list.Success {
list.Error = errorResponseFromJSON(body)
2017-12-12 23:33:41 +01:00
}
2018-01-30 10:29:45 +01:00
return list
2017-12-12 23:33:41 +01:00
}