Skip to content

Commit

Permalink
feat: Update trends api
Browse files Browse the repository at this point in the history
  • Loading branch information
neet committed Apr 3, 2022
1 parent 8621213 commit 3d1d236
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/entities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export * from './history';
export * from './identity-proof';
export * from './instance';
export * from './field';
export * from './link';
export * from './list';
export * from './marker';
export * from './mention';
Expand Down
6 changes: 6 additions & 0 deletions src/entities/link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Card } from './card';
import { History } from './history';

export interface Link extends Card {
history: History[];
}
3 changes: 2 additions & 1 deletion src/paginator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Http } from './http';
import { Response } from './http/http';

export class Paginator<Params, Result>
implements AsyncIterableIterator<Result> {
implements AsyncIterableIterator<Result>
{
private nextUrl?: string;
private nextParams?: Params;

Expand Down
29 changes: 26 additions & 3 deletions src/repositories/trend-repository.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { version } from '../decorators';
import { Tag } from '../entities';
import { Link, Status, Tag } from '../entities';
import { Http } from '../http';
import { Repository } from '../repository';
import { Paginator } from '../paginator';
import { DefaultPaginationParams, Repository } from '../repository';

export interface FetchTrendsParams {
/** Maximum number of results to return. Defaults to 10. */
Expand All @@ -11,6 +12,28 @@ export interface FetchTrendsParams {
export class TrendRepository implements Repository<Tag> {
constructor(private readonly http: Http, readonly version: string) {}

get statuses(): Paginator<DefaultPaginationParams, Status[]> {
return this.getStatuses();
}

get links(): Paginator<DefaultPaginationParams, Link[]> {
return this.getLinks();
}

@version({ since: '3.5.0' })
getStatuses(
params?: DefaultPaginationParams,
): Paginator<DefaultPaginationParams, Status[]> {
return new Paginator(this.http, '/api/v1/trends/statuses', params);
}

@version({ since: '3.5.0' })
getLinks(
params?: DefaultPaginationParams,
): Paginator<DefaultPaginationParams, Link[]> {
return new Paginator(this.http, '/api/v1/trends/links', params);
}

/**
* Tags that are being used more frequently within the past week.
* @param params Parameters
Expand All @@ -19,6 +42,6 @@ export class TrendRepository implements Repository<Tag> {
*/
@version({ since: '3.0.0' })
fetchAll(params?: FetchTrendsParams): Promise<Tag[]> {
return this.http.get<Tag[]>('/api/v1/trends', params);
return this.http.get<Tag[]>('/api/v1/trends/tags', params);
}
}

0 comments on commit 3d1d236

Please sign in to comment.