Skip to content

Commit

Permalink
Fixes #12 and changes to_data to to_dict
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrotoledo committed Jul 20, 2015
1 parent 859f04e commit f4ad703
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion telegram/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def de_json(data):
mime_type=data.get('mime_type', None),
file_size=data.get('file_size', None))

def to_data(self):
def to_dict(self):
data = {'file_id': self.file_id,
'duration': self.duration}
if self.mime_type:
Expand Down
6 changes: 3 additions & 3 deletions telegram/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TelegramObject(object):
__metaclass__ = ABCMeta

def __str__(self):
return self.to_data()
return str(self.to_dict())

def __getitem__(self, item):
return self.__dict__[item]
Expand All @@ -21,8 +21,8 @@ def de_json(data):
raise NotImplementedError

def to_json(self):
return json.dumps(self.to_data())
return json.dumps(self.to_dict())

@abstractmethod
def to_data(self):
def to_dict(self):
return
2 changes: 1 addition & 1 deletion telegram/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def de_json(data):
last_name=data.get('last_name', None),
user_id=data.get('user_id', None))

def to_data(self):
def to_dict(self):
data = {'phone_number': self.phone_number,
'first_name': self.first_name}
if self.last_name:
Expand Down
4 changes: 2 additions & 2 deletions telegram/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def de_json(data):
mime_type=data.get('mime_type', None),
file_size=data.get('file_size', None))

def to_data(self):
def to_dict(self):
data = {'file_id': self.file_id,
'thumb': self.thumb.to_data()}
'thumb': self.thumb.to_dict()}
if self.file_name:
data['file_name'] = self.file_name
if self.mime_type:
Expand Down
2 changes: 1 addition & 1 deletion telegram/forcereply.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def de_json(data):
return ForceReply(force_reply=data.get('force_reply', None),
selective=data.get('selective', None))

def to_data(self):
def to_dict(self):
data = {'force_reply': self.force_reply}
if self.selective:
data['selective'] = self.selective
Expand Down
2 changes: 1 addition & 1 deletion telegram/groupchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def de_json(data):
return GroupChat(id=data.get('id', None),
title=data.get('title', None))

def to_data(self):
def to_dict(self):
data = {'id': self.id,
'title': self.title}
return data
2 changes: 1 addition & 1 deletion telegram/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def de_json(data):
return Location(longitude=data.get('longitude', None),
latitude=data.get('latitude', None))

def to_data(self):
def to_dict(self):
data = {'longitude': self.longitude,
'latitude': self.latitude}
return data
20 changes: 10 additions & 10 deletions telegram/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ def de_json(data):
delete_chat_photo=data.get('delete_chat_photo', None),
group_chat_created=data.get('group_chat_created', None))

def to_data(self):
def to_dict(self):
data = {'message_id': self.message_id,
'from': self.from_user.to_data(),
'from': self.from_user.to_dict(),
'date': self.date,
'chat': self.chat.to_data()}
'chat': self.chat.to_dict()}
if self.forward_from:
data['forward_from'] = self.forward_from
if self.forward_date:
Expand All @@ -177,19 +177,19 @@ def to_data(self):
if self.text:
data['text'] = self.text
if self.audio:
data['audio'] = self.audio.to_data()
data['audio'] = self.audio.to_dict()
if self.document:
data['document'] = self.document.to_data()
data['document'] = self.document.to_dict()
if self.photo:
data['photo'] = self.photo.to_data()
data['photo'] = [p.to_dict() for p in self.photo]
if self.sticker:
data['sticker'] = self.sticker.to_data()
data['sticker'] = self.sticker.to_dict()
if self.video:
data['video'] = self.video.to_data()
data['video'] = self.video.to_dict()
if self.contact:
data['contact'] = self.contact.to_data()
data['contact'] = self.contact.to_dict()
if self.location:
data['location'] = self.location.to_data()
data['location'] = self.location.to_dict()
if self.new_chat_participant:
data['new_chat_participant'] = self.new_chat_participant
if self.left_chat_participant:
Expand Down
2 changes: 1 addition & 1 deletion telegram/photosize.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def de_json(data):
height=data.get('height', None),
file_size=data.get('file_size', None))

def to_data(self):
def to_dict(self):
data = {'file_id': self.file_id,
'width': self.width,
'height': self.height}
Expand Down
2 changes: 1 addition & 1 deletion telegram/replykeyboardhide.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def de_json(data):
return ReplyKeyboardHide(hide_keyboard=data.get('hide_keyboard', None),
selective=data.get('selective', None))

def to_data(self):
def to_dict(self):
data = {'hide_keyboard': self.hide_keyboard}
if self.selective:
data['selective'] = self.selective
Expand Down
2 changes: 1 addition & 1 deletion telegram/replykeyboardmarkup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def de_json(data):
),
selective=data.get('selective', None))

def to_data(self):
def to_dict(self):
data = {'keyboard': self.keyboard}
if self.resize_keyboard:
data['resize_keyboard'] = self.resize_keyboard
Expand Down
4 changes: 2 additions & 2 deletions telegram/sticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ def de_json(data):
thumb=thumb,
file_size=data.get('file_size', None))

def to_data(self):
def to_dict(self):
data = {'file_id': self.file_id,
'width': self.width,
'height': self.height,
'thumb': self.thumb.to_data()}
'thumb': self.thumb.to_dict()}
if self.file_size:
data['file_size'] = self.file_size
return data
4 changes: 2 additions & 2 deletions telegram/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def de_json(data):
return Update(update_id=data.get('update_id', None),
message=message)

def to_data(self):
def to_dict(self):
data = {'update_id': self.update_id}
if self.message:
data['message'] = self.message.to_data()
data['message'] = self.message.to_dict()
return data
2 changes: 1 addition & 1 deletion telegram/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def de_json(data):
last_name=data.get('last_name', None),
username=data.get('username', None))

def to_data(self):
def to_dict(self):
data = {'id': self.id,
'first_name': self.first_name}
if self.last_name:
Expand Down
4 changes: 2 additions & 2 deletions telegram/userprofilephotos.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ def de_json(data):
return UserProfilePhotos(total_count=data.get('total_count', None),
photos=photos)

def to_data(self):
def to_dict(self):
data = {}
if self.total_count:
data['total_count'] = self.total_count
if self.photos:
data['photos'] = []
for photo in self.photos:
data['photos'].append([x.to_data() for x in photo])
data['photos'].append([x.to_dict() for x in photo])
return data
4 changes: 2 additions & 2 deletions telegram/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ def de_json(data):
file_size=data.get('file_size', None),
caption=data.get('caption', None))

def to_data(self):
def to_dict(self):
data = {'file_id': self.file_id,
'width': self.width,
'height': self.height,
'duration': self.duration,
'thumb': self.thumb.to_data()}
'thumb': self.thumb.to_dict()}
if self.mime_type:
data['mime_type'] = self.mime_type
if self.file_size:
Expand Down

0 comments on commit f4ad703

Please sign in to comment.