api

package
v0.0.0-...-8bc6207 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2023 License: MIT Imports: 10 Imported by: 0

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

This section is empty.

Functions

This section is empty.

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
	// PatchReq corresponds to PATCH
	PatchReq
	// DeleteReq corresponds to DELETE
	DeleteReq
)

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

func NewRequest(endpoint string) *Request

NewRequest constructs a new request for the given endpoint.

func NewRequestf

func NewRequestf(format string, params ...interface{}) *Request

NewRequestf constructs a new request for the endpoint constructed by the given format string and parameters.

type Requester

type Requester interface {
	// Do fulfils an API request.
	Do(r *Request) *Response
	DoToken(r *Request, token string) *Response
}

Requester is the type of anything that can handle an API request.

func NewRequester

func NewRequester(url url.URL) Requester

NewRequester creates a new 'live' requester.

type Response

type Response struct {
	// contains filtered or unexported fields
}

Response represents the result of an API request.

func (*Response) Into

func (r *Response) Into(in interface{}) error

Into unmarshals the response r into in.

func (*Response) IsEmpty

func (r *Response) IsEmpty() bool

IsEmpty checks whether the response payload is present, but empty.

func (*Response) JSON

func (r *Response) JSON() (*json.RawMessage, error)

JSON returns r as raw JSON.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL