Skip to content

Commit

Permalink
feat(marketboard): add support for datacenter price requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Supamiu committed Apr 25, 2019
1 parent 1e00c64 commit 0e3aba3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 17 deletions.
21 changes: 13 additions & 8 deletions src/model/xivapi-options.ts
Expand Up @@ -9,7 +9,7 @@ export interface XivapiOptions {
*/
language?: string;

/**
/**
* Pull specific columns from the data. By default the list just provides the ID, and result provides every column.
* You can request specific pieces of information from a list or result by plugging in the column names.
* For extended content you use dot notation to access it, for example:
Expand All @@ -29,13 +29,13 @@ export interface XivapiOptions {
columns?: string[];

/**
* You can add tracking counters to your app for whatever purpose using "tags". Tags will appear in your dashboard with a counter
* next to them. You can have as many tags you would like and counts will store for a period of 30 days before taping off
* and being removed if they become inactive.
*
* A tag must be alpha numeric and allows dashes and underscores, however this is not checked or validated until it hits XivAPI.
* A GitHub issue to add support for this to TypeScript can be found at https://github.com/Microsoft/TypeScript/issues/6579
*/
* You can add tracking counters to your app for whatever purpose using "tags". Tags will appear in your dashboard with a counter
* next to them. You can have as many tags you would like and counts will store for a period of 30 days before taping off
* and being removed if they become inactive.
*
* A tag must be alpha numeric and allows dashes and underscores, however this is not checked or validated until it hits XivAPI.
* A GitHub issue to add support for this to TypeScript can be found at https://github.com/Microsoft/TypeScript/issues/6579
*/
tags?: string[];

/**
Expand All @@ -47,4 +47,9 @@ export interface XivapiOptions {
* Servers for the market endpoint.
*/
servers?: string[];

/**
* Extra query params to add to the request.
*/
extraQueryParams?: { [index: string]: string };
}
48 changes: 39 additions & 9 deletions src/xivapi.service.ts
Expand Up @@ -98,6 +98,13 @@ export class XivapiService {
return this.request<string[]>(`/servers`);
}

/**
* Gets the current list of available servers, per DC.
*/
public getDCList(): Observable<{ [index: string]: string[] }> {
return this.request<{ [index: string]: string[] }>(`/servers/dc`);
}

/**
* Search for a character on **The Lodestone**. This does not search XIVAPI but instead it goes directly to
* lodestone so the response will be "real-time". Responses are cached for 1 hour,
Expand Down Expand Up @@ -223,6 +230,20 @@ export class XivapiService {
return this.request<{ [index: string]: MarketboardItem[] }>(`/market/item/${itemId}`, options);
}

/**
* Gets marketboard informations for a given item.
*
* @param datacenter The datacenter to use for marketboard informations.
* @param itemId The item you want informations on.
* @param options Options of the request.
*/
public getMarketBoardItemCrossServer(datacenter: string, itemId: number,
options: XivapiOptions = {}): Observable<{ [index: string]: MarketboardItem }> {
options.extraQueryParams = options.extraQueryParams || {};
options.extraQueryParams['dc'] = datacenter;
return this.request<{ [index: string]: MarketboardItem }>(`/market/items/${itemId}`, options);
}

protected request<T>(endpoint: string, params?: XivapiOptions): Observable<T> {
let queryParams: HttpParams = this.prepareQueryString(params);
let baseUrl: string;
Expand All @@ -242,15 +263,24 @@ export class XivapiService {
if (options === null || options === undefined) {
return queryString;
}
Object.keys(options).forEach(optionKey => {
// @ts-ignore
const value: any = options[optionKey] as any;
if (value instanceof Array) {
queryString = queryString.set(optionKey, value.join(','));
} else {
queryString = queryString.set(optionKey, value.toString());
}
});
Object.keys(options)
.filter(key => key !== 'extraQueryParams')
.forEach(optionKey => {
// @ts-ignore
const value: any = options[optionKey] as any;
if (value instanceof Array) {
queryString = queryString.set(optionKey, value.join(','));
} else {
queryString = queryString.set(optionKey, value.toString());
}
});
if (options.extraQueryParams !== undefined) {
Object.keys(options.extraQueryParams)
.forEach(key => {
// @ts-ignore
queryString.set(key, options.extraQueryParams[key].toString());
});
}
return queryString;
}

Expand Down

0 comments on commit 0e3aba3

Please sign in to comment.