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

io.swagger.client.api.MessagesApi Maven / Gradle / Ivy

The newest version!
/*
 * Easemob REST APIs
 * Easemob Server REST API Swagger is designated to provide better documentation and thorough interfaces for testing. For more details about server implementation, request rate limitation, etc, please visit [Easemob Server Integration](http://docs.easemob.com/im/100serverintegration/10intro).    **Note:**  `org_ID` is the unique ID of the organization created when you first registered [Easemob console](https://console.easemob.com/).                          `app_name` is the unique app ID created when you new application in [Easemob console](https://console.easemob.com/).            `Authorization token` is required for most API requests as part of requesting header in the format `Bearer ${token}`. You can obtain the token via [/{org_name}/{app_name}/token](https://docs.hyphenate.io/docs/server-overview#section-request-authentication-token).                                             
 *
 * OpenAPI spec version: 1.0.2
 * 
 *
 * NOTE: This class is auto generated by the swagger code generator program.
 * https://github.com/swagger-api/swagger-codegen.git
 * Do not edit the class manually.
 */


package io.swagger.client.api;

import io.swagger.client.ApiCallback;
import io.swagger.client.ApiClient;
import io.swagger.client.ApiException;
import io.swagger.client.ApiResponse;
import io.swagger.client.Configuration;
import io.swagger.client.Pair;
import io.swagger.client.ProgressRequestBody;
import io.swagger.client.ProgressResponseBody;

import com.google.gson.reflect.TypeToken;

import java.io.IOException;


import io.swagger.client.model.Msg;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MessagesApi {
    private ApiClient apiClient;

    public MessagesApi() {
        this(Configuration.getDefaultApiClient());
    }

    public MessagesApi(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return apiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    /* Build call for orgNameAppNameMessagesPost */
    private com.squareup.okhttp.Call orgNameAppNameMessagesPostCall(String orgName, String appName, String authorization, Msg body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = body;
        
        // create path and map variables
        String localVarPath = "/{org_name}/{app_name}/messages".replaceAll("\\{format\\}","json")
        .replaceAll("\\{" + "org_name" + "\\}", apiClient.escapeString(orgName.toString()))
        .replaceAll("\\{" + "app_name" + "\\}", apiClient.escapeString(appName.toString()));

        List localVarQueryParams = new ArrayList();

        Map localVarHeaderParams = new HashMap();
        if (authorization != null)
        localVarHeaderParams.put("Authorization", apiClient.parameterToString(authorization));

        Map localVarFormParams = new HashMap();

        final String[] localVarAccepts = {
            "application/json"
        };
        final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
        if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept);

        final String[] localVarContentTypes = {
            "application/json"
        };
        final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
        localVarHeaderParams.put("Content-Type", localVarContentType);

        if(progressListener != null) {
            apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
                @Override
                public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
                    com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                    return originalResponse.newBuilder()
                    .body(new ProgressResponseBody(originalResponse.body(), progressListener))
                    .build();
                }
            });
        }

        String[] localVarAuthNames = new String[] {  };
        return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }
    
    @SuppressWarnings("rawtypes")
    private com.squareup.okhttp.Call orgNameAppNameMessagesPostValidateBeforeCall(String orgName, String appName, String authorization, Msg body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        // verify the required parameter 'orgName' is set
        if (orgName == null) {
            throw new ApiException("Missing the required parameter 'orgName' when calling orgNameAppNameMessagesPost(Async)");
        }
        
        // verify the required parameter 'appName' is set
        if (appName == null) {
            throw new ApiException("Missing the required parameter 'appName' when calling orgNameAppNameMessagesPost(Async)");
        }
        
        // verify the required parameter 'authorization' is set
        if (authorization == null) {
            throw new ApiException("Missing the required parameter 'authorization' when calling orgNameAppNameMessagesPost(Async)");
        }
        
        // verify the required parameter 'body' is set
        if (body == null) {
            throw new ApiException("Missing the required parameter 'body' when calling orgNameAppNameMessagesPost(Async)");
        }
        
        
        com.squareup.okhttp.Call call = orgNameAppNameMessagesPostCall(orgName, appName, authorization, body, progressListener, progressRequestListener);
        return call;

        
        
        
        
    }

    /**
     * Send a Message
     * Send a message to user(s) and group(s).                Please refer to the Hyphenate docs for further details about message body. https://docs.hyphenate.io/docs/post-messages
     * @param orgName Organization ID (required)
     * @param appName Application name (required)
     * @param authorization Bearer ${token} (required)
     * @param body Message types: Text, image, audio message, video, command, etc. Please refer to the Hyphenate docs for further details about message body. https://docs.hyphenate.io/docs/post-messages (required)
     * @return String
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public String orgNameAppNameMessagesPost(String orgName, String appName, String authorization, Msg body) throws ApiException {
        ApiResponse resp = orgNameAppNameMessagesPostWithHttpInfo(orgName, appName, authorization, body);
        return resp.getData();
    }

    /**
     * Send a Message
     * Send a message to user(s) and group(s).                Please refer to the Hyphenate docs for further details about message body. https://docs.hyphenate.io/docs/post-messages
     * @param orgName Organization ID (required)
     * @param appName Application name (required)
     * @param authorization Bearer ${token} (required)
     * @param body Message types: Text, image, audio message, video, command, etc. Please refer to the Hyphenate docs for further details about message body. https://docs.hyphenate.io/docs/post-messages (required)
     * @return ApiResponse<String>
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse orgNameAppNameMessagesPostWithHttpInfo(String orgName, String appName, String authorization, Msg body) throws ApiException {
        com.squareup.okhttp.Call call = orgNameAppNameMessagesPostValidateBeforeCall(orgName, appName, authorization, body, null, null);
        Type localVarReturnType = new TypeToken(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Send a Message (asynchronously)
     * Send a message to user(s) and group(s).                Please refer to the Hyphenate docs for further details about message body. https://docs.hyphenate.io/docs/post-messages
     * @param orgName Organization ID (required)
     * @param appName Application name (required)
     * @param authorization Bearer ${token} (required)
     * @param body Message types: Text, image, audio message, video, command, etc. Please refer to the Hyphenate docs for further details about message body. https://docs.hyphenate.io/docs/post-messages (required)
     * @param callback The callback to be executed when the API call finishes
     * @return The request call
     * @throws ApiException If fail to process the API call, e.g. serializing the request body object
     */
    public com.squareup.okhttp.Call orgNameAppNameMessagesPostAsync(String orgName, String appName, String authorization, Msg body, final ApiCallback callback) throws ApiException {

        ProgressResponseBody.ProgressListener progressListener = null;
        ProgressRequestBody.ProgressRequestListener progressRequestListener = null;

        if (callback != null) {
            progressListener = new ProgressResponseBody.ProgressListener() {
                @Override
                public void update(long bytesRead, long contentLength, boolean done) {
                    callback.onDownloadProgress(bytesRead, contentLength, done);
                }
            };

            progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
                @Override
                public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
                    callback.onUploadProgress(bytesWritten, contentLength, done);
                }
            };
        }

        com.squareup.okhttp.Call call = orgNameAppNameMessagesPostValidateBeforeCall(orgName, appName, authorization, body, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy