api-client-python/retailcrm/response.py

49 lines
894 B
Python
Raw Normal View History

2016-03-17 00:54:42 +03:00
# coding=utf-8
"""
Response class
"""
2016-03-17 00:54:42 +03:00
class Response(object):
"""
API response class
"""
def __init__(self, code, body):
self.__status_code = code
self.__response_body = body
2016-03-17 00:54:42 +03:00
def get_status_code(self):
"""
:return: integer
"""
return self.__status_code
2016-03-17 00:54:42 +03:00
def get_response(self):
"""
:return: string
2016-03-17 00:54:42 +03:00
"""
return self.__response_body
2016-03-17 00:54:42 +03:00
def is_successful(self):
2016-03-17 00:54:42 +03:00
"""
:return: boolean
"""
return int(self.__status_code) < 400
def get_error_msg(self):
"""
:return: string
"""
return self.__response_body['errorMsg']
def get_errors(self):
"""
:return: collection
"""
errors = {
} if not self.__response_body['errors'] else self.__response_body['errors']
return errors