# Path: mapmyfitness/exceptions.py
# class BadRequestException(Exception):
#     """The API returned a status of 400 (Bad Request)."""
# 
# class UnauthorizedException(Exception):
#     """The request authentication failed. The OAuth credentials that the client supplied were missing or invalid."""
# 
# class NotFoundException(Exception):
#     """The resource could not be found."""
# 
# class InternalServerErrorException(Exception):
#     """There was an error while processing your request."""
# 
# class ForbiddenException(Exception):
#     """The request credentials authenticated, but the requesting user or client app is not authorized to access the given resource."""
# 
# Path: mapmyfitness/utils.py
# def datetime_to_iso_format(dt):
#     utc_datetime = dt.replace(tzinfo=utc)
#     return utc_datetime.isoformat()


import datetime
import json
import requests
from ..exceptions import BadRequestException, UnauthorizedException, NotFoundException, InternalServerErrorException, ForbiddenException
from ..utils import datetime_to_iso_format
            'Authorization': 'Bearer {0}'.format(self.api_config.access_token)
        }
        if extra_headers is not None:
            headers.update(extra_headers)

        kwargs = {'headers': headers}

        if data is not None:
            kwargs['data'] = json.dumps(data)

        if params is not None:
            if 'close_to_location' in params:
                coords = map(str, params['close_to_location'])
                params['close_to_location'] = ','.join(coords)
            kwargs['params'] = params
            for param_key, param_val in params.items():
                if isinstance(param_val, datetime.datetime):
                    kwargs['params'][param_key] = datetime_to_iso_format(param_val)

        resp = getattr(requests, method)(full_path, **kwargs)

        if resp.status_code in self.http_exception_map:
            bad_request_json = resp.json()
            if resp.status_code == 400 and '_diagnostics' in bad_request_json and 'validation_failures' in bad_request_json['_diagnostics'] and len(bad_request_json['_diagnostics']['validation_failures']):
                printable_errors = []
                validation_failures = bad_request_json['_diagnostics']['validation_failures']
                for validation_dict_or_list in validation_failures:
                    if isinstance(validation_dict_or_list, dict):
                        for validation_dict_key, validation_dict_list in validation_dict_or_list.items():
                            for validation_error in validation_dict_list:

# Path: mapmyfitness/exceptions.py
# class BadRequestException(Exception):
#     """The API returned a status of 400 (Bad Request)."""
# 
# class UnauthorizedException(Exception):
#     """The request authentication failed. The OAuth credentials that the client supplied were missing or invalid."""
# 
# class NotFoundException(Exception):
#     """The resource could not be found."""
# 
# class InternalServerErrorException(Exception):
#     """There was an error while processing your request."""
# 
# class ForbiddenException(Exception):
#     """The request credentials authenticated, but the requesting user or client app is not authorized to access the given resource."""
# 
# Path: mapmyfitness/utils.py
# def datetime_to_iso_format(dt):
#     utc_datetime = dt.replace(tzinfo=utc)
#     return utc_datetime.isoformat()


# Path: mapmyfitness/api/base.py
import datetime
import json
import requests
from ..exceptions import BadRequestException, UnauthorizedException, NotFoundException, InternalServerErrorException, ForbiddenException
from ..utils import datetime_to_iso_format

            'Authorization': 'Bearer {0}'.format(self.api_config.access_token)
        }
        if extra_headers is not None:
            headers.update(extra_headers)

        kwargs = {'headers': headers}

        if data is not None:
            kwargs['data'] = json.dumps(data)

        if params is not None:
            if 'close_to_location' in params:
                coords = map(str, params['close_to_location'])
                params['close_to_location'] = ','.join(coords)
            kwargs['params'] = params
            for param_key, param_val in params.items():
                if isinstance(param_val, datetime.datetime):
                    kwargs['params'][param_key] = datetime_to_iso_format(param_val)

        resp = getattr(requests, method)(full_path, **kwargs)

        if resp.status_code in self.http_exception_map:
            bad_request_json = resp.json()
            if resp.status_code == 400 and '_diagnostics' in bad_request_json and 'validation_failures' in bad_request_json['_diagnostics'] and len(bad_request_json['_diagnostics']['validation_failures']):
                printable_errors = []
                validation_failures = bad_request_json['_diagnostics']['validation_failures']
                for validation_dict_or_list in validation_failures:
                    if isinstance(validation_dict_or_list, dict):
                        for validation_dict_key, validation_dict_list in validation_dict_or_list.items():
                            for validation_error in validation_dict_list:

                                printable_errors.append('{0} {1}'.format(validation_dict_key, validation_error))