[giphy-api] Add types

This commit is contained in:
Christian Rackerseder
2019-02-07 10:32:12 +01:00
parent 0b417416fe
commit 18e80f42e7
4 changed files with 247 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
import giphyApi = require('giphy-api');
const cb = (err: Error, res: any) => {};
giphyApi('API KEY HERE');
giphyApi({ https: true });
giphyApi({ timeout: 60 });
giphyApi({ apiKey: 'API KEY' });
const giphy = giphyApi();
giphy.search('pokemon', cb);
giphy.search('pokemon').then(res => {});
giphy.search({ q: 'pokemon', rating: 'g' }, cb);
giphy.search({ q: 'pokemon', rating: 'g' }).then(res => {});
giphy.id('feqkVgjJpYtjy', cb);
giphy.id('feqkVgjJpYtjy').then(res => {});
giphy.id(['feqkVgjJpYtjy'], cb);
giphy.id(['feqkVgjJpYtjy']).then(res => {});
giphy.translate('superman', cb);
giphy.translate('superman').then(res => {});
giphy.translate({ s: 'superman', rating: 'g', fmt: 'html' }, cb);
giphy.translate({ s: 'superman', rating: 'g' }).then(res => {});
giphy.random('superman', cb);
giphy.random('superman').then(res => {});
giphy.random({ tag: 'superman', rating: 'g' }, cb);
giphy.random({ tag: 'superman', rating: 'g' }).then(res => {});
giphy.trending(cb);
giphy.trending().then(res => {});
giphy.trending({ limit: 2, rating: 'g' });
giphy.trending({ limit: 2, rating: 'g' }).then(res => {});
+189
View File
@@ -0,0 +1,189 @@
// Type definitions for giphy-api 2.0
// Project: https://github.com/austinkelleher/giphy-api
// Definitions by: Christian Rackerseder <https://github.com/screendriver>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
type Rating = "y" | "g" | "pg" | "pg-13" | "r";
type Format = "html" | "json";
interface GiphyOptions {
https?: boolean;
timeout?: number;
apiKey?: string;
}
interface BaseOptions {
rating: Rating;
fmt?: Format;
}
interface SearchOptions extends BaseOptions {
q: string;
limit?: number;
offset?: number;
}
interface TranslateOptions extends BaseOptions {
s: string;
}
interface RandomOptions extends BaseOptions {
tag: string;
}
interface TrendingOptions extends BaseOptions {
limit?: number;
}
interface BaseImage {
url: string;
width: string;
height: string;
}
interface Result {
data: [
{
type: "gif";
id: string;
slug: string;
url: string;
bitly_gif_url: string;
bitly_url: string;
embed_url: string;
username: string;
source: string;
rating: Rating;
content_url: string;
source_tld: string;
source_post_url: string;
is_sticker: number;
import_datetime: string;
trending_datetime: string;
images: {
fixed_height_still: BaseImage;
original_still: BaseImage;
fixed_width: BaseImage & {
size: string;
mp4: string;
mp4_size: string;
webp: string;
webp_size: string;
};
fixed_height_small_still: BaseImage;
fixed_height_downsampled: BaseImage & {
size: string;
webp: string;
webp_size: string;
};
preview: {
width: string;
height: string;
mp4: string;
mp4_size: string;
};
fixed_height_small: BaseImage & {
size: string;
mp4: string;
mp4_size: string;
webp: string;
webp_size: string;
};
downsized_still: BaseImage & {
size: string;
};
downsized: BaseImage & {
size: string;
};
downsized_large: BaseImage & {
size: string;
};
fixed_width_small_still: BaseImage;
preview_webp: BaseImage & {
size: string;
};
fixed_width_still: BaseImage;
fixed_width_small: BaseImage & {
size: string;
mp4: string;
mp4_size: string;
webp: string;
webp_size: string;
};
downsized_small: {
width: string;
height: string;
mp4: string;
mp4_size: string;
};
fixed_width_downsampled: BaseImage & {
size: string;
webp: string;
webp_size: string;
};
downsized_medium: BaseImage & {
size: string;
};
original: BaseImage & {
size: string;
frames: string;
mp4: string;
mp4_size: string;
webp: string;
webp_size: string;
};
fixed_height: BaseImage & {
size: string;
mp4: string;
mp4_size: string;
webp: string;
webp_size: string;
};
looping: { mp4: string; mp4_size: string };
original_mp4: {
width: string;
height: string;
mp4: string;
mp4_size: string;
};
preview_gif: BaseImage & {
size: string;
};
title: string;
_score: number;
analytics: {
onload: { url: string };
onclick: { url: string };
onsent: { url: string };
};
};
}
];
pagination: { total_count: number; count: number; offset: number };
meta: {
status: number;
msg: string;
response_id: string;
};
}
type Callback = (err: Error, res: Result) => void;
interface Giphy {
search(queryOrOptions: string | SearchOptions, cb: Callback): void;
search(queryOrOptions: string | SearchOptions): Promise<Result>;
id(ids: string | string[], cb: Callback): void;
id(ids: string | string[]): Promise<Result>;
translate(termOrOptions: string | TranslateOptions, cb: Callback): void;
translate(termOrOptions: string | TranslateOptions): Promise<Result>;
random(tagOrOptions: string | RandomOptions, cb: Callback): void;
random(tagOrOptions: string | RandomOptions): Promise<Result>;
trending(options: TrendingOptions, cb: Callback): void;
trending(cb: Callback): void;
trending(options?: TrendingOptions): Promise<Result>;
}
declare function giphyApi(apiKeyOrOptions?: string | GiphyOptions): Giphy;
export = giphyApi;
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"giphy-api-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }