api

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2024 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

Variables

View Source
var (
	ErrUnsuccessfulReply = Reply{Success: false}
	ErrNotFoundReply     = Reply{Success: false, Error: "resource not found"}
	ErrNotAllowedReply   = Reply{Success: false, Error: "method not allowed"}
	ErrUnparsable        = Reply{Success: false, Error: "could not parse json request"}
)
View Source
var (
	ErrMissingURL         = errors.New("a url is required for shortening")
	ErrCannotParseExpires = errors.New("expires must be a timestamp in the form of YYYY-MM-DD or YYYY-MM-DD HH:MM:SS")
	ErrInvalidExpires     = errors.New("expiration must be valid timestamp in the future")
	ErrParseBearer        = errors.New("could not parse Bearer token from Authorization header")
	ErrNoAuthorization    = errors.New("no authorization header in request")
	ErrInvalidToken       = errors.New("invalid bearer token in Authorization header")
	ErrUnauthenticated    = errors.New("this endpoint requires authentication")
	ErrForwardsBackwards  = errors.New("cannot specify both prev and next page token in page query")
)
View Source
var ClickType = &api.Type{
	Name:         "Click",
	MajorVersion: pkg.VersionMajor,
	MinorVersion: pkg.VersionMinor,
	PatchVersion: pkg.VersionPatch,
}
View Source
var DeletedType = &api.Type{
	Name:         "Deleted",
	MajorVersion: pkg.VersionMajor,
	MinorVersion: pkg.VersionMinor,
	PatchVersion: pkg.VersionPatch,
}
View Source
var ShortenedType = &api.Type{
	Name:         "Shortened",
	MajorVersion: pkg.VersionMajor,
	MinorVersion: pkg.VersionMinor,
	PatchVersion: pkg.VersionPatch,
}

Functions

func Prepare added in v1.2.0

func Prepare(conf config.Config)

Types

type Click added in v1.1.0

type Click struct {
	URL       string `json:"url" msgpack:"url"`
	Time      string `json:"time" msgpack:"time"`
	Views     int    `json:"views" msgpack:"views"`
	UserAgent string `json:"user_agent" msgpack:"user_agent"`
	IPAddr    string `json:"ip_address" msgpack:"ip_address"`
}

func Clicked added in v1.1.0

func Clicked(c *gin.Context) *Click

func (*Click) Event added in v1.1.0

func (c *Click) Event() *ensign.Event

func (*Click) LinkID added in v1.1.0

func (m *Click) LinkID() string

func (*Click) MarshalValue added in v1.1.0

func (m *Click) MarshalValue() ([]byte, error)

func (*Click) UnmarshalValue added in v1.1.0

func (m *Click) UnmarshalValue(data []byte) error

type Deleted added in v1.1.0

type Deleted struct {
	LinkID  string `msgpack:"link_id"`
	Expired bool   `msgpack:"expired"`
}

func (*Deleted) Event added in v1.1.0

func (c *Deleted) Event() *ensign.Event

func (*Deleted) MarshalValue added in v1.1.0

func (m *Deleted) MarshalValue() ([]byte, error)

func (*Deleted) UnmarshalValue added in v1.1.0

func (m *Deleted) UnmarshalValue(data []byte) error

type InfoDetail added in v1.1.0

type InfoDetail struct {
	WebData
	Info *ShortURL
}
type LinkList struct {
	WebData
	URLs []*ShortURL
	Page *PageQuery
}

type LoginData added in v1.2.0

type LoginData struct {
	WebData
	GoogleClientID string
	LoginURI       string
}

func GetLoginData added in v1.2.0

func GetLoginData() LoginData

type LoginForm added in v1.1.0

type LoginForm struct {
	Credential string `json:"credential" url:"credential" form:"credential"`
	Next       string `json:"next" url:"next" form:"next"`
}

LoginForm is used for Google to submit an id token back to the server.

type LongURL added in v0.2.0

type LongURL struct {
	URL     string `json:"url" form:"url"`
	Expires string `json:"expires,omitempty" form:"expires"`
}

func (*LongURL) ExpiresAt added in v0.2.0

func (u *LongURL) ExpiresAt() (time.Time, error)

func (*LongURL) Validate added in v0.2.0

func (u *LongURL) Validate() error

type PageQuery

type PageQuery struct {
	PageSize      int    `json:"page_size" url:"page_size,omitempty" form:"page_size"`
	PrevPageToken string `json:"prev_page_token" url:"prev_page_token,omitempty" form:"prev_page_token"`
	NextPageToken string `json:"next_page_token" url:"next_page_token,omitempty" form:"next_page_token"`
}

PageQuery manages paginated list requests.

func (*PageQuery) Validate added in v1.1.0

func (p *PageQuery) Validate() error

type Reply

type Reply struct {
	Success bool   `json:"success"`
	Error   string `json:"error,omitempty"`
}

Reply contains standard fields that are used for generic API responses and errors.

func ErrorResponse

func ErrorResponse(err interface{}) Reply

Construct a new response for an error or simply return unsuccessful.

type Service added in v1.0.0

type Service interface {
	// Unauthenticated endpoints
	Status(context.Context) (*StatusReply, error)

	// URL Management
	// TODO: edit short url with details
	ShortURLList(context.Context, *PageQuery) (*ShortURLList, error)
	ShortenURL(context.Context, *LongURL) (*ShortURL, error)
	ShortURLInfo(context.Context, string) (*ShortURL, error)
	DeleteShortURL(context.Context, string) error

	// Websockets
	Updates(context.Context, string) (<-chan *Click, error)
}

type ShortURL added in v0.2.0

type ShortURL struct {
	URL         string     `json:"url"`
	AltURL      string     `json:"alt_url,omitempty"`
	Target      string     `json:"target,omitempty"`
	Title       string     `json:"title"`
	Description string     `json:"description,omitempty"`
	Visits      uint64     `json:"visits"`
	Expires     *time.Time `json:"expires,omitempty"`
	Created     *time.Time `json:"created,omitempty"`
	Modified    *time.Time `json:"modified,omitempty"`
	CampaignID  uint64     `json:"campaign_id,omitempty"`
	Campaigns   []uint64   `json:"campaigns,omitempty"`
}

TODO: change campaign uint64s to links

func (*ShortURL) DeleteURL added in v1.3.0

func (u *ShortURL) DeleteURL() string

func (*ShortURL) InfoURL added in v1.3.0

func (u *ShortURL) InfoURL() string

func (*ShortURL) WebData added in v1.1.0

func (s *ShortURL) WebData() InfoDetail

type ShortURLList added in v1.1.0

type ShortURLList struct {
	URLs []*ShortURL `json:"urls"`
	Page *PageQuery  `json:"page"`
}

func (*ShortURLList) WebData added in v1.1.0

func (s *ShortURLList) WebData() LinkList

type ShortcrustInfo added in v1.2.0

type ShortcrustInfo struct {
	Links     uint64 `json:"links"`
	Clicks    uint64 `json:"clicks"`
	Campaigns uint64 `json:"campaigns"`
}
func (s *ShortcrustInfo) CampaignsPerLink() float64

func (*ShortcrustInfo) WebData added in v1.2.0

func (s *ShortcrustInfo) WebData() Stats

type Shortened added in v1.1.0

type Shortened struct {
	URL         string     `msgpack:"url"`
	AltURL      string     `msgpack:"alt_url"`
	Title       string     `msgpack:"title"`
	Description string     `msgpack:"description"`
	Expires     *time.Time `msgpack:"expires,omitempty"`
	CampaignID  uint64     `msgpack:"campaign_id,omitempty"`
	Campaigns   []uint64   `msgpack:"campaigns,omitempty"`
}

func (*Shortened) Event added in v1.1.0

func (c *Shortened) Event() *ensign.Event

func (*Shortened) LinkID added in v1.1.0

func (m *Shortened) LinkID() string

func (*Shortened) MarshalValue added in v1.1.0

func (m *Shortened) MarshalValue() ([]byte, error)

func (*Shortened) UnmarshalValue added in v1.1.0

func (m *Shortened) UnmarshalValue(data []byte) error

type Stats added in v1.2.0

type Stats struct {
	WebData
	Info *ShortcrustInfo
}

type StatusReply

type StatusReply struct {
	Status  string `json:"status"`
	Uptime  string `json:"uptime,omitempty"`
	Version string `json:"version,omitempty"`
}

Returned on status requests.

type WebData added in v1.1.0

type WebData struct {
	Version string
}

func GetWebData added in v1.2.0

func GetWebData() WebData

Jump to

Keyboard shortcuts

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