apiv1

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// LabelLanguage ISO-639 two-letter language code. channel.language
	LabelLanguage = "language"
	// LabelExplicit ["true"|"false"] channel.itunes.explicit
	LabelExplicit = "explicit"
	// LabelType ["Episodic"|"Serial"] channel.itunes.type
	LabelType = "type"
	// LabelBlock ["Yes"] channel.itunes.block
	LabelBlock = "block"
	// LabelComplete ["Yes"] channel.itunes.complete
	LabelComplete = "complete"
	// LabelGUID resources GUID
	LabelGUID = "guid"
	// LabelParentGUID guid of the resources parent resource
	LabelParentGUID = "parent_guid"
	// LabelDate used as e.g. publish date of an episode
	LabelDate = "date"
	// LabelSeason defaults to "1"
	LabelSeason = "season"
	// LabelEpisode positive integer 1..
	LabelEpisode = ResourceEpisode

	// ShowTypeEpisodic type of podcast is episodic
	ShowTypeEpisodic = "Episodic"
	// ShowTypeSerial type of podcast is serial
	ShowTypeSerial = "Serial"

	// EpisodeTypeFull type of episode is 'full'
	EpisodeTypeFull = "Full"
	// EpisodeTypeTrailer type of episode is 'trailer'
	EpisodeTypeTrailer = "Trailer"
	// EpisodeTypeBonus type of episode is 'bonus'
	EpisodeTypeBonus = "Bonus"

	// ResourceTypeExternal references an external URL
	ResourceTypeExternal = "external"
	// ResourceTypeLocal references a local resource
	ResourceTypeLocal = "local"
	// ResourceTypeImport references an external resources that will be imported into the CDN
	ResourceTypeImport = "import"

	// ResourceShow is referencing a resource of type "show"
	ResourceShow = "show"
	// ResourceEpisode is referencing a resource of type "episode"
	ResourceEpisode = "episode"
	// ResourceAsset is referencing any media or binary resource e.g. .mp3 or .png
	ResourceAsset = "asset"
	// ResourceALL is a wildcard for any kind of resource
	ResourceALL = "ALL"
)
View Source
const (
	// AssertionWarning indicates a potential issue
	AssertionWarning = 0
	// AssertionError indicates an error in the validation
	AssertionError = 1
)
View Source
const (
	// Version specifies the verion of the API and its structs
	Version = "v1"
)

Variables

View Source
var (
	// ErrNoSuchProduction indicates that the production does not exist
	ErrNoSuchProduction = errors.New("api: production doesn't exist")
	// ErrNoSuchResource indicates that the resource does not exist
	ErrNoSuchResource = errors.New("api: resource doesn't exist")
	// ErrNoSuchAsset indicates that the asset does not exist
	ErrNoSuchAsset = errors.New("api: asset doesn't exist")
	// ErrBuildFailed indicates that the feed build failed
	ErrBuildFailed = errors.New("api: build failed")
	// ErrValidationFailed indicates that a resource validation failed
	ErrValidationFailed = errors.New("api: validation failed")
)

Functions

func DefaultEpisodeMetadata

func DefaultEpisodeMetadata(guid, parent string) map[string]string

DefaultEpisodeMetadata creates a default set of labels etc for a Episode resource

guid:		<unique id> 'item.guid'
date:		<publish date> REQUIRED 'item.pubDate'
season: 	<season number> OPTIONAL 'item.itunes.season'
episode:	<episode number> REQUIRED 'item.itunes.episode'
explicit:	True | False REQUIRED 'channel.itunes.explicit'
type:		Full | Trailer | Bonus REQUIRED 'item.itunes.episodeType'
block:		Yes OPTIONAL 'item.itunes.block' Anything else than 'Yes' has no effect

func DefaultShowMetadata

func DefaultShowMetadata(guid string) map[string]string

DefaultShowMetadata creates a default set of labels etc for a Show resource

language:	<ISO639 two-letter-code> REQUIRED 'channel.language'
explicit:	True | False REQUIRED 'channel.itunes.explicit'
type:		Episodic | Serial REQUIRED 'channel. itunes.type'
block:		Yes OPTIONAL 'channel.itunes.block' Anything else than 'Yes' has no effect
complete:	Yes OPTIONAL 'channel.itunes.complete' Anything else than 'Yes' has no effect

func LoadResource

func LoadResource(data []byte) (interface{}, string, string, error)

LoadResource takes a byte array and determines its kind before unmarshalling it into its struct form

func ValidResourceName added in v0.9.4

func ValidResourceName(name string) bool

ValidResourceName verifies that a name is valid for a resource. The following rules apply:

'name' must contain only lowercase letters, numbers, dashes (-), underscores (_). 'name' must contain 8-64 characters. Spaces and dots (.) are not allowed.

Types

type Assertion

type Assertion struct {
	Type int    // 0 == warning, 1 == error
	Txt  string // description of the problem
	Err  error
}

Assertion is used to collect validation information

type Asset

type Asset struct {
	URI    string `json:"uri" yaml:"uri" binding:"required"`        // REQUIRED
	Title  string `json:"title,omitempty" yaml:"title,omitempty"`   // OPTIONAL
	Anchor string `json:"anchor,omitempty" yaml:"anchor,omitempty"` // OPTIONAL
	Rel    string `json:"rel,omitempty" yaml:"rel,omitempty"`       // OPTIONAL
	Type   string `json:"type,omitempty" yaml:"type,omitempty"`     // OPTIONAL
	Size   int    `json:"size,omitempty" yaml:"size,omitempty"`     // OPTIONAL
}

Asset provides a link to a media resource

func (*Asset) FingerprintURI

func (r *Asset) FingerprintURI(guid string) string

FingerprintURI is used in rewriting the URI when Rel == IMPORT

func (*Asset) ResolveURI

func (r *Asset) ResolveURI(cdn, guid string) string

ResolveURI re-writes the URI

func (*Asset) Validate

func (r *Asset) Validate(v *Validator) *Validator

Validate verifies the integrity of struct Resource

URI    string `json:"uri" yaml:"uri" binding:"required"`        // REQUIRED
Title  string `json:"title,omitempty" yaml:"title,omitempty"`   // OPTIONAL
Anchor string `json:"anchor,omitempty" yaml:"anchor,omitempty"` // OPTIONAL
Rel    string `json:"rel,omitempty" yaml:"rel,omitempty"`       // OPTIONAL
Type   string `json:"type,omitempty" yaml:"type,omitempty"`     // OPTIONAL
Size   int    `json:"size,omitempty" yaml:"size,omitempty"`     // OPTIONAL

type AuthorizationRequest

type AuthorizationRequest struct {
	Secret     string `json:"secret" binding:"required"`
	Realm      string `json:"realm" binding:"required"`
	ClientID   string `json:"client_id" binding:"required"`
	ClientType string `json:"client_type" binding:"required"` // user,app,bot
	UserID     string `json:"user_id" binding:"required"`
	Scope      string `json:"scope" binding:"required"`
	Duration   int64  `json:"duration" binding:"required"`
}

AuthorizationRequest struct is used to request a token Imported from https://github.com/txsvc/service/blob/main/pkg/auth/types.go

type AuthorizationResponse

type AuthorizationResponse struct {
	Realm    string `json:"realm" binding:"required"`
	ClientID string `json:"client_id" binding:"required"`
	Token    string `json:"token" binding:"required"`
}

AuthorizationResponse provides a valid token Imported from https://github.com/txsvc/service/blob/main/pkg/auth/types.go

type Build added in v0.9.4

type Build struct {
	GUID         string `json:"guid" binding:"required"`
	FeedURL      string `json:"feed"`
	FeedAliasURL string `json:"alias"`
}

Build initiates the build of the feed

type Category

type Category struct {
	Name        string   `json:"name" yaml:"name" binding:"required"`      // REQUIRED
	SubCategory []string `json:"subcategory" yaml:"subcategory,omitempty"` // OPTIONAL
}

Category is the show/episodes category and it's subcategories

func (*Category) Validate

func (c *Category) Validate(v *Validator) *Validator

Validate verifies the integrity of struct Category

Name        string   `json:"name" yaml:"name" binding:"required"`      // REQUIRED
SubCategory []string `json:"subcategory" yaml:"subcategory,omitempty"` // OPTIONAL

type Episode

type Episode struct {
	APIVersion  string             `json:"apiVersion" yaml:"apiVersion" binding:"required"`   // REQUIRED default: v1.0
	Kind        string             `json:"kind" yaml:"kind" binding:"required"`               // REQUIRED default: episode
	Metadata    Metadata           `json:"metadata" yaml:"metadata" binding:"required"`       // REQUIRED
	Description EpisodeDescription `json:"description" yaml:"description" binding:"required"` // REQUIRED
	Image       Asset              `json:"image" yaml:"image" binding:"required"`             // REQUIRED 'item.itunes.image'
	Enclosure   Asset              `json:"enclosure" yaml:"enclosure" binding:"required"`     // REQUIRED
}

Episode holds all metadata related to a podcast episode

func DefaultEpisode

func DefaultEpisode(baseURL, name, parentName, guid, parent string) *Episode

DefaultEpisode creates a default episode struc

func (*Episode) GUID

func (e *Episode) GUID() string

GUID is a convenience method to access the resources guid

func (*Episode) ParentGUID

func (e *Episode) ParentGUID() string

ParentGUID is a convenience method to access the resources parent guid

func (*Episode) PublishDate

func (e *Episode) PublishDate() string

PublishDate is a convenience method to access the pub date

func (*Episode) PublishDateTimestamp

func (e *Episode) PublishDateTimestamp() int64

PublishDateTimestamp converts a RFC1123Z formatted timestamp into UNIX timestamp

func (*Episode) Validate

func (e *Episode) Validate(v *Validator) *Validator

Validate verifies the integrity of struct Episode

APIVersion  string             `json:"apiVersion" yaml:"apiVersion" binding:"required"`   // REQUIRED default: v1.0
Kind        string             `json:"kind" yaml:"kind" binding:"required"`               // REQUIRED default: episode
Metadata    Metadata           `json:"metadata" yaml:"metadata" binding:"required"`       // REQUIRED
Description EpisodeDescription `json:"description" yaml:"description" binding:"required"` // REQUIRED
Image       Resource           `json:"image" yaml:"image" binding:"required"`             // REQUIRED 'item.itunes.image'
Enclosure   Resource           `json:"enclosure" yaml:"enclosure" binding:"required"`     // REQUIRED

type EpisodeDescription

type EpisodeDescription struct {
	Title       string `json:"title" yaml:"title" binding:"required"`                                 // REQUIRED 'item.title' 'item.itunes.title'
	Summary     string `json:"summary" yaml:"summary" binding:"required"`                             // REQUIRED 'item.description'
	EpisodeText string `json:"episodeText,omitempty" yaml:"episodeText,omitempty" binding:"required"` // REQUIRED 'item.itunes.summary'
	Link        Asset  `json:"link" yaml:"link"`                                                      // RECOMMENDED 'item.link'
	Duration    int    `json:"duration" yaml:"duration" binding:"required"`                           // REQUIRED 'item.itunes.duration'
}

EpisodeDescription holds essential episode metadata

func (*EpisodeDescription) Validate

func (d *EpisodeDescription) Validate(v *Validator) *Validator

Validate verifies the integrity of struct EpisodeDescription

Title       string   `json:"title" yaml:"title" binding:"required"`                                 // REQUIRED 'item.title' 'item.itunes.title'
Summary     string   `json:"summary" yaml:"summary" binding:"required"`                             // REQUIRED 'item.description'
EpisodeText string   `json:"episodeText,omitempty" yaml:"episodeText,omitempty" binding:"required"` // REQUIRED 'item.itunes.summary'
Link        Resource `json:"link" yaml:"link"`                                                      // RECOMMENDED 'item.link'
Duration    int      `json:"duration" yaml:"duration" binding:"required"`                           // REQUIRED 'item.itunes.duration'

type Import added in v0.9.4

type Import struct {
	Source string `json:"src" binding:"required"`
	Dest   string `json:"dest" binding:"required"`
}

Import is used by the import task

type Metadata

type Metadata struct {
	Name   string            `json:"name" yaml:"name" binding:"required"` // REQUIRED <unique name>
	Labels map[string]string `json:"labels" yaml:"labels,omitempty"`      // REQUIRED
}

Metadata contains information describing a resource

func (*Metadata) Validate

func (m *Metadata) Validate(v *Validator) *Validator

Validate verifies the integrity of struct Metadata

Name   string            `json:"name" yaml:"name" binding:"required"` // REQUIRED <unique name>
Labels map[string]string `json:"labels" yaml:"labels,omitempty"`      // REQUIRED

type Owner

type Owner struct {
	Name  string `json:"name" yaml:"name" binding:"required"`   // REQUIRED
	Email string `json:"email" yaml:"email" binding:"required"` // REQUIRED
}

Owner describes the owner of the show/podcast

func (*Owner) Validate

func (o *Owner) Validate(v *Validator) *Validator

Validate verifies the integrity of struct Owner

Name  string `json:"name" yaml:"name" binding:"required"`   // REQUIRED
Email string `json:"email" yaml:"email" binding:"required"` // REQUIRED

type Production

type Production struct {
	Name      string `json:"name" binding:"required"`
	GUID      string `json:"guid,omitempty"`
	Owner     string `json:"owner"`
	Title     string `json:"title"`
	Summary   string `json:"summary"`
	BuildDate int64  `json:"build_date"`
	// internal
	Created int64 `json:"-"`
	Updated int64 `json:"-"`
}

Production is the parent struct of all other resources.

type ProductionList

type ProductionList struct {
	Productions []*Production `json:"productions" `
}

ProductionList returns a list of productions

type Resource

type Resource struct {
	Name       string `json:"name"`
	GUID       string `json:"guid"`
	Kind       string `json:"kind"`
	ParentGUID string `json:"parent_guid"`
	Location   string `json:"location"` // path to the .yaml
	// only used in assets e.g. .mp3/.png
	ContentType string `json:"content_type"`
	Size        int64  `json:"size"`
	// internal
	Created int64 `json:"-"`
	Updated int64 `json:"-"`
}

Resource is used to maintain a repository of all existing resources across all shows

type ResourceList

type ResourceList struct {
	Resources []*Resource `json:"resources" `
}

ResourceList returns a list of resources

type ResourceLoaderFunc

type ResourceLoaderFunc func(data []byte) (interface{}, string, error)

ResourceLoaderFunc implements loading of resources

type ResourceMetadata

type ResourceMetadata struct {
	APIVersion string   `json:"apiVersion" yaml:"apiVersion" binding:"required"` // REQUIRED default: v1.0
	Kind       string   `json:"kind" yaml:"kind" binding:"required"`             // REQUIRED default: show
	Metadata   Metadata `json:"metadata" yaml:"metadata" binding:"required"`     // REQUIRED
}

ResourceMetadata holds only the kind and metadata of a resource

func LoadResourceMetadata

func LoadResourceMetadata(data []byte) (*ResourceMetadata, error)

LoadResourceMetadata reads only the metadata of a resource

func (*ResourceMetadata) GUID

func (r *ResourceMetadata) GUID() string

GUID is a convenience method to access the resources guid

type Show

type Show struct {
	APIVersion  string          `json:"apiVersion" yaml:"apiVersion" binding:"required"`   // REQUIRED default: v1.0
	Kind        string          `json:"kind" yaml:"kind" binding:"required"`               // REQUIRED default: show
	Metadata    Metadata        `json:"metadata" yaml:"metadata" binding:"required"`       // REQUIRED
	Description ShowDescription `json:"description" yaml:"description" binding:"required"` // REQUIRED
	Image       Asset           `json:"image" yaml:"image" binding:"required"`             // REQUIRED 'channel.itunes.image'
}

Show holds all metadata related to a podcast/show

func DefaultShow

func DefaultShow(baseURL, name, title, summary, guid string) *Show

DefaultShow creates a default show struc

func (*Show) GUID

func (s *Show) GUID() string

GUID is a convenience method to access the resources guid

func (*Show) Validate

func (s *Show) Validate(v *Validator) *Validator

Validate verifies the integrity of struct Show

APIVersion  string          `json:"apiVersion" yaml:"apiVersion" binding:"required"`   // REQUIRED default: v1.0
Kind        string          `json:"kind" yaml:"kind" binding:"required"`               // REQUIRED default: show
Metadata    Metadata        `json:"metadata" yaml:"metadata" binding:"required"`       // REQUIRED
Description ShowDescription `json:"description" yaml:"description" binding:"required"` // REQUIRED
Image       Resource        `json:"image" yaml:"image" binding:"required"`             // REQUIRED 'channel.itunes.image'

type ShowDescription

type ShowDescription struct {
	Title     string   `json:"title" yaml:"title" binding:"required"`          // REQUIRED 'channel.title' 'channel.itunes.title'
	Summary   string   `json:"summary" yaml:"summary" binding:"required"`      // REQUIRED 'channel.description'
	Link      Asset    `json:"link" yaml:"link"`                               // RECOMMENDED 'channel.link'
	Category  Category `json:"category" yaml:"category" binding:"required"`    // REQUIRED channel.category
	Owner     Owner    `json:"owner" yaml:"owner"`                             // RECOMMENDED 'channel.itunes.owner'
	Author    string   `json:"author" yaml:"author"`                           // RECOMMENDED 'channel.itunes.author'
	Copyright string   `json:"copyright,omitempty" yaml:"copyright,omitempty"` // OPTIONAL 'channel.copyright'
	NewFeed   *Asset   `json:"newFeed,omitempty" yaml:"newFeed,omitempty"`     // OPTIONAL channel.itunes.new-feed-url -> move to label
}

ShowDescription holds essential show metadata

func (*ShowDescription) Validate

func (d *ShowDescription) Validate(v *Validator) *Validator

Validate verifies the integrity of struct ShowDescription

Title     string    `json:"title" yaml:"title" binding:"required"`          // REQUIRED 'channel.title' 'channel.itunes.title'
Summary   string    `json:"summary" yaml:"summary" binding:"required"`      // REQUIRED 'channel.description'
Link      Resource  `json:"link" yaml:"link"`                               // RECOMMENDED 'channel.link'
Category  Category  `json:"category" yaml:"category" binding:"required"`    // REQUIRED channel.category
Owner     Owner     `json:"owner" yaml:"owner"`                             // RECOMMENDED 'channel.itunes.owner'
Author    string    `json:"author" yaml:"author"`                           // RECOMMENDED 'channel.itunes.author'
Copyright string    `json:"copyright,omitempty" yaml:"copyright,omitempty"` // OPTIONAL 'channel.copyright'
NewFeed   *Resource `json:"newFeed,omitempty" yaml:"newFeed,omitempty"`     // OPTIONAL channel.itunes.new-feed-url -> move to label

type StatusObject

type StatusObject struct {
	Status    int    `json:"status" binding:"required"`
	Message   string `json:"message" binding:"required"`
	RootError error  `json:"-"`
}

StatusObject is used to report operation status and errors in an API request. The struct can be used as a response object or be treated as an error object

func NewErrorStatus added in v0.9.4

func NewErrorStatus(s int, e error) StatusObject

NewErrorStatus initializes a new StatusObject from an error

func NewStatus added in v0.9.4

func NewStatus(s int, m string) StatusObject

NewStatus initializes a new StatusObject

func (*StatusObject) Error

func (so *StatusObject) Error() string

type Validatable

type Validatable interface {
	Validate(*Validator) *Validator
}

Validatable is the interface that maust be implemented to support recursive validations of strucs

type Validator

type Validator struct {
	Name     string
	Issues   []*Assertion
	Errors   int
	Warnings int
}

Validator collects assertions

func NewValidator

func NewValidator(name string) *Validator

NewValidator initializes and returns a new Validator

func (*Validator) AsError

func (v *Validator) AsError() error

AsError returns an error if NError > 0, nil otherwise

func (*Validator) AssertContains

func (v *Validator) AssertContains(src map[string]string, key, name string)

AssertContains verifies that a map contains key

func (*Validator) AssertError

func (v *Validator) AssertError(txt string)

AssertError add an error assertion

func (*Validator) AssertExistsError

func (v *Validator) AssertExistsError(src interface{}, expected string)

AssertExistsError verifies that a struct exists

func (*Validator) AssertISO639

func (v *Validator) AssertISO639(src string)

AssertISO639 verifies that src complies with ISO 639-1

func (*Validator) AssertNotEmpty

func (v *Validator) AssertNotEmpty(src map[string]string, name string)

AssertNotEmpty verifies that a map is not empty

func (*Validator) AssertNotNil

func (v *Validator) AssertNotNil(src interface{}, name string)

AssertNotNil verifies that an attribute is not nil

func (*Validator) AssertNotZero

func (v *Validator) AssertNotZero(src int, name string)

AssertNotZero verifies that a map is not empty

func (*Validator) AssertStringError

func (v *Validator) AssertStringError(src, expected string)

AssertStringError verifies a string

func (*Validator) AssertStringExists

func (v *Validator) AssertStringExists(src, name string)

AssertStringExists verifies a string is not empty

func (*Validator) AssertWarning

func (v *Validator) AssertWarning(txt string)

AssertWarning add an warning assertion

func (*Validator) Error

func (v *Validator) Error() string

Error returns an error text

func (*Validator) IsClean

func (v *Validator) IsClean() bool

IsClean returns true if NError == 0 AND NWarnings == 0

func (*Validator) IsValid

func (v *Validator) IsValid() bool

IsValid returns true if NError == 0. Warnings are ignored

func (*Validator) NErrors

func (v *Validator) NErrors() int

NErrors returns the number of erros

func (*Validator) NWarnings

func (v *Validator) NWarnings() int

NWarnings returns the number of warnings

func (*Validator) Report

func (v *Validator) Report() string

Report returns a description of all issues

func (*Validator) Validate

func (v *Validator) Validate(src Validatable) *Validator

Validate starts the chain of validations

Jump to

Keyboard shortcuts

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