Esempio n. 1
0
async def server_call_async(method,
                            server,
                            timeout=DEFAULT_TIMEOUT,
                            verify_ssl=True,
                            **parameters):
    """Makes an asynchronous call to an un-authenticated method on a server.

    :param method: The method name.
    :param server: The MyGeotab server.
    :param timeout: The timeout to make the call, in seconds. By default, this is 300 seconds (or 5 minutes).
    :param verify_ssl: If True, verify the SSL certificate. It's recommended not to modify this.
    :param parameters: Additional parameters to send (for example, search=dict(id='b123') ).
    :return: The JSON result (decoded into a dict) from the server.
    :raise MyGeotabException: Raises when an exception occurs on the MyGeotab server.
    :raise TimeoutException: Raises when the request does not respond after some time.
    """
    if method is None:
        raise Exception("A method name must be specified")
    if server is None:
        raise Exception("A server (eg. my3.geotab.com) must be specified")
    parameters = api.process_parameters(parameters)
    return await _query(server,
                        method,
                        parameters,
                        timeout=timeout,
                        verify_ssl=verify_ssl)
Esempio n. 2
0
    async def call_async(self, method, **parameters):
        """Makes an async call to the API.

        :param method: The method name.
        :param params: Additional parameters to send (for example, search=dict(id='b123') )
        :return: The JSON result (decoded into a dict) from the server.abs
        :raise MyGeotabException: Raises when an exception occurs on the MyGeotab server.
        :raise TimeoutException: Raises when the request does not respond after some time.
        """
        if method is None:
            raise Exception('A method name must be specified')
        params = api.process_parameters(parameters)
        if self.credentials and not self.credentials.session_id:
            self.authenticate()
        if 'credentials' not in params and self.credentials.session_id:
            params['credentials'] = self.credentials.get_param()

        try:
            result = await _query(self._server,
                                  method,
                                  params,
                                  verify_ssl=self._is_verify_ssl,
                                  loop=self.loop)
            if result is not None:
                self.__reauthorize_count = 0
            return result
        except MyGeotabException as exception:
            if exception.name == 'InvalidUserException' and self.__reauthorize_count == 0:
                self.__reauthorize_count += 1
                self.authenticate()
                return await self.call_async(method, **parameters)
            raise
Esempio n. 3
0
    async def call_async(self, method, **parameters):
        """Makes an async call to the API.

        :param method: The method name.
        :param params: Additional parameters to send (for example, search=dict(id='b123') )
        :return: The JSON result (decoded into a dict) from the server.abs
        :raise MyGeotabException: Raises when an exception occurs on the MyGeotab server.
        :raise TimeoutException: Raises when the request does not respond after some time.
        """
        if method is None:
            raise Exception('A method name must be specified')
        params = api.process_parameters(parameters)
        if self.credentials and not self.credentials.session_id:
            self.authenticate()
        if 'credentials' not in params and self.credentials.session_id:
            params['credentials'] = self.credentials.get_param()

        try:
            result = await _query(self._server, method, params,
                                  verify_ssl=self._is_verify_ssl, loop=self.loop)
            if result is not None:
                self.__reauthorize_count = 0
            return result
        except MyGeotabException as exception:
            if exception.name == 'InvalidUserException':
                if self.__reauthorize_count == 0 and self.credentials.password:
                    self.__reauthorize_count += 1
                    self.authenticate()
                    return await self.call_async(method, **parameters)
                else:
                    raise AuthenticationException(self.credentials.username,
                                                  self.credentials.database,
                                                  self.credentials.server)
            raise
Esempio n. 4
0
 def test_camel_case_transformer(self):
     params = dict(search=dict(device_search=dict(id=123), include_overlapped_trips=True))
     fixed_params = api.process_parameters(params)
     assert fixed_params is not None
     assert "search" in fixed_params
     assert "deviceSearch" in fixed_params["search"]
     assert "id" in fixed_params["search"]["deviceSearch"]
     assert fixed_params["search"]["deviceSearch"]["id"] == 123
     assert "includeOverlappedTrips" in fixed_params["search"]
     assert fixed_params["search"]["includeOverlappedTrips"]
Esempio n. 5
0
 def test_camel_case_transformer(self):
     params = dict(search=dict(device_search=dict(id=123),
                               include_overlapped_trips=True))
     fixed_params = api.process_parameters(params)
     self.assertIsNotNone(fixed_params)
     self.assertTrue('search' in fixed_params)
     self.assertTrue('deviceSearch' in fixed_params['search'])
     self.assertTrue('id' in fixed_params['search']['deviceSearch'])
     self.assertEqual(123, fixed_params['search']['deviceSearch']['id'])
     self.assertTrue('includeOverlappedTrips' in fixed_params['search'])
     self.assertEqual(True, fixed_params['search']['includeOverlappedTrips'])
Esempio n. 6
0
 def test_camel_case_transformer(self):
     params = dict(search=dict(device_search=dict(id=123),
                               include_overlapped_trips=True))
     fixed_params = api.process_parameters(params)
     assert fixed_params is not None
     assert 'search' in fixed_params
     assert 'deviceSearch' in fixed_params['search']
     assert 'id' in fixed_params['search']['deviceSearch']
     assert fixed_params['search']['deviceSearch']['id'] == 123
     assert 'includeOverlappedTrips' in fixed_params['search']
     assert fixed_params['search']['includeOverlappedTrips']
Esempio n. 7
0
async def server_call_async(method, server, loop: asyncio.AbstractEventLoop=asyncio.get_event_loop(), timeout=DEFAULT_TIMEOUT,
                      verify_ssl=True, **parameters):
    """Makes an asynchronous call to an un-authenticated method on a server.

    :param method: The method name.
    :param server: The MyGeotab server.
    :param loop: The event loop.
    :param timeout: The timeout to make the call, in seconds. By default, this is 300 seconds (or 5 minutes).
    :param verify_ssl: If True, verify the SSL certificate. It's recommended not to modify this.
    :param parameters: Additional parameters to send (for example, search=dict(id='b123') ).
    :return: The JSON result (decoded into a dict) from the server.
    :raise MyGeotabException: Raises when an exception occurs on the MyGeotab server.
    :raise TimeoutException: Raises when the request does not respond after some time.
    """
    if method is None:
        raise Exception("A method name must be specified")
    if server is None:
        raise Exception("A server (eg. my3.geotab.com) must be specified")
    parameters = api.process_parameters(parameters)
    return await _query(server, method, parameters, timeout=timeout, verify_ssl=verify_ssl, loop=loop)