UNPKG

@berry-cloud/ngx-unsplash

Version:

Lightweight Angular wrapper for the Unsplash API.

378 lines (377 loc) 13.6 kB
import { HttpClient } from '@angular/common/http'; import { InjectionToken } from '@angular/core'; import { Observable } from 'rxjs'; import { Collection } from './model/collection'; import { Download } from './model/download'; import { Photo } from './model/photo'; import { SearchResult } from './model/search-result'; import { UserStatistics } from './model/statistics'; import { Topic } from './model/topic'; import { UnsplashColor, UnsplashContentFilter, UnsplashFeaturedOrderBy, UnsplashOrderBy, UnsplashOrientation, UnsplashResolution, UnsplashSearchOrderBy } from './model/types'; import { User } from './model/user'; import * as i0 from "@angular/core"; export interface UnsplashConfig { url: string; authorization: string; } export declare const UNSPLASH_CONFIG: InjectionToken<UnsplashConfig | Observable<UnsplashConfig>>; export type Count = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30; export declare class UnsplashService { private http; private readonly searchUrl; private readonly photosUrl; private readonly randomUrl; private readonly collectionsUrl; private readonly topicsUrl; private readonly usersUrl; private config$; constructor(http: HttpClient, config: UnsplashConfig | Observable<UnsplashConfig>); /** * [List photos](https://unsplash.com/documentation#list-photos). * * Get a single page from the list of all photos. * * @param options to be used when getting list of photos * * @returns Observable containing a {@link Photo} array */ photos(options?: { page?: number; perPage?: number; orderBy?: UnsplashOrderBy; }): Observable<Photo[]>; /** * [List photos](https://unsplash.com/documentation#list-photos). * * Get a single page from the list of all photos. * * @param options to be used when getting list of photos * * @returns Observable containing a {@link Photo} array * * @deprecated Use {@link photos} instead */ list(options?: { page?: number; perPage?: number; orderBy?: UnsplashOrderBy; }): Observable<Photo[]>; /** * [Get a photo](https://unsplash.com/documentation#get-a-photo). * * Retrieve a single photo. * * @param id of the photo * * @returns Observable containing the {@link Photo} */ photo(id: string): Observable<Photo>; /** * [Get a photo](https://unsplash.com/documentation#get-a-photo). * * Retrieve a single photo. * * @param id of the photo * * @returns Observable containing the {@link Photo} * * @deprecated Use {@link photo} instead */ get(id: string): Observable<Photo>; /** * [Get random photos](https://unsplash.com/documentation#get-a-random-photo). * * Retrieve random photos. * * @param options to be used when getting random photos * * @returns Observable containing a {@link Photo} array */ randomPhoto(options?: { collections?: string; topics?: string; username?: string; query?: string; orientation?: UnsplashOrientation; contentFilter?: UnsplashContentFilter; count?: Count; }): Observable<Photo[]>; /** * [Get random photos](https://unsplash.com/documentation#get-a-random-photo). * * Retrieve random photos. * * @param options to be used when getting random photos * * @returns Observable containing a {@link Photo} array * * @deprecated Use {@link randomPhoto} instead */ random(options?: { collections?: string; topics?: string; username?: string; query?: string; orientation?: UnsplashOrientation; contentFilter?: UnsplashContentFilter; count?: Count; }): Observable<Photo[]>; /** * [Search photos](https://unsplash.com/documentation#search-photos). * * Get a single page of photo results for a query. * * @param query to search for * @param options to be used when searching photos * * @returns Observable containing a {@link SearchResult} */ searchPhotos(query: string, options?: { page?: number; perPage?: number; orderBy?: UnsplashSearchOrderBy; collections?: string; contentFilter?: UnsplashContentFilter; color?: UnsplashColor; orientation?: UnsplashOrientation; }): Observable<SearchResult>; /** * [Search photos](https://unsplash.com/documentation#search-photos). * * Get a single page of photo results for a query. * * @param query to search for * @param options to be used when searching photos * * @returns Observable containing a {@link SearchResult} * * @deprecated Use {@link searchPhotos} instead */ search(query: string, options?: { page?: number; perPage?: number; orderBy?: UnsplashSearchOrderBy; collections?: string; contentFilter?: UnsplashContentFilter; color?: UnsplashColor; orientation?: UnsplashOrientation; }): Observable<SearchResult>; /** * [Trigger a download](https://help.unsplash.com/en/articles/2511258-guideline-triggering-a-download) * of a photo. * * @param photo to download * * @returns Observable containing the {@link Download} */ downloadPhoto(photo: Photo): Observable<Download>; /** * [Trigger a download](https://help.unsplash.com/en/articles/2511258-guideline-triggering-a-download) * of a photo. * * @param photo to download * * @returns Observable containing the {@link Download} * * @deprecated Use {@link downloadPhoto} instead */ download(photo: Photo): Observable<Download>; /** * [List collections](https://unsplash.com/documentation#list-collections). * Retrieve a list of collections. * * @param options to be used when getting collections * * @returns Observable containing a {@link Collection} array * * @throws Error if the Unsplash configuration is not provided */ collections(options?: { page?: number; perPage?: number; }): Observable<Collection[]>; /** * [Get a collection](https://unsplash.com/documentation#get-a-collection). * Retrieve a single collection. * * @param id of the collection to retrieve * * @returns Observable containing a {@link Collection} * * @throws Error if the collection id is not provided * @throws Error if the Unsplash configuration is not provided */ collection(id: string): Observable<Collection>; /** * [Get a collection's photos](https://unsplash.com/documentation#get-a-collections-photos). * Retrieve a list of photos in a collection. * * @param id of the collection to retrieve photos from * @param options to be used when getting photos from a collection * * @returns Observable containing a {@link Photo} array * * @throws Error if the collection id is not provided * @throws Error if the Unsplash configuration is not provided */ collectionPhotos(id: string, options?: { page?: number; perPage?: number; orientation?: UnsplashOrientation; }): Observable<Photo[]>; /** * [List related collections](https://unsplash.com/documentation#list-a-collections-related-collections). * Retrieve a list of collections related to a particular one. * * @param id of the collection to retrieve related collections from * * @returns Observable containing a {@link Collection} array * * @throws Error if the collection id is not provided * @throws Error if the Unsplash configuration is not provided */ relatedCollections(id: string): Observable<Collection[]>; /** * [List topics](https://unsplash.com/documentation#list-topics). * Retrieve a list of topics. * * @param options to be used when getting topics * * @returns Observable containing a {@link Topic} array */ topics(options?: { ids?: string[]; page?: number; perPage?: number; orderBy?: UnsplashFeaturedOrderBy; }): Observable<Topic[]>; /** * [Get a topic](https://unsplash.com/documentation#get-a-topic). * Retrieve a single topic. * * @param id of the topic to retrieve * * @returns Observable containing a {@link Topic} * * @throws Error if the topic id is not provided * @throws Error if the Unsplash configuration is not provided */ topic(id: string): Observable<Topic>; /** * [Get a topic's photos](https://unsplash.com/documentation#get-a-topics-photos). * Retrieve a list of photos in a topic. * * @param id of the topic to retrieve photos from * @param options to be used when getting photos from a topic * * @returns Observable containing a {@link Photo} array * * @throws Error if the topic id is not provided * @throws Error if the Unsplash configuration is not provided */ topicPhotos(id: string, options?: { page?: number; perPage?: number; orientation?: UnsplashOrientation; orderBy?: UnsplashOrderBy; }): Observable<Photo[]>; /** * [Get a user](https://unsplash.com/documentation#get-a-user). * Retrieve public details on a given user. * * @param username of the user to retrieve * * @returns Observable containing a {@link User} * * @throws Error if the user username is not provided * @throws Error if the Unsplash configuration is not provided */ user(username: string): Observable<User>; /** * [Get a user's portfolio link](https://unsplash.com/documentation#get-a-users-portfolio-link). * Retrieve a single user’s portfolio link. * * @param username of the user to retrieve portfolio link from * * @returns Observable containing a {@link User} * * @throws Error if the user username is not provided * @throws Error if the Unsplash configuration is not provided */ userPortfolio(username: string): Observable<string | undefined>; /** * [List a user’s photos](https://unsplash.com/documentation#list-a-users-photos). * Retrieve a list of photos uploaded by a user. * * @param username of the user to retrieve photos from * @param options to be used when getting photos from a user * * @returns Observable containing a {@link Photo} array * * @throws Error if the user username is not provided * @throws Error if the Unsplash configuration is not provided */ userPhotos(username: string, options?: { page?: number; perPage?: number; orderBy?: UnsplashOrderBy; stats?: boolean; resolution?: UnsplashResolution; quantity?: number; orientation?: UnsplashOrientation; }): Observable<Photo[]>; /** * [List a user’s liked photos](https://unsplash.com/documentation#list-a-users-liked-photos). * Retrieve a list of photos liked by a user. * * @param username of the user to retrieve liked photos from * @param options to be used when getting liked photos from a user * * @returns Observable containing a {@link Photo} array * * @throws Error if the user username is not provided * @throws Error if the Unsplash configuration is not provided */ userLikes(username: string, options?: { page?: number; perPage?: number; orderBy?: UnsplashOrderBy; }): Observable<Photo[]>; /** * [List a user’s collections](https://unsplash.com/documentation#list-a-users-collections). * Retrieve a list of collections created by the user. * * @param username of the user to retrieve collections from * @param options to be used when getting collections from a user * * @returns Observable containing a {@link Collection} array * * @throws Error if the user username is not provided * @throws Error if the Unsplash configuration is not provided */ userCollections(username: string, options?: { page?: number; perPage?: number; orderBy?: UnsplashOrderBy; }): Observable<Collection[]>; /** * [Get a user’s statistics](https://unsplash.com/documentation#get-a-users-statistics). * Retrieve total number of downloads, views and likes of all user’s photos, as well as the historical breakdown and average of these stats in a specific time frame (default is 30 days). * * @param username of the user to retrieve statistics from * @param options to be used when getting statistics from a user * * @returns Observable containing a {@link UserStatistics} object * * @throws Error if the user username is not provided * @throws Error if the Unsplash configuration is not provided */ userStatistics(username: string, options?: { resolution?: UnsplashResolution; quantity?: number; }): Observable<UserStatistics>; private unsplashUrl; private unsplashHeaders; static ɵfac: i0.ɵɵFactoryDeclaration<UnsplashService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<UnsplashService>; }