Refactoring InlineQueryResultVideo #232

This commit is contained in:
Leandro Toledo 2016-04-16 13:01:26 -03:00
parent 109af62425
commit 8bf4a6fdda

View file

@ -20,70 +20,24 @@
"""This module contains the classes that represent Telegram """This module contains the classes that represent Telegram
InlineQueryResultVideo""" InlineQueryResultVideo"""
from telegram import InlineQueryResult from telegram import InlineQueryResult, InlineKeyboardMarkup, \
from telegram.utils.validate import validate_string InputMessageContent
class InlineQueryResultVideo(InlineQueryResult): class InlineQueryResultVideo(InlineQueryResult):
"""This object represents a Telegram InlineQueryResultVideo.
Attributes:
id (str):
video_url (str):
mime_type (str):
video_width (int):
video_height (int):
video_duration (int):
thumb_url (str):
title (str):
description (str):
caption (str):
message_text (str):
parse_mode (str):
disable_web_page_preview (bool):
Args:
id (str): Unique identifier for this result, 1-64 Bytes
video_url (str):
mime_type (str):
thumb_url (str):
title (str):
message_text (str):
Keyword Args:
video_width (Optional[int]):
video_height (Optional[int]):
video_duration (Optional[int]):
description (Optional[str]):
caption (Optional[str]):
parse_mode (Optional[str]):
disable_web_page_preview (Optional[bool]):
"""
def __init__(self, def __init__(self,
id, id,
video_url, video_url,
mime_type, mime_type,
thumb_url, thumb_url,
title, title,
message_text, caption=None,
video_width=None, video_width=None,
video_height=None, video_height=None,
video_duration=None, video_duration=None,
description=None, description=None,
caption=None, reply_markup=None,
parse_mode=None, input_message_content=None):
disable_web_page_preview=None,
**kwargs):
validate_string(video_url, 'video_url')
validate_string(mime_type, 'mime_type')
validate_string(thumb_url, 'thumb_url')
validate_string(title, 'title')
validate_string(message_text, 'message_text')
validate_string(description, 'description')
validate_string(caption, 'caption')
validate_string(parse_mode, 'parse_mode')
# Required # Required
super(InlineQueryResultVideo, self).__init__('video', id) super(InlineQueryResultVideo, self).__init__('video', id)
@ -91,30 +45,31 @@ class InlineQueryResultVideo(InlineQueryResult):
self.mime_type = mime_type self.mime_type = mime_type
self.thumb_url = thumb_url self.thumb_url = thumb_url
self.title = title self.title = title
self.message_text = message_text
# Optional # Optional
if video_width is not None: if caption:
self.video_width = int(video_width)
if video_height is not None:
self.video_height = int(video_height)
if video_duration is not None:
self.video_duration = int(video_duration)
self.description = description
self.caption = caption self.caption = caption
self.parse_mode = parse_mode if video_width:
self.disable_web_page_preview = bool(disable_web_page_preview) self.video_width = video_width
if video_height:
self.video_height = video_height
if video_duration:
self.video_duration = video_duration
if description:
self.description = description
if reply_markup:
self.reply_markup = reply_markup
if input_message_content:
self.input_message_content = input_message_content
@staticmethod @staticmethod
def de_json(data): def de_json(data):
""" data = super(InlineQueryResultVideo,
Args: InlineQueryResultVideo).de_json(data)
data (dict):
Returns: data['reply_markup'] = InlineKeyboardMarkup.de_json(
telegram.InlineQueryResultVideo: data.get('reply_markup'))
""" data['input_message_content'] = InputMessageContent.de_json(
if not data: data.get('input_message_content'))
return None
return InlineQueryResultVideo(**data) return InlineQueryResultVideo(**data)