Skip to content

Commit f8f9840

Browse files
committed
feat: added support for lore search
1 parent 1d3e8fd commit f8f9840

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/model/lore-search-result.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Pagination } from './pagination';
2+
3+
export interface LoreSearchResult {
4+
Results: {
5+
Context: string;
6+
Source: string;
7+
SourceID: number;
8+
Text: string;
9+
};
10+
Pagination: Pagination;
11+
}

src/xivapi.service.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
import { CharacterResponse, CharacterVerification } from './model/schema/character';
1616
import { MarketboardItem } from './model/schema/market/marketboard-item';
1717
import { GCF_URL } from './xivapi-client.module';
18+
import { LoreSearchResult } from './model/lore-search-result';
1819

1920
@Injectable()
2021
export class XivapiService {
@@ -39,6 +40,15 @@ export class XivapiService {
3940
return this.request<T>(`/${endpoint}/${id}`, options);
4041
}
4142

43+
/**
44+
* Makes a request on a given endpoint with an id.
45+
*
46+
* @param query Text to search inside the lore.
47+
*/
48+
public searchLore(query: string): Observable<LoreSearchResult> {
49+
return this.doGet<LoreSearchResult>(`${XivapiService.API_BASE_URL}/lore`, new HttpParams().set('string', query));
50+
}
51+
4252
/**
4353
* Makes a request to a given endpoint to list resources available.
4454
*

test/xivapi.service.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,14 @@ describe('Client tests', () => {
4343
expect(req.request.params.has('url')).toBeTruthy();
4444
expect(req.request.params.get('url')).toEqual('aHR0cHM6Ly94aXZhcGkuY29tL0l0ZW0vMTIwODc=');
4545
});
46+
47+
it('Should search Lore properly', () => {
48+
const service: XivapiService = new XivapiService(httpClient);
49+
service.searchLore('legendary').subscribe();
50+
const req: TestRequest = <TestRequest>httpMock.match({method: 'GET'})
51+
.find(row => row.request.url === `${XivapiService.API_BASE_URL}/lore`);
52+
expect(req).not.toBeUndefined();
53+
expect(req.request.params.has('string')).toBeTruthy();
54+
expect(req.request.params.get('string')).toEqual('legendary');
55+
});
4656
});

0 commit comments

Comments
 (0)