From b6b0a561ca03bed639e14b6b616509b2b51a01cd Mon Sep 17 00:00:00 2001 From: Luke William Westby Date: Sat, 28 Mar 2015 13:20:43 -0500 Subject: [PATCH 1/4] added imgur-api typings --- imgur-api/imgur-api-tests.ts | 103 ++++++++++++++ imgur-api/imgur-api.d.ts | 255 +++++++++++++++++++++++++++++++++++ 2 files changed, 358 insertions(+) create mode 100644 imgur-api/imgur-api-tests.ts create mode 100644 imgur-api/imgur-api.d.ts diff --git a/imgur-api/imgur-api-tests.ts b/imgur-api/imgur-api-tests.ts new file mode 100644 index 000000000..beb21f74e --- /dev/null +++ b/imgur-api/imgur-api-tests.ts @@ -0,0 +1,103 @@ +/// + +function testAccount(account: ImgurApi.Account) : ImgurApi.Account { + return account; +} + +function testAccountSettings(accountSettings: ImgurApi.AccountSettings) : ImgurApi.AccountSettings { + return accountSettings; +} + +function testAlbum(album: ImgurApi.Album) : ImgurApi.Album { + return album; +} + +function testAlbumImages(album: ImgurApi.Album) : ImgurApi.Image { + return album.images[0]; +} + +function testComment(comment: ImgurApi.Comment) : ImgurApi.Comment { + return comment; +} + +function testConversation(conversation: ImgurApi.Conversation) : ImgurApi.Conversation { + return conversation; +} + +function testCustomGallery(customGallery: ImgurApi.CustomGallery) : ImgurApi.CustomGallery { + return customGallery; +} + +function testGalleryItem(galleryItem: ImgurApi.GalleryItem) : ImgurApi.GalleryItem { + return galleryItem; +} + +function testGalleryAlbum(galleryItem: ImgurApi.GalleryItem) : ImgurApi.GalleryAlbum { + if(galleryItem.is_album) { + var galleryAlbum = galleryItem; + return galleryAlbum; + } + return null; +} + +function testGalleryImage(galleryItem: ImgurApi.GalleryItem) : ImgurApi.GalleryImage { + if(!galleryItem.is_album) { + var galleryImage = galleryItem; + return galleryImage; + } + return null; +} + +function testGalleryProfile(galleryProfile: ImgurApi.GalleryProfile) : ImgurApi.GalleryProfile { + return galleryProfile; +} + +function testImage(image: ImgurApi.Image) : ImgurApi.Image { + return image; +} + +function testMemeMeta(meta: ImgurApi.MemeMetadata) : ImgurApi.MemeMetadata { + return meta; +} + +function testMessage(message: ImgurApi.Message) : ImgurApi.Message { + return message; +} + +function testAccountNotificationsReply(accountNotif: ImgurApi.AccountNotifications) : ImgurApi.Notification { + return accountNotif.replies[0]; +} + +function testAccountNotificationsMessage(accountNotif: ImgurApi.AccountNotifications) : ImgurApi.Notification { + return accountNotif.messages[0]; +} + +function testTag(tag: ImgurApi.Tag) : ImgurApi.Tag { + return tag; +} + +function testTagVote(tagVote: ImgurApi.TagVote) : ImgurApi.TagVote { + return tagVote; +} + +function testTopic(topic: ImgurApi.Topic) : ImgurApi.Topic { + return topic; +} + +function testVote(vote: ImgurApi.Vote) : ImgurApi.Vote { + return vote; +} + +function testResponseWithError(response: ImgurApi.Response) : ImgurApi.Error { + if(response.success === false) { + return response.data; + } + return null; +} + +function testResponseWithValue(response: ImgurApi.Response) : ImgurApi.GalleryProfile { + if(response.success === true) { + return response.data; + } + return null; +} diff --git a/imgur-api/imgur-api.d.ts b/imgur-api/imgur-api.d.ts new file mode 100644 index 000000000..0f96707ff --- /dev/null +++ b/imgur-api/imgur-api.d.ts @@ -0,0 +1,255 @@ +// Type definitions for Imgur API v3 +// Project: https://api.imgur.com/ +// Definitions by: Luke William Westby +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module ImgurApi { + + interface Response { + data: any; //T|Error; + status: number; + success: boolean; + } + + interface Account { + id: number; + url: string; + bio: string; + reputation: number; + created: number; + pro_expiration: any; //number|boolean; + } + + interface AccountSettings { + email: string; + high_quality: boolean; + public_images: boolean; + album_privacy: string; + pro_expiration: any; //number|boolean; + accepted_gallery_terms: boolean; + active_emails: Array; + messaging_enabled: boolean; + blocked_users: Array; + } + + /** + * This model represents the data for albums + */ + interface Album { + id: string; + title: string; + description: string; + datetime: number; + cover: string; + cover_width: number; + cover_height: number; + account_url?: string; + account_id?: number; + privacy: string; + layout: string; + views: number; + link: string; + favorite: boolean; + nsfw?: boolean; + section: string; + order: number; + deletehash?: string; + images_count: number; + images: Array; + } + + interface BlockedUser { + blocked_id: number; + blocked_url: string; + } + + interface Comment { + id: number; + image_id: string; + comment: string; + author: string; + author_id: number; + on_album: boolean; + album_cover: string; + ups: number; + downs: number; + points: number; + datetime: number; + parent_id: number; + deleted: boolean; + vote?: string; + children: Array + } + + interface Conversation { + id: number; + last_message_preview: string; + datetime: number; + with_account_id: number; + with_account: string; + message_count: number; + messages?: Array; + done?: boolean; + page?: number; + } + + interface CustomGallery { + account_url: string; + link: string; + tags: Array + item_count: number; + items: Array; + } + + interface GalleryItem { + id: string; + title: string; + description: string; + datetime: number; + account_url?: string; + account_id?: number; + ups: number; + downs: number; + score: number; + is_album: boolean; + views: number; + link: string; + vote?: string; + favorite: boolean; + nsfw?: boolean; + comment_count: number; + topic: string; + topic_id: number; + } + + interface GalleryAlbum extends GalleryItem { + cover: string; + cover_width: number; + cover_height: number; + privacy: string; + layout: string; + images_count: number; + images: Array; + } + + interface GalleryImage extends GalleryItem { + type: string; + animated: boolean; + width: number; + height: number; + size: number; + bandwidth: number; + deletehash?: string; + gifv?: string; + mp4?: string; + webm?: string; + looping?: boolean; + section: string; + } + + interface GalleryProfile { + total_gallery_comments: number; + total_gallery_favorites: number; + total_gallery_submissions: number; + trophies: Array; + } + + interface Trophy { + id: number; + name: string; + name_clean: string; + description: string; + data: string; + data_link: string; + datetime: number; + image: string; + } + + interface Image { + id: string; + title: string; + description: string; + datetime: number; + type: string; + animated: boolean; + width: number; + height: number; + size: number; + views: number; + bandwidth: number; + deletehash?: string; + name?: string; + section: string; + link: string; + gifv?: string; + mp4?: string; + webm?: string; + looping?: boolean; + vote?: string; + favorite: boolean; + nsfw?: boolean; + account_url?: string; + account_id?: number; + } + + interface MemeMetadata { + meme_name: string; + top_text: string; + bottom_text: string; + bg_image: string; + } + + interface Message { + id: number; + from: string; + account_id: number; + sender_id: number; + body: string; + conversation_id: number; + datetime: number; + } + + interface Notification { + id: number; + account_id: number; + viewed: boolean; + content: T; + } + + interface AccountNotifications { + replies: Array>; + messages: Array>; + } + + interface Tag { + name: string; + followers: number; + total_items: number; + following?: boolean; + items: Array + } + + interface TagVote { + ups: number; + downs: number; + name: string; + author: string; + } + + interface Topic { + id: number; + name: string; + description: string; + } + + interface Vote { + ups: number; + downs: number; + } + + interface Error { + error: string; + request: string; + method: string; + } +} From 5908e54415e813ab4d175a86a04bf05ef61f01fd Mon Sep 17 00:00:00 2001 From: Luke William Westby Date: Sat, 28 Mar 2015 13:21:50 -0500 Subject: [PATCH 2/4] removing stray doc comment, will add doc comments later --- imgur-api/imgur-api.d.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/imgur-api/imgur-api.d.ts b/imgur-api/imgur-api.d.ts index 0f96707ff..c25cd8acb 100644 --- a/imgur-api/imgur-api.d.ts +++ b/imgur-api/imgur-api.d.ts @@ -32,9 +32,6 @@ declare module ImgurApi { blocked_users: Array; } - /** - * This model represents the data for albums - */ interface Album { id: string; title: string; From c4076573bbc56c95ec4ad206a7b4584036a18800 Mon Sep 17 00:00:00 2001 From: Luke William Westby Date: Thu, 2 Apr 2015 10:58:56 -0500 Subject: [PATCH 3/4] renamed imgur-api to imgur-rest-api --- .../imgur-rest-api-tests.ts | 0 imgur-api/imgur-api.d.ts => imgur-rest-api/imgur-rest-api.d.ts | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename imgur-api/imgur-api-tests.ts => imgur-rest-api/imgur-rest-api-tests.ts (100%) rename imgur-api/imgur-api.d.ts => imgur-rest-api/imgur-rest-api.d.ts (99%) diff --git a/imgur-api/imgur-api-tests.ts b/imgur-rest-api/imgur-rest-api-tests.ts similarity index 100% rename from imgur-api/imgur-api-tests.ts rename to imgur-rest-api/imgur-rest-api-tests.ts diff --git a/imgur-api/imgur-api.d.ts b/imgur-rest-api/imgur-rest-api.d.ts similarity index 99% rename from imgur-api/imgur-api.d.ts rename to imgur-rest-api/imgur-rest-api.d.ts index c25cd8acb..c06bff5e5 100644 --- a/imgur-api/imgur-api.d.ts +++ b/imgur-rest-api/imgur-rest-api.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Imgur API v3 +// Type definitions for Imgur REST API v3 // Project: https://api.imgur.com/ // Definitions by: Luke William Westby // Definitions: https://github.com/borisyankov/DefinitelyTyped From b9d7ffce3429e2de826c6332a1aab356884fc4cb Mon Sep 17 00:00:00 2001 From: Luke William Westby Date: Thu, 2 Apr 2015 11:01:29 -0500 Subject: [PATCH 4/4] renamed module ImgurApi to ImgurRestApi as well --- imgur-rest-api/imgur-rest-api-tests.ts | 54 +++++++++++++------------- imgur-rest-api/imgur-rest-api.d.ts | 2 +- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/imgur-rest-api/imgur-rest-api-tests.ts b/imgur-rest-api/imgur-rest-api-tests.ts index beb21f74e..247885557 100644 --- a/imgur-rest-api/imgur-rest-api-tests.ts +++ b/imgur-rest-api/imgur-rest-api-tests.ts @@ -1,103 +1,103 @@ -/// +/// -function testAccount(account: ImgurApi.Account) : ImgurApi.Account { +function testAccount(account: ImgurRestApi.Account) : ImgurRestApi.Account { return account; } -function testAccountSettings(accountSettings: ImgurApi.AccountSettings) : ImgurApi.AccountSettings { +function testAccountSettings(accountSettings: ImgurRestApi.AccountSettings) : ImgurRestApi.AccountSettings { return accountSettings; } -function testAlbum(album: ImgurApi.Album) : ImgurApi.Album { +function testAlbum(album: ImgurRestApi.Album) : ImgurRestApi.Album { return album; } -function testAlbumImages(album: ImgurApi.Album) : ImgurApi.Image { +function testAlbumImages(album: ImgurRestApi.Album) : ImgurRestApi.Image { return album.images[0]; } -function testComment(comment: ImgurApi.Comment) : ImgurApi.Comment { +function testComment(comment: ImgurRestApi.Comment) : ImgurRestApi.Comment { return comment; } -function testConversation(conversation: ImgurApi.Conversation) : ImgurApi.Conversation { +function testConversation(conversation: ImgurRestApi.Conversation) : ImgurRestApi.Conversation { return conversation; } -function testCustomGallery(customGallery: ImgurApi.CustomGallery) : ImgurApi.CustomGallery { +function testCustomGallery(customGallery: ImgurRestApi.CustomGallery) : ImgurRestApi.CustomGallery { return customGallery; } -function testGalleryItem(galleryItem: ImgurApi.GalleryItem) : ImgurApi.GalleryItem { +function testGalleryItem(galleryItem: ImgurRestApi.GalleryItem) : ImgurRestApi.GalleryItem { return galleryItem; } -function testGalleryAlbum(galleryItem: ImgurApi.GalleryItem) : ImgurApi.GalleryAlbum { +function testGalleryAlbum(galleryItem: ImgurRestApi.GalleryItem) : ImgurRestApi.GalleryAlbum { if(galleryItem.is_album) { - var galleryAlbum = galleryItem; + var galleryAlbum = galleryItem; return galleryAlbum; } return null; } -function testGalleryImage(galleryItem: ImgurApi.GalleryItem) : ImgurApi.GalleryImage { +function testGalleryImage(galleryItem: ImgurRestApi.GalleryItem) : ImgurRestApi.GalleryImage { if(!galleryItem.is_album) { - var galleryImage = galleryItem; + var galleryImage = galleryItem; return galleryImage; } return null; } -function testGalleryProfile(galleryProfile: ImgurApi.GalleryProfile) : ImgurApi.GalleryProfile { +function testGalleryProfile(galleryProfile: ImgurRestApi.GalleryProfile) : ImgurRestApi.GalleryProfile { return galleryProfile; } -function testImage(image: ImgurApi.Image) : ImgurApi.Image { +function testImage(image: ImgurRestApi.Image) : ImgurRestApi.Image { return image; } -function testMemeMeta(meta: ImgurApi.MemeMetadata) : ImgurApi.MemeMetadata { +function testMemeMeta(meta: ImgurRestApi.MemeMetadata) : ImgurRestApi.MemeMetadata { return meta; } -function testMessage(message: ImgurApi.Message) : ImgurApi.Message { +function testMessage(message: ImgurRestApi.Message) : ImgurRestApi.Message { return message; } -function testAccountNotificationsReply(accountNotif: ImgurApi.AccountNotifications) : ImgurApi.Notification { +function testAccountNotificationsReply(accountNotif: ImgurRestApi.AccountNotifications) : ImgurRestApi.Notification { return accountNotif.replies[0]; } -function testAccountNotificationsMessage(accountNotif: ImgurApi.AccountNotifications) : ImgurApi.Notification { +function testAccountNotificationsMessage(accountNotif: ImgurRestApi.AccountNotifications) : ImgurRestApi.Notification { return accountNotif.messages[0]; } -function testTag(tag: ImgurApi.Tag) : ImgurApi.Tag { +function testTag(tag: ImgurRestApi.Tag) : ImgurRestApi.Tag { return tag; } -function testTagVote(tagVote: ImgurApi.TagVote) : ImgurApi.TagVote { +function testTagVote(tagVote: ImgurRestApi.TagVote) : ImgurRestApi.TagVote { return tagVote; } -function testTopic(topic: ImgurApi.Topic) : ImgurApi.Topic { +function testTopic(topic: ImgurRestApi.Topic) : ImgurRestApi.Topic { return topic; } -function testVote(vote: ImgurApi.Vote) : ImgurApi.Vote { +function testVote(vote: ImgurRestApi.Vote) : ImgurRestApi.Vote { return vote; } -function testResponseWithError(response: ImgurApi.Response) : ImgurApi.Error { +function testResponseWithError(response: ImgurRestApi.Response) : ImgurRestApi.Error { if(response.success === false) { - return response.data; + return response.data; } return null; } -function testResponseWithValue(response: ImgurApi.Response) : ImgurApi.GalleryProfile { +function testResponseWithValue(response: ImgurRestApi.Response) : ImgurRestApi.GalleryProfile { if(response.success === true) { - return response.data; + return response.data; } return null; } diff --git a/imgur-rest-api/imgur-rest-api.d.ts b/imgur-rest-api/imgur-rest-api.d.ts index c06bff5e5..272600656 100644 --- a/imgur-rest-api/imgur-rest-api.d.ts +++ b/imgur-rest-api/imgur-rest-api.d.ts @@ -3,7 +3,7 @@ // Definitions by: Luke William Westby // Definitions: https://github.com/borisyankov/DefinitelyTyped -declare module ImgurApi { +declare module ImgurRestApi { interface Response { data: any; //T|Error;