|
1 | 1 | import { Inject, Injectable } from '@angular/core'; |
2 | 2 | import { HttpClient, HttpParams } from '@angular/common/http'; |
3 | 3 | 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'; |
5 | 13 | 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'; |
8 | 15 |
|
9 | 16 | @Injectable() |
10 | 17 | export class XivapiService { |
@@ -66,6 +73,36 @@ export class XivapiService { |
66 | 73 | return this.request<any>(`${XivapiService.API_BASE_URL}/Character/${lodestoneId}${details ? '/' + details : ''}`, options); |
67 | 74 | } |
68 | 75 |
|
| 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 | + |
69 | 106 | /** |
70 | 107 | * Gets character verification informations based on lodestoneId. |
71 | 108 | * |
|
0 commit comments