33
44
55class ApiModel (object ):
6-
76 @classmethod
87 def object_from_dictionary (cls , entry ):
98 # make dict keys all strings
109 if entry is None :
1110 return ""
11+
1212 entry_str_dict = dict ([(str (key ), value ) for key , value in entry .items ()])
1313 return cls (** entry_str_dict )
1414
1515 def __repr__ (self ):
1616 return str (self )
17- # if six.PY2:
18- # return six.text_type(self).encode('utf8')
19- # else:
20- # return self.encode('utf8')
2117
2218 def __str__ (self ):
2319 if six .PY3 :
@@ -27,7 +23,6 @@ def __str__(self):
2723
2824
2925class Image (ApiModel ):
30-
3126 def __init__ (self , url , width , height ):
3227 self .url = url
3328 self .height = height
@@ -38,13 +33,11 @@ def __unicode__(self):
3833
3934
4035class Video (Image ):
41-
4236 def __unicode__ (self ):
4337 return "Video: %s" % self .url
4438
4539
4640class Media (ApiModel ):
47-
4841 def __init__ (self , id = None , ** kwargs ):
4942 self .id = id
5043 for key , value in six .iteritems (kwargs ):
@@ -62,19 +55,16 @@ def get_low_resolution_url(self):
6255 else :
6356 return self .videos ['low_resolution' ].url
6457
65-
6658 def get_thumbnail_url (self ):
6759 return self .images ['thumbnail' ].url
6860
69-
7061 def __unicode__ (self ):
7162 return "Media: %s" % self .id
7263
7364 @classmethod
7465 def object_from_dictionary (cls , entry ):
7566 new_media = Media (id = entry ['id' ])
7667 new_media .type = entry ['type' ]
77-
7868 new_media .user = User .object_from_dictionary (entry ['user' ])
7969
8070 new_media .images = {}
@@ -114,21 +104,19 @@ def object_from_dictionary(cls, entry):
114104 new_media .caption = None
115105 if entry ['caption' ]:
116106 new_media .caption = Comment .object_from_dictionary (entry ['caption' ])
117-
107+
118108 new_media .tags = []
119109 if entry ['tags' ]:
120110 for tag in entry ['tags' ]:
121111 new_media .tags .append (Tag .object_from_dictionary ({'name' : tag }))
122112
123113 new_media .link = entry ['link' ]
124-
125114 new_media .filter = entry .get ('filter' )
126115
127116 return new_media
128117
129118
130119class MediaShortcode (Media ):
131-
132120 def __init__ (self , shortcode = None , ** kwargs ):
133121 self .shortcode = shortcode
134122 for key , value in six .iteritems (kwargs ):
@@ -181,19 +169,16 @@ def __init__(self, id, *args, **kwargs):
181169 def object_from_dictionary (cls , entry ):
182170 point = None
183171 if 'latitude' in entry :
184- point = Point (entry .get ('latitude' ),
185- entry .get ('longitude' ))
186- location = Location (entry .get ('id' , 0 ),
187- point = point ,
188- name = entry .get ('name' , '' ))
172+ point = Point (entry .get ('latitude' ), entry .get ('longitude' ))
173+
174+ location = Location (entry .get ('id' , 0 ), point = point , name = entry .get ('name' , '' ))
189175 return location
190176
191177 def __unicode__ (self ):
192178 return "Location: %s (%s)" % (self .id , self .point )
193179
194180
195181class User (ApiModel ):
196-
197182 def __init__ (self , id , * args , ** kwargs ):
198183 self .id = id
199184 for key , value in six .iteritems (kwargs ):
@@ -204,7 +189,6 @@ def __unicode__(self):
204189
205190
206191class Relationship (ApiModel ):
207-
208192 def __init__ (self , incoming_status = "none" , outgoing_status = "none" , target_user_is_private = False ):
209193 self .incoming_status = incoming_status
210194 self .outgoing_status = outgoing_status
0 commit comments