Skip to content

Instantly share code, notes, and snippets.

@kakajika
Created July 1, 2015 14:26
Show Gist options
  • Save kakajika/8d7ae20f1ad30af93561 to your computer and use it in GitHub Desktop.
Save kakajika/8d7ae20f1ad30af93561 to your computer and use it in GitHub Desktop.
Type definition file for twat [twitter client for node.js].
// twat.d.ts
declare module "twat" {
var client: Twitter.Client;
export = client;
}
declare module Twitter {
interface AuthParams {
consumer_key: string;
consumer_secret: string;
access_token: string;
access_token_secret: string;
}
interface PostParams {
status: string;
}
interface StreamParams {
track: string;
}
interface User {
created_at: string;
id: number;
id_str: number;
name: string;
screen_name: string;
description?: string;
profile_image_url: string;
profile_background_color: string;
default_profile: boolean;
default_profile_image: boolean;
followers_count: number;
friends_count: number;
listed_count: number;
entities: Entities;
}
interface Tweet {
created_at: string;
id: number;
id_str: number;
text: string;
user: User;
source: string;
lang?: string;
truncated: boolean;
filter_level: string;
retweeted_status: Tweet;
retweet_count: number;
retweeted: boolean;
favorite_count?: number;
favorited?: boolean;
possibly_sensitive?: boolean;
entities: Entities;
}
interface Entities {
hashtags: Hashtag[];
media: Media[];
urls: URL[];
user_mentions: UserMention[];
}
interface Hashtag {
indices: number[];
text: string;
}
interface Media {
indices: number[];
media_url: string;
sizes: Sizes;
type: string;
}
interface Size {
w: number;
h: number;
resize: string;
}
interface Sizes {
thumb: Size;
large: Size;
medium: Size;
small: Size;
}
interface URL {
indices: number[];
url: string;
}
interface UserMention {
indices: number[];
id: number;
id_str: number;
name: string;
screen_name: string;
}
interface Stream {
on(event: 'tweet', callback: (tweet: Tweet) => void): any;
on(event: 'error', callback: (type: string, info: string) => void): any;
on(event: 'reconnect', callback: (info: {error: string, attempts: number}) => void): any;
on(event: 'end', callback: (responce: string) => void): any;
on(event: 'destroy', callback: (msg: string) => void): any;
on(event: string, callback: Function): any;
destroy(): void;
}
interface Client {
new (params: Twitter.AuthParams): Client;
get(path: string, callback: (stream: Stream) => void): any;
post(path: string, params: PostParams, callback: (error: any, tweet: Tweet, responce: any) => void): any;
stream(path: string, params: StreamParams, callback: (stream: Stream) => void): any;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment