# Path: pykintone/base_api.py
# class BaseAPI(object):
# 
#     def __init__(self, account, api_token="", requests_options=(), app_id=""):
#         self.account = account
#         self.api_token = api_token
#         self.requests_options = {} if len(requests_options) == 0 else requests_options
#         self.app_id = app_id
# 
#     def _request(self, method, url, params_or_data, headers=None, use_api_token=True):
#         m = method.upper()
#         h = headers
#         token = self.api_token if use_api_token else ""
#         r = None
# 
#         if m == "GET":
#             h = h if h else self.account.to_header(api_token=token, with_content_type=False)
#             r = requests.get(url, params=params_or_data, headers=h, **self.requests_options)
#         elif m == "FILE":
#             h = h if h else self.account.to_header(api_token=token, with_content_type=False)
#             r = requests.request("POST", url, files=params_or_data, headers=h, **self.requests_options)
#         else:
#             h = h if h else self.account.to_header(api_token=token)
#             r = requests.request(m, url, data=json.dumps(params_or_data), headers=h, **self.requests_options)
# 
#         return r


from pykintone.base_api import BaseAPI
        from pykintone.application_settings.administrator import Administrator

    def __init__(self, account, api_token="", requests_options=(), app_id=""):
        super(BaseAdministrationAPI, self).__init__(account, api_token, requests_options, app_id)
        self.__test_mode = False
        self._commit_revision = -1
        self._cached_changes = False

    def as_test_mode(self):
        self.__test_mode = True
        return self

    def _request(self, method, url, params_or_data, headers=None, use_api_token=True):
        result = super(BaseAdministrationAPI, self)._request(method, url, params_or_data, headers, use_api_token)
        if method in ("POST", "PUT", "DELETE"):
            self._cached_changes = True
        return result

    def __enter__(self):
        self._commit_revision = -1
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        if self._cached_changes and not self.app_id:
            raise Exception("There are some changes to be committed, but no application id.")
        elif not (self._cached_changes and self.app_id):
            return None

        admin = self.__get_admin()
        result = None
        exit_type = "Commit"

# Path: pykintone/base_api.py
# class BaseAPI(object):
# 
#     def __init__(self, account, api_token="", requests_options=(), app_id=""):
#         self.account = account
#         self.api_token = api_token
#         self.requests_options = {} if len(requests_options) == 0 else requests_options
#         self.app_id = app_id
# 
#     def _request(self, method, url, params_or_data, headers=None, use_api_token=True):
#         m = method.upper()
#         h = headers
#         token = self.api_token if use_api_token else ""
#         r = None
# 
#         if m == "GET":
#             h = h if h else self.account.to_header(api_token=token, with_content_type=False)
#             r = requests.get(url, params=params_or_data, headers=h, **self.requests_options)
#         elif m == "FILE":
#             h = h if h else self.account.to_header(api_token=token, with_content_type=False)
#             r = requests.request("POST", url, files=params_or_data, headers=h, **self.requests_options)
#         else:
#             h = h if h else self.account.to_header(api_token=token)
#             r = requests.request(m, url, data=json.dumps(params_or_data), headers=h, **self.requests_options)
# 
#         return r


# Path: pykintone/application_settings/base_administration_api.py
from pykintone.base_api import BaseAPI
        from pykintone.application_settings.administrator import Administrator


    def __init__(self, account, api_token="", requests_options=(), app_id=""):
        super(BaseAdministrationAPI, self).__init__(account, api_token, requests_options, app_id)
        self.__test_mode = False
        self._commit_revision = -1
        self._cached_changes = False

    def as_test_mode(self):
        self.__test_mode = True
        return self

    def _request(self, method, url, params_or_data, headers=None, use_api_token=True):
        result = super(BaseAdministrationAPI, self)._request(method, url, params_or_data, headers, use_api_token)
        if method in ("POST", "PUT", "DELETE"):
            self._cached_changes = True
        return result

    def __enter__(self):
        self._commit_revision = -1
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        if self._cached_changes and not self.app_id:
            raise Exception("There are some changes to be committed, but no application id.")
        elif not (self._cached_changes and self.app_id):
            return None

        admin = self.__get_admin()
        result = None
        exit_type = "Commit"

        if exc_type is None and not self.__test_mode: