import { inject, injectable } from "inversify"; import BaseService from "../../service"; import { IService, IResourceMapper, IFindParams } from "../../interfaces"; import BookmarkPopularityMapper from "./mapper"; import BookmarkPopularity, { bookmarkPopularityType, IBookmarkPopularity, IBookmarkPopularityResource, IBookmarkPopularityResponse } from "../bookmarkPopularity"; export interface IBookmarkPopularityService extends IService { findByPlaceId(placeId: string, options: IFindParams): Promise findByTargetType(targetType: string, options: IFindParams): Promise } @injectable() export default class BookmarkPopularityService extends BaseService implements IBookmarkPopularityService { resource: string = bookmarkPopularityType; mapper: IResourceMapper = new BookmarkPopularityMapper(); /** * @example http://stable.web.op-api-gateway.qa.lonelyplanet.com/bookmark-lists/popularity */ public url() { return `${this.host}/bookmark-lists/popularity`; } /** * Find bookmarked resources' popularity by place id. * * @param placeId Place Id * @param options * @example * * ```typescript * * client.bookmarkListPopularity.findByPlaceId("1341151"}); * ``` */ public async findByPlaceId(placeId: string, options: IFindParams = {}) { return this.fetch({ resource: "target", place_id: placeId, ...options, }); } /** * Find bookmarked resources' popularity by their type. * * @param targetType the type of the bookmarked resource * @param options * @example * * ```typescript * * client.bookmarkListPopularity.findByTargetType("poi"}); * ``` */ public findByTargetType(targetType: string, options: IFindParams = {}) { return this.fetch({ resource: "target", type: targetType, ...options, }); } private async fetch(options: IFindParams) { const resources = await this.http.fetch( `${this.url()}${this.qs(options)}`, { headers: this.headers(), } ); return this.mapper.map(resources); } }