Created
November 27, 2012 17:32
-
-
Save ptigas/4155731 to your computer and use it in GitHub Desktop.
unifying python api response
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
class API : | |
ERROR = -1 | |
OK = 0 | |
class APIResponse(API) : | |
def __init__(self, code, data) : | |
self.code = code | |
self.data = data | |
def __str__(self) : | |
response = {} | |
response['code'] = self.code | |
response['data'] = str(self.data) | |
return json.dumps(response) | |
res = APIResponse(API.ERROR, "foo") | |
print res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment