Class AbstractAPIClient

    • Field Detail

      • LABEL_GROUPS_URI

        protected static final java.lang.String LABEL_GROUPS_URI
        See Also:
        Constant Field Values
      • clientConnectTimeout

        protected int clientConnectTimeout
      • clientRequestTimeout

        protected int clientRequestTimeout
      • httpTransport

        protected com.google.api.client.http.HttpTransport httpTransport
      • apiURL

        protected java.lang.String apiURL
    • Constructor Detail

      • AbstractAPIClient

        public AbstractAPIClient()
    • Method Detail

      • getRequestFactory

        protected com.google.api.client.http.HttpRequestFactory getRequestFactory()
                                                                           throws APIException
        Throws:
        APIException
      • setConnectTimeout

        public void setConnectTimeout​(int timeout)
        Description copied from interface: APIClient
        Sets establish connection timeout for APIClient requests.
        Specified by:
        setConnectTimeout in interface APIClient
        Parameters:
        timeout - timeout is ms. Value 0 means infinite timeout.
      • setRequestTimeout

        public void setRequestTimeout​(int timeout)
        Description copied from interface: APIClient
        Sets timeout for read data from established connection for APIClient requests.
        Specified by:
        setRequestTimeout in interface APIClient
        Parameters:
        timeout - timeout is ms. Value 0 means infinite timeout.
      • get

        public <T extends APIEntity> T get​(java.lang.String uri,
                                           java.lang.Class<T> type)
                                    throws APIException
        Description copied from interface: APIClient
        Calls GET request to API
        Specified by:
        get in interface APIClient
        Type Parameters:
        T - expected result class to be parsed from response
        Parameters:
        uri - context URI of the resource (without /api/v2 prefix
        type - expected result class to be parsed from response
        Returns:
        object defined as T if succesfully returned and parsed
        Throws:
        APIException - on any problem related to API communication
      • get

        public java.io.InputStream get​(java.lang.String uri)
                                throws APIException
        Description copied from interface: APIClient
        Calls GET request to API. Used when result expected as stream.
        Specified by:
        get in interface APIClient
        Parameters:
        uri - context URI of the resource (without /api/v2 prefix
        Returns:
        stream with response
        Throws:
        APIException - on any problem related to API communication
      • getHttpHeaders

        protected abstract com.google.api.client.http.HttpHeaders getHttpHeaders()
      • getOnce

        protected <T extends APIEntity> T getOnce​(java.lang.String uri,
                                                  Context<?> context,
                                                  com.fasterxml.jackson.core.type.TypeReference<T> type)
                                           throws APIException
        Tries to call API once. Returns expected entity or throws exception.
        Throws:
        APIException
      • getStream

        protected java.io.InputStream getStream​(java.lang.String uri)
                                         throws APIException
        Throws:
        APIException
      • post

        public <T extends APIEntity> T post​(java.lang.String uri,
                                            java.lang.Object body,
                                            java.lang.Class<T> type)
                                     throws APIException
        Description copied from interface: APIClient
        Calls POST request to API
        Specified by:
        post in interface APIClient
        Type Parameters:
        T - expected result class to be parsed from response
        Parameters:
        uri - context URI of the resource (without /api/v2 prefix
        body - body - usually url encoded, to POST to API
        type - expected result class to be parsed from response
        Returns:
        object defined as T if succesfully returned and parsed
        Throws:
        APIException - on any problem related to API communication
      • postOnce

        protected <T extends APIEntity> T postOnce​(java.lang.String uri,
                                                   java.lang.Object body,
                                                   java.util.Map<java.lang.String,​java.lang.String> fileExtraParams,
                                                   java.lang.String contentType,
                                                   com.fasterxml.jackson.core.type.TypeReference<T> type)
                                            throws APIException
        Throws:
        APIException
      • postFile

        public <T extends APIEntity> T postFile​(java.lang.String uri,
                                                java.lang.String contentType,
                                                java.io.File file,
                                                java.util.Map<java.lang.String,​java.lang.String> fileExtraParams,
                                                java.lang.Class<T> type)
                                         throws APIException
        Description copied from interface: APIClient
        Calls POST request to API
        Specified by:
        postFile in interface APIClient
        Type Parameters:
        T - expected result class to be parsed from response
        Parameters:
        uri - context URI of the resource (without /api/v2 prefix)
        contentType - content type of uploaded file
        file - file to be uploaded with that request
        fileExtraParams - extra parameters for form-data describing the file
        type - expected result class to be parsed from response
        Returns:
        object defined as T if successfully returned and parsed
        Throws:
        APIException - on any problem related to API communication
      • delete

        public void delete​(java.lang.String uri)
                    throws APIException
        Description copied from interface: APIClient
        Calls DELETE request to API
        Specified by:
        delete in interface APIClient
        Parameters:
        uri - context URI of the resource (without /api/v2 prefix
        Throws:
        APIException - on any problem related to API communication
      • getDevices

        public APIListResource<APIDevice> getDevices()
        Description copied from interface: APIClient
        return resource for accessing list of devices in Cloud using provided filters
        Specified by:
        getDevices in interface APIClient
        Returns:
        list resource for accessing all devices matching selected filters, if no filter used returns all devices
      • fromJson

        protected <T> T fromJson​(java.io.InputStream inputStream,
                                 com.fasterxml.jackson.core.type.TypeReference<T> type)
                          throws APIException
        Throws:
        APIException
      • fromJson

        protected <T> T fromJson​(java.lang.String content,
                                 com.fasterxml.jackson.core.type.TypeReference<T> type)
                          throws APIException
        Throws:
        APIException
      • fixMapParameters

        protected java.util.Map<java.lang.String,​java.lang.Object> fixMapParameters​(java.util.Map<java.lang.String,​java.lang.Object> map)
      • getAPIException

        protected APIException getAPIException​(com.google.api.client.http.HttpResponseException ex)
      • disconnectQuietly

        protected void disconnectQuietly​(com.google.api.client.http.HttpResponse httpResponse)