# Path: solvebio/errors.py
# class SolveError(Exception):
#     """Exceptions tailored to the kinds of errors from a SolveBio API
#     request"""
#     default_message = ('Unexpected error communicating with SolveBio. '
#                        'If this problem persists, let us know at '
#                        'support@solvebio.com.')
# 
#     def __init__(self, message=None, response=None):
#         self.json_body = {}
#         self.status_code = None
#         self.message = message or self.default_message
#         self.field_errors = []
#         self.response = response
# 
#         if response is not None:
#             self.status_code = response.status_code
#             try:
#                 self.json_body = response.json()
#                 logger.debug(
#                     'API Response (%d): %s'
#                     % (self.status_code, self.json_body))
#             except:
#                 logger.debug(
#                     'API Response (%d): Response does not contain JSON.'
#                     % self.status_code)
# 
#             if self.status_code == 400:
#                 self.message = 'Bad Request ({})'.format(response.url)
#             elif response.status_code == 401:
#                 self.message = '401 Unauthorized ({})'.format(response.url)
#             elif response.status_code == 403:
#                 self.message = '403 Forbidden ({})'.format(response.url)
#             elif response.status_code == 404:
#                 self.message = '404 Not Found ({})'.format(response.url)
# 
#             # Handle other keys
#             for k, v in list(self.json_body.items()):
#                 if k in ["non_field_errors", "detail"]:
#                     self.message += '\nError: '
#                 else:
#                     self.message += '\nError (%s): ' % k
# 
#                 # can be a list, dict, string
#                 self.message += str(v)
# 
#     def __str__(self):
#         return self.message


from six.moves.urllib.parse import urlparse
from ..errors import SolveError
from __future__ import absolute_import




def validate_api_host_url(url):
    """
    Validate SolveBio API host url.

    Valid urls must not be empty and
    must contain either HTTP or HTTPS scheme.
    """
    if not url:
        raise SolveError('No SolveBio API host is set')

    # Default to https if no scheme is set
    if '://' not in url:
        url = 'https://' + url

    parsed = urlparse(url)
    if parsed.scheme not in ['http', 'https']:
        raise SolveError(
            'Invalid API host: %s. '
            'Missing url scheme (HTTP or HTTPS).' % url
        )
    elif not parsed.netloc:

# Path: solvebio/errors.py
# class SolveError(Exception):
#     """Exceptions tailored to the kinds of errors from a SolveBio API
#     request"""
#     default_message = ('Unexpected error communicating with SolveBio. '
#                        'If this problem persists, let us know at '
#                        'support@solvebio.com.')
# 
#     def __init__(self, message=None, response=None):
#         self.json_body = {}
#         self.status_code = None
#         self.message = message or self.default_message
#         self.field_errors = []
#         self.response = response
# 
#         if response is not None:
#             self.status_code = response.status_code
#             try:
#                 self.json_body = response.json()
#                 logger.debug(
#                     'API Response (%d): %s'
#                     % (self.status_code, self.json_body))
#             except:
#                 logger.debug(
#                     'API Response (%d): Response does not contain JSON.'
#                     % self.status_code)
# 
#             if self.status_code == 400:
#                 self.message = 'Bad Request ({})'.format(response.url)
#             elif response.status_code == 401:
#                 self.message = '401 Unauthorized ({})'.format(response.url)
#             elif response.status_code == 403:
#                 self.message = '403 Forbidden ({})'.format(response.url)
#             elif response.status_code == 404:
#                 self.message = '404 Not Found ({})'.format(response.url)
# 
#             # Handle other keys
#             for k, v in list(self.json_body.items()):
#                 if k in ["non_field_errors", "detail"]:
#                     self.message += '\nError: '
#                 else:
#                     self.message += '\nError (%s): ' % k
# 
#                 # can be a list, dict, string
#                 self.message += str(v)
# 
#     def __str__(self):
#         return self.message


# Path: solvebio/utils/validators.py
from six.moves.urllib.parse import urlparse
from ..errors import SolveError

from __future__ import absolute_import




def validate_api_host_url(url):
    """
    Validate SolveBio API host url.

    Valid urls must not be empty and
    must contain either HTTP or HTTPS scheme.
    """
    if not url:
        raise SolveError('No SolveBio API host is set')

    # Default to https if no scheme is set
    if '://' not in url:
        url = 'https://' + url

    parsed = urlparse(url)
    if parsed.scheme not in ['http', 'https']:
        raise SolveError(
            'Invalid API host: %s. '
            'Missing url scheme (HTTP or HTTPS).' % url
        )
    elif not parsed.netloc:

        raise SolveError('Invalid API host: %s.' % url)