1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Resolve merge conflicts.

This commit is contained in:
pieter
2015-07-02 13:54:45 +02:00
4 changed files with 26 additions and 2 deletions

View File

@ -28,6 +28,7 @@ class JsonSerializable:
Subclasses of this class are guaranteed to be able to be converted to JSON format.
All subclasses of this class must override to_json.
"""
def to_json(self):
"""
Returns a JSON string representation of this class.
@ -134,6 +135,9 @@ class Message(JsonDeserializable):
if 'location' in obj:
opts['location'] = Location.de_json(obj['location'])
content_type = 'location'
if 'contact' in obj:
opts['contact'] = Contact.de_json(json.dumps(obj['contact']))
content_type = 'contact'
return Message(message_id, from_user, date, chat, content_type, opts)
@classmethod
@ -280,6 +284,18 @@ class Video(JsonDeserializable):
class Contact:
@classmethod
def de_json(cls, json_string):
obj = json.loads(json_string)
phone_number = obj['phone_number']
first_name = obj['first_name']
last_name = None
if 'last_name' in obj:
last_name = obj['last_name']
if 'user_id' in obj:
user_id = obj['user_id']
return Contact(phone_number, first_name, last_name, user_id)
def __init__(self, phone_number, first_name, last_name=None, user_id=None):
self.phone_number = phone_number
self.first_name = first_name