instapaper-ts
Version:
A type-safe API client for Instapaper.
130 lines (126 loc) • 3.65 kB
TypeScript
import OAuth from 'oauth-1.0a';
type User = {
type: "user";
user_id: number;
username: string;
};
type Bookmark = {
type: "bookmark";
hash: string;
description: string;
tags: Array<Tag>;
bookmark_id: number;
private_source: string;
title: string;
url: string;
progress_timestamp: number;
time: number;
progress: number;
starred: "0" | "1";
};
type Folder = {
type: "folder";
position: number;
folder_id: number;
title: string;
display_title: string;
slug: string;
sync_to_mobile: 0 | 1;
public: false | 1;
};
type Tag = {
id: number;
name: string;
};
type Highlight = {
type: "highlight";
highlight_id: number;
text: string;
note: string | null;
bookmark_id: Bookmark["bookmark_id"];
time: number;
position: number;
};
type Error = {
type: "error";
error_code: number;
message: string;
};
type Meta = {
type: "meta";
};
type ListParams = Partial<{
limit: number;
folder_id: "unread" | "starred" | "archive" | (string & {});
have: string;
highlights: string;
}>;
type UpdateReadProgressParams = {
bookmark_id: string;
progress: number;
progress_timestamp: number;
};
type AddBookmarkParams = {
url: string;
title?: string;
description?: string;
folder_id?: number;
resolve_final_url?: 0 | 1;
archived?: 0 | 1;
tags?: Array<{
name: string;
}>;
is_private_from_source?: string;
content?: string;
};
type AddHighlightParams = {
bookmark_id: string;
text: string;
position?: number;
};
declare class Instapaper {
private baseUrl;
private authUrl;
private oauth;
private username?;
private password?;
private token?;
constructor({ consumerKey, consumerSecret, username, password, token, }: {
consumerKey: string;
consumerSecret: string;
username?: string;
password?: string;
token?: OAuth.Token;
});
private makeRequest;
fetchToken: () => Promise<OAuth.Token>;
private request;
setCredentials: (username: string, password: string) => void;
withCredentials: (username: string, password: string) => this;
withToken: (token: OAuth.Token) => this;
verifyCredentials: () => Promise<[User]>;
bookmarks: {
list: (params?: ListParams) => Promise<(Bookmark | Folder | User | Error | Meta)[]>;
updateReadProgress: (params: UpdateReadProgressParams) => Promise<[Bookmark]>;
add: (params: AddBookmarkParams) => Promise<[Bookmark]>;
delete: (bookmark_id: Bookmark["bookmark_id"]) => Promise<never[]>;
star: (bookmark_id: Bookmark["bookmark_id"]) => Promise<[Bookmark]>;
unstar: (bookmark_id: Bookmark["bookmark_id"]) => Promise<[Bookmark]>;
archive: (bookmark_id: Bookmark["bookmark_id"]) => Promise<[Bookmark]>;
unarchive: (bookmark_id: Bookmark["bookmark_id"]) => Promise<[Bookmark]>;
move: (bookmark_id: Bookmark["bookmark_id"], folder_id: Folder["folder_id"]) => Promise<[Bookmark]>;
getText: (bookmark_id: Bookmark["bookmark_id"]) => Promise<string>;
};
folders: {
list: () => Promise<Folder[]>;
add: (title: string) => Promise<[Folder]>;
delete: (folder_id: Folder["folder_id"]) => Promise<never[]>;
setOrder: (order: string) => Promise<Folder[]>;
};
highlights: {
list: (bookmark_id: Bookmark["bookmark_id"]) => Promise<Highlight[]>;
add: (params: AddHighlightParams) => Promise<Highlight>;
delete: (highlight_id: string) => Promise<never[]>;
};
}
export { Instapaper };