# Path: devicehive/api_request.py
# class AuthApiRequest(ApiRequest):
#     """Auth api request class."""
# 
#     def execute(self, error_message):
#         self.header(*self._api.token.auth_header)
#         try:
#             return super(AuthApiRequest, self).execute(error_message)
#         except ApiResponseError as api_response_error:
#             if api_response_error.code != 401:
#                 raise
#         self._api.token.auth()
#         self.header(*self._api.token.auth_header)
#         return super(AuthApiRequest, self).execute(error_message)
# 
# Path: devicehive/api_request.py
# class ApiRequestError(TransportError):
#     """Api request error."""


from devicehive.api_request import AuthApiRequest
from devicehive.api_request import ApiRequestError
        self.name = device[self.NAME_KEY]
        self.data = device[self.DATA_KEY]
        self.network_id = device[self.NETWORK_ID_KEY]
        self.device_type_id = device[self.DEVICE_TYPE_ID_KEY]
        self.is_blocked = device[self.IS_BLOCKED_KEY]

    def _ensure_exists(self):
        if self._id:
            return
        raise DeviceError('Device does not exist.')

    @property
    def id(self):
        return self._id

    def get(self, device_id):
        auth_api_request = AuthApiRequest(self._api)
        auth_api_request.url('device/{deviceId}', deviceId=device_id)
        auth_api_request.action('device/get')
        auth_api_request.response_key('device')
        device = auth_api_request.execute('Device get failure.')
        self._init(device)

    def save(self):
        self._ensure_exists()
        device = {self.NAME_KEY: self.name,
                  self.DATA_KEY: self.data,
                  self.NETWORK_ID_KEY: self.network_id,
                  self.DEVICE_TYPE_ID_KEY: self.device_type_id,
                  self.IS_BLOCKED_KEY: self.is_blocked}

# Path: devicehive/api_request.py
# class AuthApiRequest(ApiRequest):
#     """Auth api request class."""
# 
#     def execute(self, error_message):
#         self.header(*self._api.token.auth_header)
#         try:
#             return super(AuthApiRequest, self).execute(error_message)
#         except ApiResponseError as api_response_error:
#             if api_response_error.code != 401:
#                 raise
#         self._api.token.auth()
#         self.header(*self._api.token.auth_header)
#         return super(AuthApiRequest, self).execute(error_message)
# 
# Path: devicehive/api_request.py
# class ApiRequestError(TransportError):
#     """Api request error."""


# Path: devicehive/device.py
from devicehive.api_request import AuthApiRequest
from devicehive.api_request import ApiRequestError

        self.name = device[self.NAME_KEY]
        self.data = device[self.DATA_KEY]
        self.network_id = device[self.NETWORK_ID_KEY]
        self.device_type_id = device[self.DEVICE_TYPE_ID_KEY]
        self.is_blocked = device[self.IS_BLOCKED_KEY]

    def _ensure_exists(self):
        if self._id:
            return
        raise DeviceError('Device does not exist.')

    @property
    def id(self):
        return self._id

    def get(self, device_id):
        auth_api_request = AuthApiRequest(self._api)
        auth_api_request.url('device/{deviceId}', deviceId=device_id)
        auth_api_request.action('device/get')
        auth_api_request.response_key('device')
        device = auth_api_request.execute('Device get failure.')
        self._init(device)

    def save(self):
        self._ensure_exists()
        device = {self.NAME_KEY: self.name,
                  self.DATA_KEY: self.data,
                  self.NETWORK_ID_KEY: self.network_id,
                  self.DEVICE_TYPE_ID_KEY: self.device_type_id,
                  self.IS_BLOCKED_KEY: self.is_blocked}

        auth_api_request = AuthApiRequest(self._api)