/** * 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.search.implementation; import retrofit2.Retrofit; import com.google.common.reflect.TypeToken; import com.microsoft.azure.CloudException; import com.microsoft.rest.ServiceFuture; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; import java.io.IOException; import okhttp3.ResponseBody; import retrofit2.http.Header; import retrofit2.http.Headers; import retrofit2.http.Path; import retrofit2.http.POST; 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 AdminKeys. */ public final class AdminKeysInner { /** The Retrofit service to perform REST calls. */ private AdminKeysService service; /** The service client containing this operation class. */ private SearchManagementClientImpl client; /** * Initializes an instance of AdminKeysInner. * * @param retrofit the Retrofit instance built from a Retrofit Builder. * @param client the instance of the service client containing this operation class. */ public AdminKeysInner(Retrofit retrofit, SearchManagementClientImpl client) { this.service = retrofit.create(AdminKeysService.class); this.client = client; } /** * The interface defining all the services for AdminKeys to be * used by Retrofit to perform actually REST calls. */ interface AdminKeysService { @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.search.AdminKeys list" }) @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Search/searchServices/{serviceName}/listAdminKeys") Observable<Response<ResponseBody>> list(@Path("resourceGroupName") String resourceGroupName, @Path("serviceName") String serviceName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); } /** * Returns the primary and secondary API keys for the given Azure Search service. * * @param resourceGroupName The name of the resource group within the current subscription. * @param serviceName The name of the Search service for which to list admin keys. * @return the AdminKeyResultInner object if successful. */ public AdminKeyResultInner list(String resourceGroupName, String serviceName) { return listWithServiceResponseAsync(resourceGroupName, serviceName).toBlocking().single().body(); } /** * Returns the primary and secondary API keys for the given Azure Search service. * * @param resourceGroupName The name of the resource group within the current subscription. * @param serviceName The name of the Search service for which to list admin keys. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. * @return the {@link ServiceFuture} object */ public ServiceFuture<AdminKeyResultInner> listAsync(String resourceGroupName, String serviceName, final ServiceCallback<AdminKeyResultInner> serviceCallback) { return ServiceFuture.fromResponse(listWithServiceResponseAsync(resourceGroupName, serviceName), serviceCallback); } /** * Returns the primary and secondary API keys for the given Azure Search service. * * @param resourceGroupName The name of the resource group within the current subscription. * @param serviceName The name of the Search service for which to list admin keys. * @return the observable to the AdminKeyResultInner object */ public Observable<AdminKeyResultInner> listAsync(String resourceGroupName, String serviceName) { return listWithServiceResponseAsync(resourceGroupName, serviceName).map(new Func1<ServiceResponse<AdminKeyResultInner>, AdminKeyResultInner>() { @Override public AdminKeyResultInner call(ServiceResponse<AdminKeyResultInner> response) { return response.body(); } }); } /** * Returns the primary and secondary API keys for the given Azure Search service. * * @param resourceGroupName The name of the resource group within the current subscription. * @param serviceName The name of the Search service for which to list admin keys. * @return the observable to the AdminKeyResultInner object */ public Observable<ServiceResponse<AdminKeyResultInner>> listWithServiceResponseAsync(String resourceGroupName, String serviceName) { if (resourceGroupName == null) { throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } if (serviceName == null) { throw new IllegalArgumentException("Parameter serviceName 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.list(resourceGroupName, serviceName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<AdminKeyResultInner>>>() { @Override public Observable<ServiceResponse<AdminKeyResultInner>> call(Response<ResponseBody> response) { try { ServiceResponse<AdminKeyResultInner> clientResponse = listDelegate(response); return Observable.just(clientResponse); } catch (Throwable t) { return Observable.error(t); } } }); } private ServiceResponse<AdminKeyResultInner> listDelegate(Response<ResponseBody> response) throws CloudException, IOException, IllegalArgumentException { return this.client.restClient().responseBuilderFactory().<AdminKeyResultInner, CloudException>newInstance(this.client.serializerAdapter()) .register(200, new TypeToken<AdminKeyResultInner>() { }.getType()) .registerError(CloudException.class) .build(response); } }