strava-api-handler
Version:
Unofficial handler for Strava API
66 lines (65 loc) • 2.64 kB
TypeScript
/// <reference types="node" />
import { Api as ApiBase, ApiResponseType } from 'rest-api-handler';
import Activity from './Activity';
import * as STREAM from './streams';
import { ActivityFilters } from './types/ActivityFilters';
import { ApiActivity } from './types/api/Activity';
declare type Scope = 'read' | 'read_all' | 'profile:read_all' | 'profile:write' | 'activity:read' | 'activity:read_all' | 'activity:write';
declare type Prompt = 'force' | 'auto';
interface Athlete {
badge_type_id: number;
city: string;
country: string;
created_at: string;
email: string;
firstname: string;
follower: string | undefined;
friend: string | undefined;
id: number;
lastname: string;
premium: boolean;
profile: string;
profile_medium: string;
resource_state: number;
sex: string;
state: string;
updated_at: string;
username: string;
}
interface Token {
access_token: string;
athlete: Athlete;
expires_at: number;
expires_in: number;
refresh_token: string;
token_type: string;
}
interface UploadStatus {
activity_id: number | undefined;
error: string | undefined;
external_id: string;
id: number;
status: string;
}
export default class Api extends ApiBase<ApiResponseType<any>> {
protected clientId: string;
protected secret: string;
protected accessToken?: string;
constructor(clientId: string, secret: string);
setAccessToken(token: string): void;
getAccessToken(): string | undefined;
getLoginUrl(redirectUri: string, scope?: Scope[], approvalPrompt?: Prompt, state?: string): string;
protected requestToken(parameters: Record<string, string>): Promise<Token>;
requestAccessToken(code: string): Promise<Token>;
refreshToken(token: string): Promise<Token>;
getActivity(id: number): Promise<Activity<number, ApiActivity>>;
getStream(id: number, streams?: STREAM.Stream[]): Promise<any[]>;
getActivities(parameters: ActivityFilters): Promise<any>;
processActivities(filter: ActivityFilters | undefined, processor: (workout: Activity<number, ApiActivity>) => Promise<Activity<number, ApiActivity>>): Promise<Activity<number, ApiActivity>[]>;
uploadActivity(activity: Activity, fileContent: string | Buffer, externalId: string | number, dataType?: string): Promise<UploadStatus>;
getUploadStatus(uploadId: number): Promise<UploadStatus>;
createActivity(activity: Activity<undefined, undefined>): Promise<Activity<number, ApiActivity>>;
updateActivity(activity: Activity<number>): Promise<Activity>;
updateWeight(weight: number): Promise<Athlete>;
}
export {};