Home Reference Source
public class | source

Fetcher

Base api fetcher.

Constructor Summary

Public Constructor
public

constructor(http: Http, territory: string)

Method Summary

Public Methods
public

fetchNextPage(fulfillment: fulfillment, nextUriPath: String): Promise

Fetches next page of various paged APIs.

public

hasNextPage(fulfillment: fulfillment, nextUriPath: String): Boolean

Is next page available for various paged APIs.

public

setTerritory(territory: string): Fetcher

Set the fetcher's territory.

Public Constructors

public constructor(http: Http, territory: string) source

Params:

NameTypeAttributeDescription
http Http
territory string
  • optional
  • default: 'TW'

['TW', 'HK', 'SG', 'MY', 'JP'] The territory for the fetcher.

Public Methods

public fetchNextPage(fulfillment: fulfillment, nextUriPath: String): Promise source

Fetches next page of various paged APIs.

Params:

NameTypeAttributeDescription
fulfillment fulfillment

The fulfillment get from Promose's onFulfillment function

nextUriPath String

The next uri's path. Defaults to 'data.paging.next', which means we will get the next uri path from 'fulfillment.data.paging.next'. The correct next uri path depends on respective api's response.

Return:

Promise

Example:

api.albumFetcher
  .setAlbumID('KmRKnW5qmUrTnGRuxF')
  .fetchTracks()
  .then(response => {
    api.albumFetcher.fetchNextPage(response));
  });

public hasNextPage(fulfillment: fulfillment, nextUriPath: String): Boolean source

Is next page available for various paged APIs.

Params:

NameTypeAttributeDescription
fulfillment fulfillment

The fulfillment get from Promose's onFulfillment function

nextUriPath String

The next uri's path. Defaults to 'data.paging.next', which means we will get the next uri path from 'fulfillment.data.paging.next'. The correct next uri path depends on respective api's response.

Return:

Boolean

Example:

api.albumFetcher
  .setAlbumID('KmRKnW5qmUrTnGRuxF')
  .fetchTracks()
  .then(response => {
    if (api.albumFetcher.hasNextPage(response)) {
      // more data available
    }
  });

public setTerritory(territory: string): Fetcher source

Set the fetcher's territory.

Params:

NameTypeAttributeDescription
territory string
  • optional
  • default: 'TW'

['TW', 'HK', 'SG', 'MY', 'JP'] The territory for the fetcher.

Return:

Fetcher