All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.testdroid.api.APIClient Maven / Gradle / Ivy

There is a newer version: 3.34.0
Show newest version
package com.testdroid.api;

import com.testdroid.api.dto.Context;
import com.testdroid.api.model.APIDevice;
import com.testdroid.api.model.APIDeviceProperty;
import com.testdroid.api.model.APILabelGroup;
import com.testdroid.api.model.APIUser;
import okhttp3.Response;

import java.io.File;
import java.io.InputStream;
import java.util.Map;
import java.util.Optional;

/**
 * @author Łukasz Kajda 
 */
public interface APIClient {

    /**
     * Sets establish connection timeout for APIClient requests.
     *
     * @param timeout timeout is ms. Value 0 means infinite timeout.
     */
    void setConnectTimeout(int timeout);

    /**
     * Sets timeout for read data from established connection for APIClient requests.
     *
     * @param timeout timeout is ms. Value 0 means infinite timeout.
     */
    void setRequestTimeout(int timeout);

    /**
     * Fetch and return me - the authenticated user.
     *
     * @throws APIException on invalid username, password or API error.
     */
    APIUser me() throws APIException;

    /**
     * Calls GET request to API
     *
     * @param   expected result class to be parsed from response
     * @param uri  context URI of the resource (without /api/v2 prefix
     * @param type expected result class to be parsed from response
     * @return object defined as T if succesfully returned and parsed
     * @throws APIException on any problem related to API communication
     */
     T get(String uri, Class type) throws APIException;

     APIList get(String uri, Context context) throws APIException;

    /**
     * Calls GET request to API. Used when result expected as stream.
     *
     * @param uri context URI of the resource (without /api/v2 prefix
     * @return stream with response
     * @throws APIException on any problem related to API communication
     */
    InputStream get(String uri) throws APIException;

    /**
     * Calls POST request to API
     *
     * @param   expected result class to be parsed from response
     * @param uri  context URI of the resource (without /api/v2 prefix
     * @param body body - usually url encoded, to POST to API
     * @param type expected result class to be parsed from response
     * @return object defined as T if succesfully returned and parsed
     * @throws APIException on any problem related to API communication
     */
     T post(String uri, Object body, Class type) throws APIException;

    /**
     * Calls POST request to API
     *
     * @param                expected result class to be parsed from response
     * @param uri               context URI of the resource (without /api/v2 prefix)
     * @param contentType       content type of uploaded file
     * @param file              file to be uploaded with that request
     * @param fileExtraParams   extra parameters for form-data describing the file
     * @param type              expected result class to be parsed from response
     * @return object defined as T if successfully returned and parsed
     * @throws APIException on any problem related to API communication
     */
     T postFile(
            String uri, String contentType, File file, Map fileExtraParams, Class type)
            throws APIException;

    /**
     * Calls DELETE request to API
     *
     * @param uri context URI of the resource (without /api/v2 prefix
     * @throws APIException on any problem related to API communication
     */
    void delete(String uri) throws APIException;

    /**
     * return resource for accessing list of devices in Cloud using provided filters
     *
     * @return list resource for accessing all devices matching selected filters, if no filter used returns all devices
     */
    APIListResource getDevices();

    APIListResource getDevices(Context context);

    APIListResource getLabelGroups();

    APIListResource getLabelGroups(Context context);

    Optional findDevicePropertyInLabelGroup(String groupName, String labelName) throws APIException;

    Response getHttpResponse(String uri, Context context) throws APIException;

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy