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

com.microsoft.azure.management.cognitiveservices.implementation.CognitiveServicesAccountsInner Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See License.txt in the project root for
 * license information.
 *
 * Code generated by Microsoft (R) AutoRest Code Generator.
 */

package com.microsoft.azure.management.cognitiveservices.implementation;

import com.microsoft.azure.management.resources.fluentcore.collection.InnerSupportsGet;
import com.microsoft.azure.management.resources.fluentcore.collection.InnerSupportsDelete;
import retrofit2.Retrofit;
import com.google.common.reflect.TypeToken;
import com.microsoft.azure.management.cognitiveservices.CognitiveServicesAccountUpdateParameters;
import com.microsoft.azure.management.cognitiveservices.ErrorException;
import com.microsoft.azure.management.cognitiveservices.KeyName;
import com.microsoft.azure.management.cognitiveservices.RegenerateKeyParameters;
import com.microsoft.rest.ServiceCallback;
import com.microsoft.rest.ServiceFuture;
import com.microsoft.rest.ServiceResponse;
import com.microsoft.rest.Validator;
import java.io.IOException;
import java.util.Map;
import okhttp3.ResponseBody;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Headers;
import retrofit2.http.HTTP;
import retrofit2.http.PATCH;
import retrofit2.http.Path;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Query;
import retrofit2.Response;
import rx.functions.Func1;
import rx.Observable;

/**
 * An instance of this class provides access to all the operations defined
 * in CognitiveServicesAccounts.
 */
public class CognitiveServicesAccountsInner implements InnerSupportsGet, InnerSupportsDelete {
    /** The Retrofit service to perform REST calls. */
    private CognitiveServicesAccountsService service;
    /** The service client containing this operation class. */
    private CognitiveServicesManagementClientImpl client;

    /**
     * Initializes an instance of CognitiveServicesAccountsInner.
     *
     * @param retrofit the Retrofit instance built from a Retrofit Builder.
     * @param client the instance of the service client containing this operation class.
     */
    public CognitiveServicesAccountsInner(Retrofit retrofit, CognitiveServicesManagementClientImpl client) {
        this.service = retrofit.create(CognitiveServicesAccountsService.class);
        this.client = client;
    }

    /**
     * The interface defining all the services for CognitiveServicesAccounts to be
     * used by Retrofit to perform actually REST calls.
     */
    interface CognitiveServicesAccountsService {
        @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.cognitiveservices.CognitiveServicesAccounts create" })
        @PUT("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}")
        Observable> create(@Path("resourceGroupName") String resourceGroupName, @Path("accountName") String accountName, @Path("subscriptionId") String subscriptionId, @Body CognitiveServicesAccountCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent);

        @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.cognitiveservices.CognitiveServicesAccounts update" })
        @PATCH("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}")
        Observable> update(@Path("resourceGroupName") String resourceGroupName, @Path("accountName") String accountName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body CognitiveServicesAccountUpdateParameters parameters, @Header("User-Agent") String userAgent);

        @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.cognitiveservices.CognitiveServicesAccounts delete" })
        @HTTP(path = "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}", method = "DELETE", hasBody = true)
        Observable> delete(@Path("resourceGroupName") String resourceGroupName, @Path("accountName") String accountName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent);

        @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.cognitiveservices.CognitiveServicesAccounts getByResourceGroup" })
        @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}")
        Observable> getByResourceGroup(@Path("resourceGroupName") String resourceGroupName, @Path("accountName") String accountName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent);

        @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.cognitiveservices.CognitiveServicesAccounts listKeys" })
        @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}/listKeys")
        Observable> listKeys(@Path("resourceGroupName") String resourceGroupName, @Path("accountName") String accountName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent);

        @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.cognitiveservices.CognitiveServicesAccounts regenerateKey" })
        @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}/regenerateKey")
        Observable> regenerateKey(@Path("resourceGroupName") String resourceGroupName, @Path("accountName") String accountName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body RegenerateKeyParameters parameters, @Header("User-Agent") String userAgent);

        @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.cognitiveservices.CognitiveServicesAccounts listSkus" })
        @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}/skus")
        Observable> listSkus(@Path("resourceGroupName") String resourceGroupName, @Path("accountName") String accountName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent);

    }

    /**
     * Create Cognitive Services Account. Accounts is a resource group wide resource type. It holds the keys for developer to access intelligent APIs. It's also the resource type for billing.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @param parameters The parameters to provide for the created account.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @throws ErrorException thrown if the request is rejected by server
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
     * @return the CognitiveServicesAccountInner object if successful.
     */
    public CognitiveServicesAccountInner create(String resourceGroupName, String accountName, CognitiveServicesAccountCreateParametersInner parameters) {
        return createWithServiceResponseAsync(resourceGroupName, accountName, parameters).toBlocking().single().body();
    }

    /**
     * Create Cognitive Services Account. Accounts is a resource group wide resource type. It holds the keys for developer to access intelligent APIs. It's also the resource type for billing.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @param parameters The parameters to provide for the created account.
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceFuture} object
     */
    public ServiceFuture createAsync(String resourceGroupName, String accountName, CognitiveServicesAccountCreateParametersInner parameters, final ServiceCallback serviceCallback) {
        return ServiceFuture.fromResponse(createWithServiceResponseAsync(resourceGroupName, accountName, parameters), serviceCallback);
    }

    /**
     * Create Cognitive Services Account. Accounts is a resource group wide resource type. It holds the keys for developer to access intelligent APIs. It's also the resource type for billing.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @param parameters The parameters to provide for the created account.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the CognitiveServicesAccountInner object
     */
    public Observable createAsync(String resourceGroupName, String accountName, CognitiveServicesAccountCreateParametersInner parameters) {
        return createWithServiceResponseAsync(resourceGroupName, accountName, parameters).map(new Func1, CognitiveServicesAccountInner>() {
            @Override
            public CognitiveServicesAccountInner call(ServiceResponse response) {
                return response.body();
            }
        });
    }

    /**
     * Create Cognitive Services Account. Accounts is a resource group wide resource type. It holds the keys for developer to access intelligent APIs. It's also the resource type for billing.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @param parameters The parameters to provide for the created account.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the CognitiveServicesAccountInner object
     */
    public Observable> createWithServiceResponseAsync(String resourceGroupName, String accountName, CognitiveServicesAccountCreateParametersInner parameters) {
        if (resourceGroupName == null) {
            throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
        }
        if (accountName == null) {
            throw new IllegalArgumentException("Parameter accountName is required and cannot be null.");
        }
        if (this.client.subscriptionId() == null) {
            throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
        }
        if (parameters == null) {
            throw new IllegalArgumentException("Parameter parameters is required and cannot be null.");
        }
        if (this.client.apiVersion() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
        }
        Validator.validate(parameters);
        return service.create(resourceGroupName, accountName, this.client.subscriptionId(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent())
            .flatMap(new Func1, Observable>>() {
                @Override
                public Observable> call(Response response) {
                    try {
                        ServiceResponse clientResponse = createDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    private ServiceResponse createDelegate(Response response) throws ErrorException, IOException, IllegalArgumentException {
        return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter())
                .register(200, new TypeToken() { }.getType())
                .register(201, new TypeToken() { }.getType())
                .registerError(ErrorException.class)
                .build(response);
    }

    /**
     * Updates a Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @throws ErrorException thrown if the request is rejected by server
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
     * @return the CognitiveServicesAccountInner object if successful.
     */
    public CognitiveServicesAccountInner update(String resourceGroupName, String accountName) {
        return updateWithServiceResponseAsync(resourceGroupName, accountName).toBlocking().single().body();
    }

    /**
     * Updates a Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceFuture} object
     */
    public ServiceFuture updateAsync(String resourceGroupName, String accountName, final ServiceCallback serviceCallback) {
        return ServiceFuture.fromResponse(updateWithServiceResponseAsync(resourceGroupName, accountName), serviceCallback);
    }

    /**
     * Updates a Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the CognitiveServicesAccountInner object
     */
    public Observable updateAsync(String resourceGroupName, String accountName) {
        return updateWithServiceResponseAsync(resourceGroupName, accountName).map(new Func1, CognitiveServicesAccountInner>() {
            @Override
            public CognitiveServicesAccountInner call(ServiceResponse response) {
                return response.body();
            }
        });
    }

    /**
     * Updates a Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the CognitiveServicesAccountInner object
     */
    public Observable> updateWithServiceResponseAsync(String resourceGroupName, String accountName) {
        if (resourceGroupName == null) {
            throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
        }
        if (accountName == null) {
            throw new IllegalArgumentException("Parameter accountName is required and cannot be null.");
        }
        if (this.client.subscriptionId() == null) {
            throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
        }
        if (this.client.apiVersion() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
        }
        final SkuInner sku = null;
        final Map tags = null;
        CognitiveServicesAccountUpdateParameters parameters = new CognitiveServicesAccountUpdateParameters();
        parameters.withSku(null);
        parameters.withTags(null);
        return service.update(resourceGroupName, accountName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent())
            .flatMap(new Func1, Observable>>() {
                @Override
                public Observable> call(Response response) {
                    try {
                        ServiceResponse clientResponse = updateDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    /**
     * Updates a Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @param sku Gets or sets the SKU of the resource.
     * @param tags Gets or sets a list of key value pairs that describe the resource. These tags can be used in viewing and grouping this resource (across resource groups). A maximum of 15 tags can be provided for a resource. Each tag must have a key no greater than 128 characters and value no greater than 256 characters.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @throws ErrorException thrown if the request is rejected by server
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
     * @return the CognitiveServicesAccountInner object if successful.
     */
    public CognitiveServicesAccountInner update(String resourceGroupName, String accountName, SkuInner sku, Map tags) {
        return updateWithServiceResponseAsync(resourceGroupName, accountName, sku, tags).toBlocking().single().body();
    }

    /**
     * Updates a Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @param sku Gets or sets the SKU of the resource.
     * @param tags Gets or sets a list of key value pairs that describe the resource. These tags can be used in viewing and grouping this resource (across resource groups). A maximum of 15 tags can be provided for a resource. Each tag must have a key no greater than 128 characters and value no greater than 256 characters.
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceFuture} object
     */
    public ServiceFuture updateAsync(String resourceGroupName, String accountName, SkuInner sku, Map tags, final ServiceCallback serviceCallback) {
        return ServiceFuture.fromResponse(updateWithServiceResponseAsync(resourceGroupName, accountName, sku, tags), serviceCallback);
    }

    /**
     * Updates a Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @param sku Gets or sets the SKU of the resource.
     * @param tags Gets or sets a list of key value pairs that describe the resource. These tags can be used in viewing and grouping this resource (across resource groups). A maximum of 15 tags can be provided for a resource. Each tag must have a key no greater than 128 characters and value no greater than 256 characters.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the CognitiveServicesAccountInner object
     */
    public Observable updateAsync(String resourceGroupName, String accountName, SkuInner sku, Map tags) {
        return updateWithServiceResponseAsync(resourceGroupName, accountName, sku, tags).map(new Func1, CognitiveServicesAccountInner>() {
            @Override
            public CognitiveServicesAccountInner call(ServiceResponse response) {
                return response.body();
            }
        });
    }

    /**
     * Updates a Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @param sku Gets or sets the SKU of the resource.
     * @param tags Gets or sets a list of key value pairs that describe the resource. These tags can be used in viewing and grouping this resource (across resource groups). A maximum of 15 tags can be provided for a resource. Each tag must have a key no greater than 128 characters and value no greater than 256 characters.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the CognitiveServicesAccountInner object
     */
    public Observable> updateWithServiceResponseAsync(String resourceGroupName, String accountName, SkuInner sku, Map tags) {
        if (resourceGroupName == null) {
            throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
        }
        if (accountName == null) {
            throw new IllegalArgumentException("Parameter accountName is required and cannot be null.");
        }
        if (this.client.subscriptionId() == null) {
            throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
        }
        if (this.client.apiVersion() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
        }
        Validator.validate(sku);
        Validator.validate(tags);
        CognitiveServicesAccountUpdateParameters parameters = new CognitiveServicesAccountUpdateParameters();
        parameters.withSku(sku);
        parameters.withTags(tags);
        return service.update(resourceGroupName, accountName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent())
            .flatMap(new Func1, Observable>>() {
                @Override
                public Observable> call(Response response) {
                    try {
                        ServiceResponse clientResponse = updateDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    private ServiceResponse updateDelegate(Response response) throws ErrorException, IOException, IllegalArgumentException {
        return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter())
                .register(200, new TypeToken() { }.getType())
                .registerError(ErrorException.class)
                .build(response);
    }

    /**
     * Deletes a Cognitive Services account from the resource group.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @throws ErrorException thrown if the request is rejected by server
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
     */
    public void delete(String resourceGroupName, String accountName) {
        deleteWithServiceResponseAsync(resourceGroupName, accountName).toBlocking().single().body();
    }

    /**
     * Deletes a Cognitive Services account from the resource group.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceFuture} object
     */
    public ServiceFuture deleteAsync(String resourceGroupName, String accountName, final ServiceCallback serviceCallback) {
        return ServiceFuture.fromResponse(deleteWithServiceResponseAsync(resourceGroupName, accountName), serviceCallback);
    }

    /**
     * Deletes a Cognitive Services account from the resource group.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceResponse} object if successful.
     */
    public Observable deleteAsync(String resourceGroupName, String accountName) {
        return deleteWithServiceResponseAsync(resourceGroupName, accountName).map(new Func1, Void>() {
            @Override
            public Void call(ServiceResponse response) {
                return response.body();
            }
        });
    }

    /**
     * Deletes a Cognitive Services account from the resource group.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceResponse} object if successful.
     */
    public Observable> deleteWithServiceResponseAsync(String resourceGroupName, String accountName) {
        if (resourceGroupName == null) {
            throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
        }
        if (accountName == null) {
            throw new IllegalArgumentException("Parameter accountName is required and cannot be null.");
        }
        if (this.client.subscriptionId() == null) {
            throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
        }
        if (this.client.apiVersion() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
        }
        return service.delete(resourceGroupName, accountName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent())
            .flatMap(new Func1, Observable>>() {
                @Override
                public Observable> call(Response response) {
                    try {
                        ServiceResponse clientResponse = deleteDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    private ServiceResponse deleteDelegate(Response response) throws ErrorException, IOException, IllegalArgumentException {
        return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter())
                .register(200, new TypeToken() { }.getType())
                .register(204, new TypeToken() { }.getType())
                .registerError(ErrorException.class)
                .build(response);
    }

    /**
     * Returns a Cognitive Services account specified by the parameters.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @throws ErrorException thrown if the request is rejected by server
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
     * @return the CognitiveServicesAccountInner object if successful.
     */
    public CognitiveServicesAccountInner getByResourceGroup(String resourceGroupName, String accountName) {
        return getByResourceGroupWithServiceResponseAsync(resourceGroupName, accountName).toBlocking().single().body();
    }

    /**
     * Returns a Cognitive Services account specified by the parameters.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceFuture} object
     */
    public ServiceFuture getByResourceGroupAsync(String resourceGroupName, String accountName, final ServiceCallback serviceCallback) {
        return ServiceFuture.fromResponse(getByResourceGroupWithServiceResponseAsync(resourceGroupName, accountName), serviceCallback);
    }

    /**
     * Returns a Cognitive Services account specified by the parameters.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the CognitiveServicesAccountInner object
     */
    public Observable getByResourceGroupAsync(String resourceGroupName, String accountName) {
        return getByResourceGroupWithServiceResponseAsync(resourceGroupName, accountName).map(new Func1, CognitiveServicesAccountInner>() {
            @Override
            public CognitiveServicesAccountInner call(ServiceResponse response) {
                return response.body();
            }
        });
    }

    /**
     * Returns a Cognitive Services account specified by the parameters.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the CognitiveServicesAccountInner object
     */
    public Observable> getByResourceGroupWithServiceResponseAsync(String resourceGroupName, String accountName) {
        if (resourceGroupName == null) {
            throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
        }
        if (accountName == null) {
            throw new IllegalArgumentException("Parameter accountName is required and cannot be null.");
        }
        if (this.client.subscriptionId() == null) {
            throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
        }
        if (this.client.apiVersion() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
        }
        return service.getByResourceGroup(resourceGroupName, accountName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent())
            .flatMap(new Func1, Observable>>() {
                @Override
                public Observable> call(Response response) {
                    try {
                        ServiceResponse clientResponse = getByResourceGroupDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    private ServiceResponse getByResourceGroupDelegate(Response response) throws ErrorException, IOException, IllegalArgumentException {
        return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter())
                .register(200, new TypeToken() { }.getType())
                .registerError(ErrorException.class)
                .build(response);
    }

    /**
     * Lists the account keys for the specified Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @throws ErrorException thrown if the request is rejected by server
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
     * @return the CognitiveServicesAccountKeysInner object if successful.
     */
    public CognitiveServicesAccountKeysInner listKeys(String resourceGroupName, String accountName) {
        return listKeysWithServiceResponseAsync(resourceGroupName, accountName).toBlocking().single().body();
    }

    /**
     * Lists the account keys for the specified Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceFuture} object
     */
    public ServiceFuture listKeysAsync(String resourceGroupName, String accountName, final ServiceCallback serviceCallback) {
        return ServiceFuture.fromResponse(listKeysWithServiceResponseAsync(resourceGroupName, accountName), serviceCallback);
    }

    /**
     * Lists the account keys for the specified Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the CognitiveServicesAccountKeysInner object
     */
    public Observable listKeysAsync(String resourceGroupName, String accountName) {
        return listKeysWithServiceResponseAsync(resourceGroupName, accountName).map(new Func1, CognitiveServicesAccountKeysInner>() {
            @Override
            public CognitiveServicesAccountKeysInner call(ServiceResponse response) {
                return response.body();
            }
        });
    }

    /**
     * Lists the account keys for the specified Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the CognitiveServicesAccountKeysInner object
     */
    public Observable> listKeysWithServiceResponseAsync(String resourceGroupName, String accountName) {
        if (resourceGroupName == null) {
            throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
        }
        if (accountName == null) {
            throw new IllegalArgumentException("Parameter accountName is required and cannot be null.");
        }
        if (this.client.subscriptionId() == null) {
            throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
        }
        if (this.client.apiVersion() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
        }
        return service.listKeys(resourceGroupName, accountName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent())
            .flatMap(new Func1, Observable>>() {
                @Override
                public Observable> call(Response response) {
                    try {
                        ServiceResponse clientResponse = listKeysDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    private ServiceResponse listKeysDelegate(Response response) throws ErrorException, IOException, IllegalArgumentException {
        return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter())
                .register(200, new TypeToken() { }.getType())
                .registerError(ErrorException.class)
                .build(response);
    }

    /**
     * Regenerates the specified account key for the specified Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @param keyName key name to generate (Key1|Key2). Possible values include: 'Key1', 'Key2'
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @throws ErrorException thrown if the request is rejected by server
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
     * @return the CognitiveServicesAccountKeysInner object if successful.
     */
    public CognitiveServicesAccountKeysInner regenerateKey(String resourceGroupName, String accountName, KeyName keyName) {
        return regenerateKeyWithServiceResponseAsync(resourceGroupName, accountName, keyName).toBlocking().single().body();
    }

    /**
     * Regenerates the specified account key for the specified Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @param keyName key name to generate (Key1|Key2). Possible values include: 'Key1', 'Key2'
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceFuture} object
     */
    public ServiceFuture regenerateKeyAsync(String resourceGroupName, String accountName, KeyName keyName, final ServiceCallback serviceCallback) {
        return ServiceFuture.fromResponse(regenerateKeyWithServiceResponseAsync(resourceGroupName, accountName, keyName), serviceCallback);
    }

    /**
     * Regenerates the specified account key for the specified Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @param keyName key name to generate (Key1|Key2). Possible values include: 'Key1', 'Key2'
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the CognitiveServicesAccountKeysInner object
     */
    public Observable regenerateKeyAsync(String resourceGroupName, String accountName, KeyName keyName) {
        return regenerateKeyWithServiceResponseAsync(resourceGroupName, accountName, keyName).map(new Func1, CognitiveServicesAccountKeysInner>() {
            @Override
            public CognitiveServicesAccountKeysInner call(ServiceResponse response) {
                return response.body();
            }
        });
    }

    /**
     * Regenerates the specified account key for the specified Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @param keyName key name to generate (Key1|Key2). Possible values include: 'Key1', 'Key2'
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the CognitiveServicesAccountKeysInner object
     */
    public Observable> regenerateKeyWithServiceResponseAsync(String resourceGroupName, String accountName, KeyName keyName) {
        if (resourceGroupName == null) {
            throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
        }
        if (accountName == null) {
            throw new IllegalArgumentException("Parameter accountName is required and cannot be null.");
        }
        if (this.client.subscriptionId() == null) {
            throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
        }
        if (this.client.apiVersion() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
        }
        if (keyName == null) {
            throw new IllegalArgumentException("Parameter keyName is required and cannot be null.");
        }
        RegenerateKeyParameters parameters = new RegenerateKeyParameters();
        parameters.withKeyName(keyName);
        return service.regenerateKey(resourceGroupName, accountName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent())
            .flatMap(new Func1, Observable>>() {
                @Override
                public Observable> call(Response response) {
                    try {
                        ServiceResponse clientResponse = regenerateKeyDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    private ServiceResponse regenerateKeyDelegate(Response response) throws ErrorException, IOException, IllegalArgumentException {
        return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter())
                .register(200, new TypeToken() { }.getType())
                .registerError(ErrorException.class)
                .build(response);
    }

    /**
     * List available SKUs for the requested Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @throws ErrorException thrown if the request is rejected by server
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
     * @return the CognitiveServicesAccountEnumerateSkusResultInner object if successful.
     */
    public CognitiveServicesAccountEnumerateSkusResultInner listSkus(String resourceGroupName, String accountName) {
        return listSkusWithServiceResponseAsync(resourceGroupName, accountName).toBlocking().single().body();
    }

    /**
     * List available SKUs for the requested Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceFuture} object
     */
    public ServiceFuture listSkusAsync(String resourceGroupName, String accountName, final ServiceCallback serviceCallback) {
        return ServiceFuture.fromResponse(listSkusWithServiceResponseAsync(resourceGroupName, accountName), serviceCallback);
    }

    /**
     * List available SKUs for the requested Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the CognitiveServicesAccountEnumerateSkusResultInner object
     */
    public Observable listSkusAsync(String resourceGroupName, String accountName) {
        return listSkusWithServiceResponseAsync(resourceGroupName, accountName).map(new Func1, CognitiveServicesAccountEnumerateSkusResultInner>() {
            @Override
            public CognitiveServicesAccountEnumerateSkusResultInner call(ServiceResponse response) {
                return response.body();
            }
        });
    }

    /**
     * List available SKUs for the requested Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group within the user's subscription.
     * @param accountName The name of Cognitive Services account.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the CognitiveServicesAccountEnumerateSkusResultInner object
     */
    public Observable> listSkusWithServiceResponseAsync(String resourceGroupName, String accountName) {
        if (resourceGroupName == null) {
            throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
        }
        if (accountName == null) {
            throw new IllegalArgumentException("Parameter accountName is required and cannot be null.");
        }
        if (this.client.subscriptionId() == null) {
            throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
        }
        if (this.client.apiVersion() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
        }
        return service.listSkus(resourceGroupName, accountName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent())
            .flatMap(new Func1, Observable>>() {
                @Override
                public Observable> call(Response response) {
                    try {
                        ServiceResponse clientResponse = listSkusDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    private ServiceResponse listSkusDelegate(Response response) throws ErrorException, IOException, IllegalArgumentException {
        return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter())
                .register(200, new TypeToken() { }.getType())
                .registerError(ErrorException.class)
                .build(response);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy