<s> import jsonpickle <EOL> import json <EOL> import requests <EOL> import inflection <EOL> class Serializable ( object ) : <EOL> def to_JSON ( self ) : <EOL> underscores = jsonpickle . encode ( self ) <EOL> temp = json . loads ( underscores ) <EOL> camel_case = self . convert_json ( temp , self . lower_camelize ) <EOL> return jsonpickle . encode ( camel_case ) <EOL> @ classmethod <EOL> def lower_camelize ( cls , string ) : <EOL> return inflection . camelize ( string , False ) <EOL> @ classmethod <EOL> def convert_json ( cls , d , convert ) : <EOL> new_d = { } <EOL> for k , v in d . iteritems ( ) : <EOL> new_d [ convert ( k ) ] = cls . convert_json ( v , convert ) if isinstance ( v , dict ) else v <EOL> return new_d <EOL> @ classmethod <EOL> def from_JSON ( cls , response ) : <EOL> temp_camel_case = json . loads ( response ) <EOL> temp = cls . convert_json ( temp_camel_case , inflection . underscore ) <EOL> class_name = cls . __module__ + '<STR_LIT:.>' + cls . __name__ <EOL> temp [ '<STR_LIT>' ] = class_name <EOL> pickle = json . dumps ( temp ) <EOL> return jsonpickle . decode ( pickle ) <EOL> @ classmethod <EOL> def from_JSON_list ( cls , response ) : <EOL> items = [ cls . from_JSON ( json . dumps ( item ) ) for item in response ] <EOL> return items </s>
