Skip to content

Commit 1215f7c

Browse files
committed
feat: add support for character search query, including server listing
1 parent 2751bfa commit 1215f7c

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export interface CharacterSearchResultRow {
2+
ID: number;
3+
Name: string;
4+
Server: string;
5+
Avatar: string;
6+
Rank: string;
7+
RankIcon: string;
8+
FeastMatches: number;
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { CharacterSearchResultRow } from './character-search-result-row';
2+
3+
export interface CharacterSearchResult {
4+
Characters: CharacterSearchResultRow[];
5+
6+
// TODO change this for normalized pagination
7+
PageCurrent: number;
8+
PageNext: number;
9+
PagePrevious: number;
10+
PageTotal: number;
11+
Total: number;
12+
}

src/model/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export { CharacterSearchResult } from './character-search-result';
2+
export { CharacterSearchResultRow } from './character-search-result-row';
13
export { Pagination } from './pagination';
24
export { SearchAlgo } from './search-algo';
35
export { SearchIndex } from './search-index';

src/xivapi.service.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import { Inject, Injectable } from '@angular/core';
22
import { HttpClient, HttpParams } from '@angular/common/http';
33
import { Observable } from 'rxjs';
4-
import { XivapiCharacterOptions, XivapiEndpoint, XivapiList, XivapiOptions, XivapiRequestOptions, XivapiSearchOptions } from './model';
4+
import {
5+
CharacterSearchResult,
6+
XivapiCharacterOptions,
7+
XivapiEndpoint,
8+
XivapiList,
9+
XivapiOptions,
10+
XivapiRequestOptions,
11+
XivapiSearchOptions
12+
} from './model';
513
import { XIVAPI_KEY } from './xivapi-client.module';
6-
import { CharacterResponse } from './model/schema/character/character-response';
7-
import { CharacterVerification } from './model/schema/character/character-verification';
14+
import { CharacterResponse, CharacterVerification } from './model/schema/character';
815

916
@Injectable()
1017
export class XivapiService {
@@ -66,6 +73,36 @@ export class XivapiService {
6673
return this.request<any>(`${XivapiService.API_BASE_URL}/Character/${lodestoneId}${details ? '/' + details : ''}`, options);
6774
}
6875

76+
/**
77+
* Gets the current list of available servers. Useful for character search queries.
78+
*/
79+
public getServerList(): Observable<string[]> {
80+
return this.request<string[]>(`${XivapiService.API_BASE_URL}/servers`);
81+
}
82+
83+
/**
84+
* Search for a character on **The Lodestone**. This does not search XIVAPI but instead it goes directly to
85+
* lodestone so the response will be "real-time". Responses are cached for 1 hour,
86+
* it is important to know that Lodestone has a ~6 hour varnish and CDN cache.
87+
*
88+
* @param name The name of the character to search, you can use + for spaces or let the API handle it for you.
89+
* If you search very short names you will get lots of responses.
90+
* This is an issue with The Lodestone and not much XIVAPI can do about it at this time.
91+
* @param server (optional) The server to search against, this is case sensitive.
92+
* You can obtain a list of valid servers via getServerList method.
93+
* @param page Search or move to a specific page.
94+
*/
95+
public searchCharacter(name: string, server?: string, page?: number): Observable<CharacterSearchResult> {
96+
let url: string = `${XivapiService.API_BASE_URL}/character/search?name=${name}`;
97+
if (server !== undefined) {
98+
url += `&world=${server}`;
99+
}
100+
if (page !== undefined) {
101+
url += `&page=${page}`;
102+
}
103+
return this.request<CharacterSearchResult>(url);
104+
}
105+
69106
/**
70107
* Gets character verification informations based on lodestoneId.
71108
*

0 commit comments

Comments
 (0)