From d0a044f3c7bdc609019304b8de6268825dd55300 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Fri, 12 Jan 2018 16:51:11 -0800 Subject: [PATCH] Add models of Telegram API JSON responses. --- src/telepathy/model.cr | 1 + src/telepathy/model/audio.cr | 14 ++++++ src/telepathy/model/chat.cr | 22 ++++++++++ src/telepathy/model/contact.cr | 12 ++++++ src/telepathy/model/document.cr | 14 ++++++ src/telepathy/model/location.cr | 10 +++++ src/telepathy/model/message.cr | 61 +++++++++++++++++++++++++++ src/telepathy/model/message_entity.cr | 14 ++++++ src/telepathy/model/photo_size.cr | 12 ++++++ src/telepathy/model/user.cr | 14 ++++++ src/telepathy/model/venue.cr | 13 ++++++ src/telepathy/model/video.cr | 16 +++++++ src/telepathy/model/video_note.cr | 14 ++++++ src/telepathy/model/voice.cr | 13 ++++++ 14 files changed, 230 insertions(+) create mode 100644 src/telepathy/model.cr create mode 100644 src/telepathy/model/audio.cr create mode 100644 src/telepathy/model/chat.cr create mode 100644 src/telepathy/model/contact.cr create mode 100644 src/telepathy/model/document.cr create mode 100644 src/telepathy/model/location.cr create mode 100644 src/telepathy/model/message.cr create mode 100644 src/telepathy/model/message_entity.cr create mode 100644 src/telepathy/model/photo_size.cr create mode 100644 src/telepathy/model/user.cr create mode 100644 src/telepathy/model/venue.cr create mode 100644 src/telepathy/model/video.cr create mode 100644 src/telepathy/model/video_note.cr create mode 100644 src/telepathy/model/voice.cr diff --git a/src/telepathy/model.cr b/src/telepathy/model.cr new file mode 100644 index 0000000..e9500af --- /dev/null +++ b/src/telepathy/model.cr @@ -0,0 +1 @@ +require "./model/*" diff --git a/src/telepathy/model/audio.cr b/src/telepathy/model/audio.cr new file mode 100644 index 0000000..2e3e868 --- /dev/null +++ b/src/telepathy/model/audio.cr @@ -0,0 +1,14 @@ +require "json" + +module Telepathy + class Audio + JSON.mapping( + file_id: String, + duration: Int64, + performer: String?, + title: String?, + mime_type: String?, + file_size: Int64? + ) + end +end diff --git a/src/telepathy/model/chat.cr b/src/telepathy/model/chat.cr new file mode 100644 index 0000000..aa47610 --- /dev/null +++ b/src/telepathy/model/chat.cr @@ -0,0 +1,22 @@ +require "json" +require "./message.cr" + +module Telepathy + class Chat + JSON.mapping( + id: Int64, + type: String, + title: String?, + username: String?, + first_name: String?, + last_name: String?, + all_members_are_administrators: Bool?, + # TODO photo + description: String?, + invite_link: String?, + pinned_message: Message?, + sticker_set_name: String?, + can_set_sticker_set: Bool? + ) + end +end diff --git a/src/telepathy/model/contact.cr b/src/telepathy/model/contact.cr new file mode 100644 index 0000000..564858b --- /dev/null +++ b/src/telepathy/model/contact.cr @@ -0,0 +1,12 @@ +require "json" + +module Telepathy + class Contact + JSON.mapping( + phone_number: String, + first_name: String, + last_name: String?, + user_id: Int64? + ) + end +end diff --git a/src/telepathy/model/document.cr b/src/telepathy/model/document.cr new file mode 100644 index 0000000..1fe9754 --- /dev/null +++ b/src/telepathy/model/document.cr @@ -0,0 +1,14 @@ +require "json" +require "./photo_size.cr" + +module Telepathy + class Document + JSON.mapping( + file_id: String, + thumb: PhotoSize?, + file_name: String?, + mime_type: String?, + file_size: Int64? + ) + end +end diff --git a/src/telepathy/model/location.cr b/src/telepathy/model/location.cr new file mode 100644 index 0000000..796aae5 --- /dev/null +++ b/src/telepathy/model/location.cr @@ -0,0 +1,10 @@ +require "json" + +module Telepathy + class Location + JSON.mapping( + longitude: Float32, + latitude: Float32 + ) + end +end diff --git a/src/telepathy/model/message.cr b/src/telepathy/model/message.cr new file mode 100644 index 0000000..f05b25c --- /dev/null +++ b/src/telepathy/model/message.cr @@ -0,0 +1,61 @@ +require "json" +require "./user.cr" +require "./char.cr" +require "./message_entity.cr" +require "./audio.cr" +require "./document.cr" +require "./photo_size.cr" +require "./video.cr" +require "./voice.cr" +require "./video_note.cr" +require "./contact.cr" +require "./location.cr" +require "./venue.cr" + +module Telepathy + class Message + JSON.mapping( + message_id: Int64, + from: User?, + date: Int64, + chat: Chat, + forward_from: User?, + forward_from_chat: Chat?, + forward_from_message_id: Int64?, + forward_signature: String?, + forward_date: Int64?, + reply_to_message: Message?, + edit_date: Int64?, + media_group_id: String?, + author_signature: String?, + text: String?, + entities: Array(MessageEntity)?, + caption_entities: Array(MessageEntity)?, + audio: Audio?, + document: Document?, + photo: Array(PhotoSize)?, + video: Video?, + voice: Voice?, + video_note: VideoNote?, + # TODO game + # TODO sticker + caption: String?, + contact: Contact?, + location: Location?, + venue: Venue?, + new_chat_members: Array(User)?, + left_chat_member: User?, + new_chat_title: String?, + # new_chat_photo + delete_chat_photo: Bool?, + group_chat_created: Bool?, + supergroup_chat_created: Bool?, + channel_chat_created: Bool?, + migrate_to_chat_id: Int64?, + migrate_from_chat_id: Int64?, + pinned_message: Message? + # invoice + # successful_payment + ) + end +end diff --git a/src/telepathy/model/message_entity.cr b/src/telepathy/model/message_entity.cr new file mode 100644 index 0000000..88aad95 --- /dev/null +++ b/src/telepathy/model/message_entity.cr @@ -0,0 +1,14 @@ +require "json" +require "./user.cr" + +module Telepathy + class MessageEntity + JSON.mapping( + type: String, + offset: Int64, + length: Int64, + url: String?, + user: User? + ) + end +end diff --git a/src/telepathy/model/photo_size.cr b/src/telepathy/model/photo_size.cr new file mode 100644 index 0000000..b90075d --- /dev/null +++ b/src/telepathy/model/photo_size.cr @@ -0,0 +1,12 @@ +require "json" + +module Telepathy + class PhotoSize + JSON.mapping( + file_id: String?, + width: Int64, + height: Int64, + file_size: Int64? + ) + end +end diff --git a/src/telepathy/model/user.cr b/src/telepathy/model/user.cr new file mode 100644 index 0000000..cf60651 --- /dev/null +++ b/src/telepathy/model/user.cr @@ -0,0 +1,14 @@ +require "json" + +module Telepathy + class User + JSON.mapping( + id: Int64, + is_bot: Bool, + first_name: String, + last_name: String?, + username: String?, + language_code: String? + ) + end +end diff --git a/src/telepathy/model/venue.cr b/src/telepathy/model/venue.cr new file mode 100644 index 0000000..cabe902 --- /dev/null +++ b/src/telepathy/model/venue.cr @@ -0,0 +1,13 @@ +require "json" +require "./location.cr" + +module Telepathy + class Venue + JSON.mapping( + location: Location, + title: String, + address: String, + foursquare_id: String? + ) + end +end diff --git a/src/telepathy/model/video.cr b/src/telepathy/model/video.cr new file mode 100644 index 0000000..b2a0c28 --- /dev/null +++ b/src/telepathy/model/video.cr @@ -0,0 +1,16 @@ +require "json" +require "./photo_size.cr" + +module Telepathy + class Video + JSON.mapping( + file_id: String, + width: Int64, + height: Int64, + duration: Int64, + thumb: PhotoSize?, + mime_type: String?, + file_size: Int64? + ) + end +end diff --git a/src/telepathy/model/video_note.cr b/src/telepathy/model/video_note.cr new file mode 100644 index 0000000..2906519 --- /dev/null +++ b/src/telepathy/model/video_note.cr @@ -0,0 +1,14 @@ +require "json" +require "./photo_size.cr" + +module Telepathy + class VideoNote + JSON.mapping( + file_id: String, + length: Int64, + duration: Int64, + thumb: PhotoSize?, + file_size: Int64? + ) + end +end diff --git a/src/telepathy/model/voice.cr b/src/telepathy/model/voice.cr new file mode 100644 index 0000000..7cecd40 --- /dev/null +++ b/src/telepathy/model/voice.cr @@ -0,0 +1,13 @@ +require "json" +require "./photo_size.cr" + +module Telepathy + class Voice + JSON.mapping( + file_id: String, + duration: Int64, + mime_type: String?, + file_size: Int64? + ) + end +end