Merge pull request #32981 from screendriver/giphy-api

[giphy-api] Introduce namespace to make some types public available
This commit is contained in:
Armando Aguirre
2019-02-12 12:41:50 -08:00
committed by GitHub
2 changed files with 147 additions and 143 deletions
+5 -3
View File
@@ -2,15 +2,17 @@ import giphyApi = require('giphy-api');
const cb = (err: Error, res: any) => {};
const apiOptions: giphyApi.GiphyOptions = { https: true };
giphyApi('API KEY HERE');
giphyApi({ https: true });
giphyApi(apiOptions);
giphyApi({ timeout: 60 });
giphyApi({ apiKey: 'API KEY' });
const giphy = giphyApi();
const searchOptions: giphyApi.SearchOptions = { q: 'pokemon', rating: 'g' };
const giphy: giphyApi.Giphy = giphyApi();
giphy.search('pokemon', cb);
giphy.search('pokemon').then(res => {});
giphy.search({ q: 'pokemon', rating: 'g' }, cb);
giphy.search(searchOptions, cb);
giphy.search({ q: 'pokemon', rating: 'g' }).then(res => {});
giphy.id('feqkVgjJpYtjy', cb);
+142 -140
View File
@@ -7,23 +7,11 @@
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;
}
@@ -42,136 +30,150 @@ interface BaseImage {
height: string;
}
interface Result {
data: [
{
type: string;
id: string;
slug: string;
url: string;
bitly_url: string;
embed_url: string;
username: string;
source: string;
rating: Rating;
content_url: string;
user?: {
avatar_url: string;
banner_url: string;
profile_url: string;
type Callback = (err: Error, res: giphyApi.Result) => void;
declare function giphyApi(apiKeyOrOptions?: string | giphyApi.GiphyOptions): giphyApi.Giphy;
declare namespace giphyApi {
interface GiphyOptions {
https?: boolean;
timeout?: number;
apiKey?: string;
}
interface SearchOptions extends BaseOptions {
q: string;
limit?: number;
offset?: number;
}
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>;
}
interface Result {
data: [
{
type: string;
id: string;
slug: string;
url: string;
bitly_url: string;
embed_url: string;
username: string;
display_name: string;
twitter: string;
},
source_tld: string;
source_post_url: string;
update_datetime: string;
create_datetime: string;
import_datetime: string;
trending_datetime: string;
title: string;
images: {
fixed_height: BaseImage & {
size: string;
mp4: string;
mp4_size: string;
webp: string;
webp_size: string;
source: string;
rating: Rating;
content_url: string;
user?: {
avatar_url: string;
banner_url: string;
profile_url: string;
username: string;
display_name: string;
twitter: string;
},
source_tld: string;
source_post_url: string;
update_datetime: string;
create_datetime: string;
import_datetime: string;
trending_datetime: string;
title: string;
images: {
fixed_height: BaseImage & {
size: string;
mp4: string;
mp4_size: string;
webp: string;
webp_size: string;
};
fixed_height_still: BaseImage;
fixed_height_downsampled: BaseImage & {
size: string;
webp: string;
webp_size: string;
};
fixed_width: BaseImage & {
size: string;
mp4: string;
mp4_size: string;
webp: string;
webp_size: string;
};
original_still: BaseImage;
fixed_width_still: BaseImage;
fixed_width_downsampled: BaseImage & {
size: string;
webp: string;
webp_size: string;
};
fixed_height_small: BaseImage & {
size: string;
mp4: string;
mp4_size: string;
webp: string;
webp_size: string;
};
fixed_height_small_still: BaseImage;
fixed_width_small: BaseImage & {
size: string;
mp4: string;
mp4_size: string;
webp: string;
webp_size: string;
};
fixed_width_small_still: BaseImage;
downsized: BaseImage & {
size: string;
};
downsized_still: BaseImage;
downsized_large: BaseImage & {
size: string;
};
downsized_medium: BaseImage & {
size: string;
};
downsized_small: BaseImage & {
size: string;
};
original: BaseImage & {
size: string;
frames: string;
mp4: string;
mp4_size: string;
webp: string;
webp_size: string;
};
looping: { mp4: string; };
preview: {
width: string;
height: string;
mp4: string;
mp4_size: string;
};
preview_gif: BaseImage & {
size: string;
};
};
fixed_height_still: BaseImage;
fixed_height_downsampled: BaseImage & {
size: string;
webp: string;
webp_size: string;
};
fixed_width: BaseImage & {
size: string;
mp4: string;
mp4_size: string;
webp: string;
webp_size: string;
};
original_still: BaseImage;
fixed_width_still: BaseImage;
fixed_width_downsampled: BaseImage & {
size: string;
webp: string;
webp_size: string;
};
fixed_height_small: BaseImage & {
size: string;
mp4: string;
mp4_size: string;
webp: string;
webp_size: string;
};
fixed_height_small_still: BaseImage;
fixed_width_small: BaseImage & {
size: string;
mp4: string;
mp4_size: string;
webp: string;
webp_size: string;
};
fixed_width_small_still: BaseImage;
downsized: BaseImage & {
size: string;
};
downsized_still: BaseImage;
downsized_large: BaseImage & {
size: string;
};
downsized_medium: BaseImage & {
size: string;
};
downsized_small: BaseImage & {
size: string;
};
original: BaseImage & {
size: string;
frames: string;
mp4: string;
mp4_size: string;
webp: string;
webp_size: string;
};
looping: { mp4: string; };
preview: {
width: string;
height: string;
mp4: string;
mp4_size: string;
};
preview_gif: BaseImage & {
size: string;
};
};
}
];
pagination: { total_count: number; count: number; offset: number };
meta: {
status: number;
msg: string;
response_id: 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;