Add models of Telegram API JSON responses.

This commit is contained in:
Danila Fedorin 2018-01-12 16:51:11 -08:00
parent 76381e004a
commit d0a044f3c7
14 changed files with 230 additions and 0 deletions

1
src/telepathy/model.cr Normal file
View File

@ -0,0 +1 @@
require "./model/*"

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,10 @@
require "json"
module Telepathy
class Location
JSON.mapping(
longitude: Float32,
latitude: Float32
)
end
end

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,12 @@
require "json"
module Telepathy
class PhotoSize
JSON.mapping(
file_id: String?,
width: Int64,
height: Int64,
file_size: Int64?
)
end
end

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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