api

package
v0.0.0-...-153d4bb Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2021 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package api contains types and methods for interacting with a shorturl server.

Index

Constants

View Source
const (
	// ErrRateLimit ...
	ErrRateLimit = errors.Sentinel("rate limit would exceed context deadline")
	// ErrUnauthorized ...
	ErrUnauthorized = errors.Sentinel("error authenticating, double check your token")
	// ErrNotFound ...
	ErrNotFound = errors.Sentinel("not found")
)

Variables

This section is empty.

Functions

func Expires

func Expires(toAdd time.Duration) *time.Time

Expires returns a *time.Time

Types

type Client

type Client struct {
	Client *http.Client

	// The user agent used by requests.
	UserAgent string

	// The default timeout for requests.
	Timeout time.Duration

	// Debug is called for debug logs. Default no-op.
	Debug func(tmpl string, v ...interface{})
	// contains filtered or unexported fields
}

Client is a shorturl API client.

func NewClient

func NewClient(baseURL, token string, requestsPerMinute int) *Client

NewClient returns a new Client.

func (s *Client) CreateLink(url string) (link *db.URL, err error)

CreateLink creates a short URL to the given link.

func (*Client) CreateLinkComplex

func (s *Client) CreateLinkComplex(data CreateLinkData) (link *db.URL, err error)

CreateLinkComplex creates a short URL to the given link.

func (*Client) EndpointInfo

func (s *Client) EndpointInfo(link string) string

EndpointInfo returns the /{short}/info.json endpoint.

func (s *Client) EndpointLink(link string) string

EndpointLink returns the /link endpoint with optional link ID. Used in Link(), CreateLink(), CreateLinkComplex(), DeleteLink().

func (s *Client) EndpointLinks(username string) string

EndpointLinks returns the /links endpoint with optional username. Used in Links(), UserLinks(), MyLinks().

func (s *Client) Link(id uuid.UUID) (link *db.URL, err error)

Link returns a link by ID.

func (*Client) LinkInfo

func (s *Client) LinkInfo(short string) (link *db.URL, err error)

LinkInfo returns a link by short URL.

func (s *Client) Links() (links []db.URL, err error)

Links returns all links.

func (s *Client) MyLinks() (links []db.URL, err error)

MyLinks returns the links created by the user whose token is being used.

func (*Client) Request

func (s *Client) Request(method, url string, data, out interface{}) (err error)

Request makes a request to `url` with `method`.

func (s *Client) UserLinks(username string) (links []db.URL, err error)

UserLinks returns this user's links.

type CreateLinkData

type CreateLinkData struct {
	// The short name for this link. Randomly generated if empty.
	Name string `json:"name,omitempty"`
	// The URL this link points to.
	URL string `json:"url"`
	// The expiry for this link. Nil if it doesn't expire.
	Expires *time.Time `json:"expires,omitempty"`
}

CreateLinkData is the data passed to CreateLinkComplex.

Jump to

Keyboard shortcuts

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