pexels

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

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

Go to latest
Published: Jan 11, 2024 License: MIT Imports: 7 Imported by: 0

README

Pexels Photo & Video Library

This is an Encore package for searching and retrieving photos and videos from Pexels.

Installation

  1. Copy over the pexels package directory to your Encore application.
  2. Sync your project dependencies by running go mod tidy.

Pexels API Key

You will need an API key from Pexels to use this package. You can get one by signing up for a free account at https://www.pexels.com/.

Once you have the API key, set it as an Encore secret using the name PexelsApiKey:

$ encore secret set --type dev,prod,local,pr PexelsApiKey
Enter secret value: *****
Successfully updated development secret PexelsApiKey.

Endpoints

The pexels package contains the following endpoints:

  • pexels.SearchPhotos - Search Pexels for photos.

  • pexels.CuratedPhotos - Receive real-time photos curated by the Pexels team.

  • pexels.GetPhoto - Retrieve a specific photo.

  • pexels.SearchVideos - Search Pexels for videos.

  • pexels.PopularVideos - Retrieve the current popular Pexels videos.

  • pexels.GetVideo - Retrieve a specific video.

  • pexels.FeaturedCollections - Retrieve all featured collections on Pexels.

  • pexels.MyCollections - Returns all of your collections.

  • pexels.CollectionMedia - Returns all the media (photos and videos) within a single collection.

Frontend example usage

After generating a request client for your frontend you can call the endpoints like this:

// Making request to locally running backend...
const client = new Client(Local);
// or to a specific deployed environment
const client = new Client(Environment("staging"));

const resp = await client.pexels.SearchPhotos({
  Query: "cats",
  Page: 1,
  PerPage: 15,
  Color: "",
  Locale: "",
  Size: "",
  Orientation: "",
});

console.log(resp.total_results);
console.log(resp.photos);

Learn More

Documentation

Overview

Package pexels is used for searching and retrieving photos and videos from Pexels https://www.pexels.com/api/documentation/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectionMedia

func CollectionMedia(w http.ResponseWriter, req *http.Request)

CollectionMedia returns all the media (photos and videos) within a single collection. You can filter to only receive photos or videos using the type parameter: /collection/gz8lwcj?page=2&per_page=10&type=photos https://www.pexels.com/api/documentation/#collections-media

Types

type CollectionMediaParams

type CollectionMediaParams struct {
	// Default: 1
	Page int `query:"page" url:"page,omitempty"`

	// Default: 15, Max: 80
	PerPage int `query:"per_page" url:"per_page,omitempty"`

	// "photos" or "videos"
	Type string `query:"type" url:"type,omitempty"`
}

type CollectionParams

type CollectionParams struct {
	// Default: 1
	Page int `query:"page" url:"page,omitempty"`

	// Default: 15, Max: 80
	PerPage int `query:"per_page" url:"per_page,omitempty"`
}

type CollectionResourceResponse

type CollectionResourceResponse struct {
	Id          string `json:"id"`
	Title       string `json:"title"`
	Description string `json:"description"`
	Private     bool   `json:"private"`
	MediaCount  int    `json:"media_count"`
	PhotosCount int    `json:"photos_count"`
	VideosCount int    `json:"videos_count"`
}

type CollectionsResponse

type CollectionsResponse struct {
	Page         int    `json:"page"`
	PerPage      int    `json:"per_page"`
	TotalResults int    `json:"total_results"`
	NextPage     string `json:"next_page"`
	PrevPage     string `json:"prev_page"`

	Collections []*CollectionResourceResponse `json:"collections"`
}

func FeaturedCollections

func FeaturedCollections(ctx context.Context, queryParams *CollectionParams) (*CollectionsResponse, error)

FeaturedCollections retrieves all featured collections on Pexels. https://www.pexels.com/api/documentation/#collections-featured

func MyCollections

func MyCollections(ctx context.Context, queryParams *CollectionParams) (*CollectionsResponse, error)

MyCollections returns all of your collections. https://www.pexels.com/api/documentation/#collections-all

type CuratedParams

type CuratedParams struct {
	// Default: 1
	Page int `query:"page" url:"page,omitempty"`

	// Default: 15, Max: 80
	PerPage int `query:"per_page" url:"per_page,omitempty"`
}

type PhotoQueryParams

type PhotoQueryParams struct {
	// Default: 1
	Page int `query:"page,omitempty" url:"page,omitempty"`

	// Default: 15, Max: 80
	PerPage int `query:"per_page" url:"per_page,omitempty"`

	Query string `query:"query" url:"query,omitempty"`

	// "landscape", "portrait", "square"
	Orientation string `query:"orientation" url:"per_page,omitempty"`

	// "large" (24MP), "medium" (12MP) or "small" (4MP)
	Size string `query:"size" url:"size,omitempty"`

	// "red", "orange", "yellow", "green", "turquoise", "blue", "violet", "pink", "brown", "black", "gray", "white" or any hexidecimal color code (eg. "#ffffff").
	Color string `query:"color" url:"color,omitempty"`

	// "en-US", "pt-BR", "es-ES", "ca-ES", "de-DE", "it-IT", "fr-FR", "sv-SE", "id-ID", "pl-PL", "ja-JP", "zh-TW", "zh-CN", "ko-KR"
	// "th-TH", "nl-NL", "hu-HU", "vi-VN", "cs-CZ", "da-DK", "fi-FI", "uk-UA", "el-GR", "ro-RO", "nb-NO", "sk-SK", "tr-TR", "ru-RU"
	Locale string `query:"locale" url:"locale,omitempty"`
}

type PhotoResponse

type PhotoResponse struct {
	Id              int    `json:"id"`
	Width           int    `json:"width"`
	Height          int    `json:"height"`
	Url             string `json:"url"`
	Photographer    string `json:"photographer"`
	PhotographerUrl string `json:"photographer_url"`
	PhotographerId  int    `json:"photographer_id"`
	AvgColor        string `json:"avg_color"`
	Src             struct {
		Original  string `json:"original"`
		Large2X   string `json:"large2x"`
		Large     string `json:"large"`
		Medium    string `json:"medium"`
		Small     string `json:"small"`
		Portrait  string `json:"portrait"`
		Landscape string `json:"landscape"`
		Tiny      string `json:"tiny"`
	} `json:"src"`
	Liked bool   `json:"liked"`
	Alt   string `json:"alt"`
}

func GetPhoto

func GetPhoto(ctx context.Context, id string) (*PhotoResponse, error)

GetPhoto retrieves a specific photo. https://www.pexels.com/api/documentation/#photos-show

type PhotoSearchResponse

type PhotoSearchResponse struct {
	Page         int              `json:"page"`
	PerPage      int              `json:"per_page"`
	TotalResults int              `json:"total_results"`
	NextPage     string           `json:"next_page"`
	PrevPage     string           `json:"prev_page"`
	Photos       []*PhotoResponse `json:"photos"`
}

func CuratedPhotos

func CuratedPhotos(ctx context.Context, queryParams *CuratedParams) (*PhotoSearchResponse, error)

CuratedPhotos receive real-time photos curated by the Pexels team. https://www.pexels.com/api/documentation/#photos-curated

func SearchPhotos

func SearchPhotos(ctx context.Context, queryParams *PhotoQueryParams) (*PhotoSearchResponse, error)

SearchPhotos search Pexels for photos. Query could be something broad like "Nature", "Tigers", "People". Or it could be something specific like "Group of people working". https://www.pexels.com/api/documentation/#photos-search

type VideoPopularParams

type VideoPopularParams struct {
	// Default: 1
	Page int `query:"page" url:"page,omitempty"`

	// Default: 15, Max: 80
	PerPage int `query:"per_page" url:"per_page,omitempty"`

	MinWidth    int `query:"min_width" url:"min_width,omitempty"`
	MinHeight   int `query:"min_height" url:"min_height,omitempty"`
	MinDuration int `query:"min_duration" url:"min_duration,omitempty"`
	MaxDuration int `query:"max_duration" url:"max_duration,omitempty"`
}

type VideoQueryParams

type VideoQueryParams struct {
	// Default: 1
	Page int `query:"page" url:"page,omitempty"`

	// Default: 15, Max: 80
	PerPage int `query:"per_page" url:"per_page,omitempty"`

	Query string `query:"query" url:"query,omitempty"`

	// "landscape", "portrait", "square"
	Orientation string `query:"orientation" url:"per_page,omitempty"`

	// "large" (4K), "medium" (Full HD) or "small" (HD)
	Size string `query:"size" url:"size,omitempty"`

	// "en-US", "pt-BR", "es-ES", "ca-ES", "de-DE", "it-IT", "fr-FR", "sv-SE", "id-ID", "pl-PL", "ja-JP", "zh-TW", "zh-CN", "ko-KR"
	// "th-TH", "nl-NL", "hu-HU", "vi-VN", "cs-CZ", "da-DK", "fi-FI", "uk-UA", "el-GR", "ro-RO", "nb-NO", "sk-SK", "tr-TR", "ru-RU"
	Locale string `query:"locale" url:"locale,omitempty"`
}

type VideoResponse

type VideoResponse struct {
	Id       int      `json:"id"`
	Width    int      `json:"width"`
	Height   int      `json:"height"`
	Url      string   `json:"url"`
	Image    string   `json:"image"`
	Tags     []string `json:"tags"`
	Duration int      `json:"duration"`

	User struct {
		Id   int    `json:"id"`
		Name string `json:"name"`
		Url  string `json:"url"`
	} `json:"user"`

	VideoFiles []struct {
		Id       int     `json:"id"`
		Quality  string  `json:"quality"`
		FileType string  `json:"file_type"`
		Width    int     `json:"width"`
		Height   int     `json:"height"`
		Fps      float64 `json:"fps"`
		Link     string  `json:"link"`
	} `json:"video_files"`

	VideoPictures []struct {
		Id      int    `json:"id"`
		Picture string `json:"picture"`
		Nr      int    `json:"nr"`
	} `json:"video_pictures"`
}

func GetVideo

func GetVideo(ctx context.Context, id string) (*VideoResponse, error)

GetVideo retrieves a specific video. https://www.pexels.com/api/documentation/#videos-show

type VideoSearchResponse

type VideoSearchResponse struct {
	Page         int              `json:"page"`
	PerPage      int              `json:"per_page"`
	TotalResults int              `json:"total_results"`
	Url          string           `json:"url"`
	NextPage     string           `json:"next_page"`
	PrevPage     string           `json:"prev_page"`
	Photos       []*VideoResponse `json:"videos"`
}

func PopularVideos

func PopularVideos(ctx context.Context, queryParams *VideoPopularParams) (*VideoSearchResponse, error)

PopularVideos receives the current popular Pexels videos. https://www.pexels.com/api/documentation/#videos-popular

func SearchVideos

func SearchVideos(ctx context.Context, queryParams *VideoQueryParams) (*VideoSearchResponse, error)

SearchVideos search Pexels for videos. Query could be something broad like "Nature", "Tigers", "People". Or it could be something specific like "Group of people working". https://www.pexels.com/api/documentation/#videos-search

Jump to

Keyboard shortcuts

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