albums

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// NullAlbum is a zero value Album.
	NullAlbum = Album{}

	ErrAlbumNotFound = errors.New("album not found")
)
View Source
var (
	// ErrCacheMiss is returned when the item does not exist in the cache.
	ErrCacheMiss = errors.New("item could not be found in the cache")
)

Functions

func WithCache

func WithCache(s Cache) option

WithCache configures the cache.

func WithRepository

func WithRepository(s Repository) option

WithRepository configures the Google Photos repository.

Types

type Album

type Album struct {
	ID                    string
	Title                 string
	ProductURL            string
	IsWriteable           bool
	MediaItemsCount       string
	CoverPhotoBaseURL     string
	CoverPhotoMediaItemID string
}

Album represents a Google Photos album. See: https://developers.google.com/photos/library/reference/rest/v1/albums

type Cache

type Cache interface {
	// GetAlbum returns Album data from the cache corresponding to the specified title.
	// It will return ErrCacheMiss if there is no cached Album.
	GetAlbum(ctx context.Context, title string) (Album, error)

	// PutAlbum stores the Album data in the cache using the title as key.
	// Underlying implementations may use any data storage format,
	// as long as the reverse operation, GetAlbum, results in the original data.
	PutAlbum(ctx context.Context, album Album) error

	// PutManyAlbums stores many Album data in the cache using the title as key.
	PutManyAlbums(ctx context.Context, albums []Album) error

	// InvalidateAlbum removes the Album data from the cache corresponding to the specified title.
	// If there's no such Album in the cache, it will return nil.
	InvalidateAlbum(ctx context.Context, title string) error

	// InvalidateAllAlbums removes all key corresponding to albums
	InvalidateAllAlbums(ctx context.Context) error
}

Cache is used to store and retrieve previously obtained objects.

type CachedAlbumsService

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

CachedAlbumsService implements a albums Google Photos client with cached results.

func NewCachedAlbumsService

func NewCachedAlbumsService(authenticatedClient *http.Client, options ...Option) *CachedAlbumsService

NewCachedAlbumsService returns an albums Google Photos client with cached results. The authenticatedClient should have all oAuth credentials in place.

func (CachedAlbumsService) AddMediaItems

func (s CachedAlbumsService) AddMediaItems(ctx context.Context, albumId string, mediaItemIds []string) error

AddMediaItems adds multiple media item(s) to the specified album.

func (CachedAlbumsService) Create

func (s CachedAlbumsService) Create(ctx context.Context, title string) (*Album, error)

Create adds and caches a new album to the repo.

func (CachedAlbumsService) GetById

func (s CachedAlbumsService) GetById(ctx context.Context, albumId string) (*Album, error)

GetById fetches and caches an album from the repo by id. It does not use the cache to look for it. Returns ErrAlbumNotFound if the album does not exist.

func (CachedAlbumsService) GetByTitle

func (s CachedAlbumsService) GetByTitle(ctx context.Context, title string) (*Album, error)

GetByTitle fetches and caches an album from the repo by title. It tries to find it in the cache, first. Returns ErrAlbumNotFound if the album does not exist.

func (CachedAlbumsService) List

func (s CachedAlbumsService) List(ctx context.Context) ([]Album, error)

List fetches and caches all the albums from the repo.

func (CachedAlbumsService) RemoveMediaItems

func (s CachedAlbumsService) RemoveMediaItems(ctx context.Context, albumId string, mediaItemIds []string) error

RemoveMediaItems removes multiple media item(s) from the specified album.

type CachitaCache

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

CachitaCache implements Cache with `gadelkareem/cachita` package.

func NewCachitaCache

func NewCachitaCache() *CachitaCache

NewCachitaCache returns a Cache service implemented using `gadelkareem/cachita`.

func (CachitaCache) GetAlbum

func (c CachitaCache) GetAlbum(ctx context.Context, title string) (Album, error)

GetAlbum reads an object data from the cache.

func (CachitaCache) InvalidateAlbum

func (c CachitaCache) InvalidateAlbum(ctx context.Context, title string) error

InvalidateAlbum removes the specified Album from the cache.

func (CachitaCache) InvalidateAllAlbums

func (c CachitaCache) InvalidateAllAlbums(ctx context.Context) error

InvalidateAllAlbums removes all albums from the cache.

func (CachitaCache) PutAlbum

func (c CachitaCache) PutAlbum(ctx context.Context, album Album) error

PutAlbum store an object data to the cache.

func (CachitaCache) PutManyAlbums

func (c CachitaCache) PutManyAlbums(ctx context.Context, albums []Album) error

PutManyAlbums store many objects data to the cache.

type Option

type Option interface {
	Name() string
	Value() interface{}
}

Option represents a configurable parameter.

type PhotosLibraryAlbumsRepository added in v2.1.0

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

PhotosLibraryAlbumsRepository represents an albums Google Photos repository.

func NewPhotosLibraryClient added in v2.1.0

func NewPhotosLibraryClient(authenticatedClient *http.Client) (*PhotosLibraryAlbumsRepository, error)

NewPhotosLibraryClient returns a Repository using PhotosLibrary service.

func NewPhotosLibraryClientWithURL added in v2.1.0

func NewPhotosLibraryClientWithURL(authenticatedClient *http.Client, url string) (*PhotosLibraryAlbumsRepository, error)

NewPhotosLibraryClientWithURL returns a Repository using PhotosLibrary service with a custom URL.

func (PhotosLibraryAlbumsRepository) AddManyItems added in v2.1.0

func (r PhotosLibraryAlbumsRepository) AddManyItems(ctx context.Context, albumId string, mediaItemIds []string) error

AddManyItems adds multiple media item(s) to the specified album.

func (PhotosLibraryAlbumsRepository) Create added in v2.1.0

Create adds and caches a new album to the repo.

func (PhotosLibraryAlbumsRepository) Get added in v2.1.0

Get fetches and caches an album from the repo by id.

func (PhotosLibraryAlbumsRepository) GetByTitle added in v2.1.0

func (r PhotosLibraryAlbumsRepository) GetByTitle(ctx context.Context, title string) (*Album, error)

GetByTitle fetches and caches an album from the repo by title.

func (PhotosLibraryAlbumsRepository) ListAll added in v2.1.0

ListAll fetches and caches all the albums from the repo.

func (PhotosLibraryAlbumsRepository) RemoveManyItems added in v2.1.0

func (r PhotosLibraryAlbumsRepository) RemoveManyItems(ctx context.Context, albumId string, mediaItemIds []string) error

RemoveManyItems removes multiple media item(s) from the specified album.

func (PhotosLibraryAlbumsRepository) URL added in v2.1.0

URL returns the albums repository url.

type PhotosLibraryClient added in v2.1.0

type PhotosLibraryClient interface {
	BatchAddMediaItems(albumId string, albumbatchaddmediaitemsrequest *photoslibrary.AlbumBatchAddMediaItemsRequest) *photoslibrary.AlbumBatchAddMediaItemsCall
	Create(createalbumrequest *photoslibrary.CreateAlbumRequest) *photoslibrary.AlbumsCreateCall
	Get(albumId string) *photoslibrary.AlbumsGetCall
	List() *photoslibrary.AlbumsListCall
}

PhotosLibraryClient represents an albums using `gphotosuploader/googlemirror/api/photoslibrary`.

type Repository

type Repository interface {
	AddManyItems(ctx context.Context, albumId string, mediaItemIds []string) error
	RemoveManyItems(ctx context.Context, albumId string, mediaItemIds []string) error
	Create(ctx context.Context, title string) (*Album, error)
	Get(ctx context.Context, albumId string) (*Album, error)
	ListAll(ctx context.Context) ([]Album, error)
	GetByTitle(ctx context.Context, title string) (*Album, error)
}

Repository represents a albums repository.

Jump to

Keyboard shortcuts

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