Documentation ¶
Overview ¶
Package api exposes a low-level interface to the MyRadio API.
It exposes the Requester interface for types that represent connections to the API, methods for constructing Requesters, and functions and methods for using Requesters to make requests.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoMYRADIOKEY is the error thrown when MYRADIOKEY is not present in // the environment. ErrNoMYRADIOKEY = errors.New("MYRADIOKEY not in environment") // ErrNoKeyFile is the error thrown when there // is no myradio.key file. ErrNoKeyFile = errors.New("couldn't find any API key file") )
Functions ¶
func GetAPIKey ¶
GetAPIKey tries to get an API key from all possible sources. This tries the following paths for a file containing one line (the API key):
- Whichever path is set in the environment variable `MYRADIOKEYFILE`;
- `.myradio.key`, in the current directory;
- `.myradio.key`, in the user's home directory;
- `/etc/myradio.key`;
- `/usr/local/etc/myradio.key`.`
Types ¶
type HTTPMethod ¶
type HTTPMethod int
HTTPMethod guards against incorrect methods being specified through strings
const ( //GetReq corresponds to GET GetReq HTTPMethod = iota //PostReq corresponds to POST PostReq //PutReq corresponds to PUT PutReq )
func (HTTPMethod) String ¶
func (m HTTPMethod) String() (string, error)
String converts a HTTPMethod object into a usable request method string
type Request ¶
type Request struct { // The endpoint, as a suffix of the API root URL. Endpoint string // The set of mixins to use. Mixins []string // The map of parameters to use. Params map[string][]string // The type of request (i.e. GET/POST etc.) ReqType HTTPMethod // The body of the request Body bytes.Buffer }
Request represents an API request being built.
func NewRequest ¶
NewRequest constructs a new request for the given endpoint.
func NewRequestf ¶
NewRequestf constructs a new request for the endpoint constructed by the given format string and parameters.
type Requester ¶
Requester is the type of anything that can handle an API request.
func MockRequester ¶
func MockRequester(message *json.RawMessage) Requester
MockRequester creates a new mocked requester.