diff --git a/Samples/azure-storage/Azure.Java.Fluent/implementation/StorageAccountsInner.java b/Samples/azure-storage/Azure.Java.Fluent/implementation/StorageAccountsInner.java index 7c406fffa0..bff3d92085 100644 --- a/Samples/azure-storage/Azure.Java.Fluent/implementation/StorageAccountsInner.java +++ b/Samples/azure-storage/Azure.Java.Fluent/implementation/StorageAccountsInner.java @@ -10,13 +10,10 @@ import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; -import com.microsoft.rest.ServiceResponseCallback; import com.microsoft.rest.Validator; import java.io.IOException; import java.util.List; import okhttp3.ResponseBody; -import retrofit2.Call; -import retrofit2.Callback; import retrofit2.http.Body; import retrofit2.http.GET; import retrofit2.http.Header; @@ -28,6 +25,8 @@ 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 @@ -57,43 +56,43 @@ public StorageAccountsInner(Retrofit retrofit, StorageManagementClientImpl clien interface StorageAccountsService { @Headers("Content-Type: application/json; charset=utf-8") @POST("subscriptions/{subscriptionId}/providers/Microsoft.Storage/checkNameAvailability") - Call checkNameAvailability(@Path("subscriptionId") String subscriptionId, @Body StorageAccountCheckNameAvailabilityParametersInner accountName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> checkNameAvailability(@Path("subscriptionId") String subscriptionId, @Body StorageAccountCheckNameAvailabilityParametersInner accountName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @PUT("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}") - Call create(@Path("resourceGroupName") String resourceGroupName, @Path("accountName") String accountName, @Path("subscriptionId") String subscriptionId, @Body StorageAccountCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> create(@Path("resourceGroupName") String resourceGroupName, @Path("accountName") String accountName, @Path("subscriptionId") String subscriptionId, @Body StorageAccountCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @PUT("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}") - Call beginCreate(@Path("resourceGroupName") String resourceGroupName, @Path("accountName") String accountName, @Path("subscriptionId") String subscriptionId, @Body StorageAccountCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> beginCreate(@Path("resourceGroupName") String resourceGroupName, @Path("accountName") String accountName, @Path("subscriptionId") String subscriptionId, @Body StorageAccountCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @HTTP(path = "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}", method = "DELETE", hasBody = true) - Call 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); + 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") @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}") - Call getProperties(@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); + Observable> getProperties(@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") @PATCH("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}") - Call update(@Path("resourceGroupName") String resourceGroupName, @Path("accountName") String accountName, @Path("subscriptionId") String subscriptionId, @Body StorageAccountUpdateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> update(@Path("resourceGroupName") String resourceGroupName, @Path("accountName") String accountName, @Path("subscriptionId") String subscriptionId, @Body StorageAccountUpdateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/listKeys") - Call 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); + 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") @GET("subscriptions/{subscriptionId}/providers/Microsoft.Storage/storageAccounts") - Call list(@Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> list(@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") @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts") - Call listByResourceGroup(@Path("resourceGroupName") String resourceGroupName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> listByResourceGroup(@Path("resourceGroupName") String resourceGroupName, @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") @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/regenerateKey") - Call regenerateKey(@Path("resourceGroupName") String resourceGroupName, @Path("accountName") String accountName, @Path("subscriptionId") String subscriptionId, @Body StorageAccountRegenerateKeyParametersInner regenerateKey, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> regenerateKey(@Path("resourceGroupName") String resourceGroupName, @Path("accountName") String accountName, @Path("subscriptionId") String subscriptionId, @Body StorageAccountRegenerateKeyParametersInner regenerateKey, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); } @@ -107,18 +106,7 @@ interface StorageAccountsService { * @return the CheckNameAvailabilityResultInner object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse checkNameAvailability(StorageAccountCheckNameAvailabilityParametersInner accountName) throws CloudException, IOException, IllegalArgumentException { - if (this.client.subscriptionId() == null) { - throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); - } - if (accountName == null) { - throw new IllegalArgumentException("Parameter accountName 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(accountName); - Call call = service.checkNameAvailability(this.client.subscriptionId(), accountName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return checkNameAvailabilityDelegate(call.execute()); + return checkNameAvailabilityAsync(accountName).toBlocking().single(); } /** @@ -126,9 +114,19 @@ public ServiceResponse checkNameAvailability(S * * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall checkNameAvailabilityAsync(StorageAccountCheckNameAvailabilityParametersInner accountName, final ServiceCallback serviceCallback) { + return ServiceCall.create(checkNameAvailabilityAsync(accountName), serviceCallback); + } + + /** + * Checks that account name is valid and is not in use. + * + * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + * @return the observable to the CheckNameAvailabilityResultInner object + */ + public Observable> checkNameAvailabilityAsync(StorageAccountCheckNameAvailabilityParametersInner accountName) { if (this.client.subscriptionId() == null) { throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); } @@ -139,26 +137,18 @@ public ServiceCall checkNameAvailabilityAsync( throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } Validator.validate(accountName); - Call call = service.checkNameAvailability(this.client.subscriptionId(), accountName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = checkNameAvailabilityDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); + return service.checkNameAvailability(this.client.subscriptionId(), accountName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = checkNameAvailabilityDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.success(clientResponse); - } catch (CloudException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse checkNameAvailabilityDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -181,24 +171,7 @@ private ServiceResponse checkNameAvailabilityD * @return the StorageAccountInner object wrapped in ServiceResponse if successful. */ public ServiceResponse create(String resourceGroupName, String accountName, StorageAccountCreateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException, InterruptedException { - 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); - Response result = service.create(resourceGroupName, accountName, this.client.subscriptionId(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()).execute(); - return client.getAzureClient().getPutOrPatchResult(result, new TypeToken() { }.getType()); + return createAsync(resourceGroupName, accountName, parameters).toBlocking().last(); } /** @@ -211,6 +184,18 @@ public ServiceResponse create(String resourceGroupName, Str * @return the {@link ServiceCall} object */ public ServiceCall createAsync(String resourceGroupName, String accountName, StorageAccountCreateParametersInner parameters, final ServiceCallback serviceCallback) { + return ServiceCall.create(createAsync(resourceGroupName, accountName, parameters), serviceCallback); + } + + /** + * Asynchronously creates a new storage account with the specified parameters. Existing accounts cannot be updated with this API and should instead use the Update Storage Account API. If an account is already created and subsequent PUT request is issued with exact same set of properties, then HTTP 200 would be returned. + * + * @param resourceGroupName The name of the resource group within the user's subscription. + * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + * @param parameters The parameters to provide for the created account. + * @return the observable for the request + */ + public Observable> createAsync(String resourceGroupName, String accountName, StorageAccountCreateParametersInner parameters) { if (resourceGroupName == null) { throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } @@ -227,22 +212,8 @@ public ServiceCall createAsync(String resourceGroupName, St throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } Validator.validate(parameters); - Call call = service.create(resourceGroupName, accountName, this.client.subscriptionId(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new Callback() { - @Override - public void onFailure(Call call, Throwable t) { - if (serviceCallback != null) { - serviceCallback.failure(t); - } - serviceCall.failure(t); - } - @Override - public void onResponse(Call call, Response response) { - client.getAzureClient().getPutOrPatchResultAsync(response, new TypeToken() { }.getType(), serviceCall, serviceCallback); - } - }); - return serviceCall; + Observable> observable = service.create(resourceGroupName, accountName, this.client.subscriptionId(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return client.getAzureClient().getPutOrPatchResultAsync(observable, new TypeToken() { }.getType()); } /** @@ -257,24 +228,7 @@ public void onResponse(Call call, Response response) * @return the StorageAccountInner object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse beginCreate(String resourceGroupName, String accountName, StorageAccountCreateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { - 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); - Call call = service.beginCreate(resourceGroupName, accountName, this.client.subscriptionId(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return beginCreateDelegate(call.execute()); + return beginCreateAsync(resourceGroupName, accountName, parameters).toBlocking().single(); } /** @@ -284,9 +238,21 @@ public ServiceResponse beginCreate(String resourceGroupName * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. * @param parameters The parameters to provide for the created account. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall beginCreateAsync(String resourceGroupName, String accountName, StorageAccountCreateParametersInner parameters, final ServiceCallback serviceCallback) { + return ServiceCall.create(beginCreateAsync(resourceGroupName, accountName, parameters), serviceCallback); + } + + /** + * Asynchronously creates a new storage account with the specified parameters. Existing accounts cannot be updated with this API and should instead use the Update Storage Account API. If an account is already created and subsequent PUT request is issued with exact same set of properties, then HTTP 200 would be returned. + * + * @param resourceGroupName The name of the resource group within the user's subscription. + * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + * @param parameters The parameters to provide for the created account. + * @return the observable to the StorageAccountInner object + */ + public Observable> beginCreateAsync(String resourceGroupName, String accountName, StorageAccountCreateParametersInner parameters) { if (resourceGroupName == null) { throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } @@ -303,26 +269,18 @@ public ServiceCall beginCreateAsync(String resourceGroupNam throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } Validator.validate(parameters); - Call call = service.beginCreate(resourceGroupName, accountName, this.client.subscriptionId(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = beginCreateDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (CloudException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.beginCreate(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 = beginCreateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse beginCreateDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -344,20 +302,7 @@ private ServiceResponse beginCreateDelegate(Response delete(String resourceGroupName, String accountName) throws CloudException, IOException, IllegalArgumentException { - 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."); - } - Call call = service.delete(resourceGroupName, accountName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return deleteDelegate(call.execute()); + return deleteAsync(resourceGroupName, accountName).toBlocking().single(); } /** @@ -366,9 +311,20 @@ public ServiceResponse delete(String resourceGroupName, String accountName * @param resourceGroupName The name of the resource group within the user's subscription. * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall deleteAsync(String resourceGroupName, String accountName, final ServiceCallback serviceCallback) { + return ServiceCall.create(deleteAsync(resourceGroupName, accountName), serviceCallback); + } + + /** + * Deletes a storage account in Microsoft Azure. + * + * @param resourceGroupName The name of the resource group within the user's subscription. + * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> deleteAsync(String resourceGroupName, String accountName) { if (resourceGroupName == null) { throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } @@ -381,26 +337,18 @@ public ServiceCall deleteAsync(String resourceGroupName, String accountNam if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.delete(resourceGroupName, accountName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = deleteDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (CloudException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + 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); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse deleteDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -421,20 +369,7 @@ private ServiceResponse deleteDelegate(Response response) th * @return the StorageAccountInner object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse getProperties(String resourceGroupName, String accountName) throws CloudException, IOException, IllegalArgumentException { - 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."); - } - Call call = service.getProperties(resourceGroupName, accountName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return getPropertiesDelegate(call.execute()); + return getPropertiesAsync(resourceGroupName, accountName).toBlocking().single(); } /** @@ -443,9 +378,20 @@ public ServiceResponse getProperties(String resourceGroupNa * @param resourceGroupName The name of the resource group within the user's subscription. * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall getPropertiesAsync(String resourceGroupName, String accountName, final ServiceCallback serviceCallback) { + return ServiceCall.create(getPropertiesAsync(resourceGroupName, accountName), serviceCallback); + } + + /** + * Returns the properties for the specified storage account including but not limited to name, account type, location, and account status. The ListKeys operation should be used to retrieve storage keys. + * + * @param resourceGroupName The name of the resource group within the user's subscription. + * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + * @return the observable to the StorageAccountInner object + */ + public Observable> getPropertiesAsync(String resourceGroupName, String accountName) { if (resourceGroupName == null) { throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } @@ -458,26 +404,18 @@ public ServiceCall getPropertiesAsync(String resourceGroupN if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.getProperties(resourceGroupName, accountName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = getPropertiesDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); + return service.getProperties(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 = getPropertiesDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.success(clientResponse); - } catch (CloudException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse getPropertiesDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -499,24 +437,7 @@ private ServiceResponse getPropertiesDelegate(Response update(String resourceGroupName, String accountName, StorageAccountUpdateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { - 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); - Call call = service.update(resourceGroupName, accountName, this.client.subscriptionId(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return updateDelegate(call.execute()); + return updateAsync(resourceGroupName, accountName, parameters).toBlocking().single(); } /** @@ -526,9 +447,21 @@ public ServiceResponse update(String resourceGroupName, Str * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. * @param parameters The parameters to update on the account. Note that only one property can be changed at a time using this API. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall updateAsync(String resourceGroupName, String accountName, StorageAccountUpdateParametersInner parameters, final ServiceCallback serviceCallback) { + return ServiceCall.create(updateAsync(resourceGroupName, accountName, parameters), serviceCallback); + } + + /** + * Updates the account type or tags for a storage account. It can also be used to add a custom domain (note that custom domains cannot be added via the Create operation). Only one custom domain is supported per storage account. In order to replace a custom domain, the old value must be cleared before a new value may be set. To clear a custom domain, simply update the custom domain with empty string. Then call update again with the new cutsom domain name. The update API can only be used to update one of tags, accountType, or customDomain per call. To update multiple of these properties, call the API multiple times with one change per call. This call does not change the storage keys for the account. If you want to change storage account keys, use the RegenerateKey operation. The location and name of the storage account cannot be changed after creation. + * + * @param resourceGroupName The name of the resource group within the user's subscription. + * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + * @param parameters The parameters to update on the account. Note that only one property can be changed at a time using this API. + * @return the observable to the StorageAccountInner object + */ + public Observable> updateAsync(String resourceGroupName, String accountName, StorageAccountUpdateParametersInner parameters) { if (resourceGroupName == null) { throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } @@ -545,26 +478,18 @@ public ServiceCall updateAsync(String resourceGroupName, St throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } Validator.validate(parameters); - Call call = service.update(resourceGroupName, accountName, this.client.subscriptionId(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = updateDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (CloudException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.update(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 = updateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse updateDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -585,20 +510,7 @@ private ServiceResponse updateDelegate(Response listKeys(String resourceGroupName, String accountName) throws CloudException, IOException, IllegalArgumentException { - 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."); - } - Call call = service.listKeys(resourceGroupName, accountName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return listKeysDelegate(call.execute()); + return listKeysAsync(resourceGroupName, accountName).toBlocking().single(); } /** @@ -607,9 +519,20 @@ public ServiceResponse listKeys(String resourceGroupNam * @param resourceGroupName The name of the resource group. * @param accountName The name of the storage account. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall listKeysAsync(String resourceGroupName, String accountName, final ServiceCallback serviceCallback) { + return ServiceCall.create(listKeysAsync(resourceGroupName, accountName), serviceCallback); + } + + /** + * Lists the access keys for the specified storage account. + * + * @param resourceGroupName The name of the resource group. + * @param accountName The name of the storage account. + * @return the observable to the StorageAccountKeysInner object + */ + public Observable> listKeysAsync(String resourceGroupName, String accountName) { if (resourceGroupName == null) { throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } @@ -622,26 +545,18 @@ public ServiceCall listKeysAsync(String resourceGroupNa if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.listKeys(resourceGroupName, accountName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = listKeysDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); + 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); } - serviceCall.success(clientResponse); - } catch (CloudException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse listKeysDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -660,48 +575,44 @@ private ServiceResponse listKeysDelegate(Response> list() throws CloudException, IOException, IllegalArgumentException { - 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."); - } - Call call = service.list(this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - List result = response.getBody().getItems(); - return new ServiceResponse<>(result, response.getResponse()); + return listAsync().toBlocking().single(); } /** * Lists all the storage accounts available under the subscription. Note that storage keys are not returned; use the ListKeys operation for this. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall> listAsync(final ServiceCallback> serviceCallback) { + return ServiceCall.create(listAsync(), serviceCallback); + } + + /** + * Lists all the storage accounts available under the subscription. Note that storage keys are not returned; use the ListKeys operation for this. + * + * @return the observable to the List<StorageAccountInner> object + */ + public Observable>> listAsync() { 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."); } - Call call = service.list(this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); - } catch (CloudException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.list(this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + ServiceResponse> clientResponse = new ServiceResponse>(result.getBody().getItems(), result.getResponse()); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse> listDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -721,19 +632,7 @@ private ServiceResponse> listDelegate(Response> listByResourceGroup(String resourceGroupName) throws CloudException, IOException, IllegalArgumentException { - if (resourceGroupName == null) { - throw new IllegalArgumentException("Parameter resourceGroupName 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."); - } - Call call = service.listByResourceGroup(resourceGroupName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listByResourceGroupDelegate(call.execute()); - List result = response.getBody().getItems(); - return new ServiceResponse<>(result, response.getResponse()); + return listByResourceGroupAsync(resourceGroupName).toBlocking().single(); } /** @@ -741,9 +640,19 @@ public ServiceResponse> listByResourceGroup(String res * * @param resourceGroupName The name of the resource group within the user's subscription. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall> listByResourceGroupAsync(String resourceGroupName, final ServiceCallback> serviceCallback) { + return ServiceCall.create(listByResourceGroupAsync(resourceGroupName), serviceCallback); + } + + /** + * Lists all the storage accounts available under the given resource group. Note that storage keys are not returned; use the ListKeys operation for this. + * + * @param resourceGroupName The name of the resource group within the user's subscription. + * @return the observable to the List<StorageAccountInner> object + */ + public Observable>> listByResourceGroupAsync(String resourceGroupName) { if (resourceGroupName == null) { throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } @@ -753,23 +662,19 @@ public ServiceCall> listByResourceGroupAsync(String re if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.listByResourceGroup(resourceGroupName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listByResourceGroupDelegate(response); - serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); - } catch (CloudException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.listByResourceGroup(resourceGroupName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByResourceGroupDelegate(response); + ServiceResponse> clientResponse = new ServiceResponse>(result.getBody().getItems(), result.getResponse()); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse> listByResourceGroupDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -791,24 +696,7 @@ private ServiceResponse> listByResourceGroupDelega * @return the StorageAccountKeysInner object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse regenerateKey(String resourceGroupName, String accountName, StorageAccountRegenerateKeyParametersInner regenerateKey) throws CloudException, IOException, IllegalArgumentException { - 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 (regenerateKey == null) { - throw new IllegalArgumentException("Parameter regenerateKey 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(regenerateKey); - Call call = service.regenerateKey(resourceGroupName, accountName, this.client.subscriptionId(), regenerateKey, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return regenerateKeyDelegate(call.execute()); + return regenerateKeyAsync(resourceGroupName, accountName, regenerateKey).toBlocking().single(); } /** @@ -818,9 +706,21 @@ public ServiceResponse regenerateKey(String resourceGro * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. * @param regenerateKey Specifies name of the key which should be regenerated. key1 or key2 for the default keys * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall regenerateKeyAsync(String resourceGroupName, String accountName, StorageAccountRegenerateKeyParametersInner regenerateKey, final ServiceCallback serviceCallback) { + return ServiceCall.create(regenerateKeyAsync(resourceGroupName, accountName, regenerateKey), serviceCallback); + } + + /** + * Regenerates the access keys for the specified storage account. + * + * @param resourceGroupName The name of the resource group within the user's subscription. + * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + * @param regenerateKey Specifies name of the key which should be regenerated. key1 or key2 for the default keys + * @return the observable to the StorageAccountKeysInner object + */ + public Observable> regenerateKeyAsync(String resourceGroupName, String accountName, StorageAccountRegenerateKeyParametersInner regenerateKey) { if (resourceGroupName == null) { throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } @@ -837,26 +737,18 @@ public ServiceCall regenerateKeyAsync(String resourceGr throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } Validator.validate(regenerateKey); - Call call = service.regenerateKey(resourceGroupName, accountName, this.client.subscriptionId(), regenerateKey, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = regenerateKeyDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (CloudException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.regenerateKey(resourceGroupName, accountName, this.client.subscriptionId(), regenerateKey, this.client.apiVersion(), this.client.acceptLanguage(), 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); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse regenerateKeyDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { diff --git a/Samples/azure-storage/Azure.Java.Fluent/implementation/UsagesInner.java b/Samples/azure-storage/Azure.Java.Fluent/implementation/UsagesInner.java index 91ac73e611..96ad3d59be 100644 --- a/Samples/azure-storage/Azure.Java.Fluent/implementation/UsagesInner.java +++ b/Samples/azure-storage/Azure.Java.Fluent/implementation/UsagesInner.java @@ -10,17 +10,17 @@ import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; -import com.microsoft.rest.ServiceResponseCallback; import java.io.IOException; import java.util.List; import okhttp3.ResponseBody; -import retrofit2.Call; import retrofit2.http.GET; import retrofit2.http.Header; import retrofit2.http.Headers; import retrofit2.http.Path; 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 @@ -50,7 +50,7 @@ public UsagesInner(Retrofit retrofit, StorageManagementClientImpl client) { interface UsagesService { @Headers("Content-Type: application/json; charset=utf-8") @GET("subscriptions/{subscriptionId}/providers/Microsoft.Storage/usages") - Call list(@Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> list(@Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); } @@ -63,48 +63,44 @@ interface UsagesService { * @return the List<UsageInner> object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse> list() throws CloudException, IOException, IllegalArgumentException { - 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."); - } - Call call = service.list(this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - List result = response.getBody().getItems(); - return new ServiceResponse<>(result, response.getResponse()); + return listAsync().toBlocking().single(); } /** * Gets the current usage count and the limit for the resources under the subscription. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall> listAsync(final ServiceCallback> serviceCallback) { + return ServiceCall.create(listAsync(), serviceCallback); + } + + /** + * Gets the current usage count and the limit for the resources under the subscription. + * + * @return the observable to the List<UsageInner> object + */ + public Observable>> listAsync() { 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."); } - Call call = service.list(this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); - } catch (CloudException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.list(this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + ServiceResponse> clientResponse = new ServiceResponse>(result.getBody().getItems(), result.getResponse()); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse> listDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { diff --git a/Samples/azure-storage/Azure.Java/StorageAccounts.java b/Samples/azure-storage/Azure.Java/StorageAccounts.java index 0afceb92d6..6ec33f1e5b 100644 --- a/Samples/azure-storage/Azure.Java/StorageAccounts.java +++ b/Samples/azure-storage/Azure.Java/StorageAccounts.java @@ -16,6 +16,7 @@ import petstore.models.StorageAccountKeys; import petstore.models.StorageAccountRegenerateKeyParameters; import petstore.models.StorageAccountUpdateParameters; +import rx.Observable; /** * An instance of this class provides access to all the operations defined @@ -38,10 +39,17 @@ public interface StorageAccounts { * * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall checkNameAvailabilityAsync(StorageAccountCheckNameAvailabilityParameters accountName, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall checkNameAvailabilityAsync(StorageAccountCheckNameAvailabilityParameters accountName, final ServiceCallback serviceCallback); + + /** + * Checks that account name is valid and is not in use. + * + * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + * @return the observable to the CheckNameAvailabilityResult object + */ + Observable> checkNameAvailabilityAsync(StorageAccountCheckNameAvailabilityParameters accountName); /** * Asynchronously creates a new storage account with the specified parameters. Existing accounts cannot be updated with this API and should instead use the Update Storage Account API. If an account is already created and subsequent PUT request is issued with exact same set of properties, then HTTP 200 would be returned. @@ -64,10 +72,19 @@ public interface StorageAccounts { * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. * @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 callback is null * @return the {@link ServiceCall} object */ - ServiceCall createAsync(String resourceGroupName, String accountName, StorageAccountCreateParameters parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall createAsync(String resourceGroupName, String accountName, StorageAccountCreateParameters parameters, final ServiceCallback serviceCallback); + + /** + * Asynchronously creates a new storage account with the specified parameters. Existing accounts cannot be updated with this API and should instead use the Update Storage Account API. If an account is already created and subsequent PUT request is issued with exact same set of properties, then HTTP 200 would be returned. + * + * @param resourceGroupName The name of the resource group within the user's subscription. + * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + * @param parameters The parameters to provide for the created account. + * @return the observable to the StorageAccount object + */ + Observable> createAsync(String resourceGroupName, String accountName, StorageAccountCreateParameters parameters); /** * Asynchronously creates a new storage account with the specified parameters. Existing accounts cannot be updated with this API and should instead use the Update Storage Account API. If an account is already created and subsequent PUT request is issued with exact same set of properties, then HTTP 200 would be returned. @@ -89,10 +106,19 @@ public interface StorageAccounts { * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. * @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 callback is null * @return the {@link ServiceCall} object */ - ServiceCall beginCreateAsync(String resourceGroupName, String accountName, StorageAccountCreateParameters parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall beginCreateAsync(String resourceGroupName, String accountName, StorageAccountCreateParameters parameters, final ServiceCallback serviceCallback); + + /** + * Asynchronously creates a new storage account with the specified parameters. Existing accounts cannot be updated with this API and should instead use the Update Storage Account API. If an account is already created and subsequent PUT request is issued with exact same set of properties, then HTTP 200 would be returned. + * + * @param resourceGroupName The name of the resource group within the user's subscription. + * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + * @param parameters The parameters to provide for the created account. + * @return the observable to the StorageAccount object + */ + Observable> beginCreateAsync(String resourceGroupName, String accountName, StorageAccountCreateParameters parameters); /** * Deletes a storage account in Microsoft Azure. @@ -112,10 +138,18 @@ public interface StorageAccounts { * @param resourceGroupName The name of the resource group within the user's subscription. * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall deleteAsync(String resourceGroupName, String accountName, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall deleteAsync(String resourceGroupName, String accountName, final ServiceCallback serviceCallback); + + /** + * Deletes a storage account in Microsoft Azure. + * + * @param resourceGroupName The name of the resource group within the user's subscription. + * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + * @return the {@link ServiceResponse} object if successful. + */ + Observable> deleteAsync(String resourceGroupName, String accountName); /** * Returns the properties for the specified storage account including but not limited to name, account type, location, and account status. The ListKeys operation should be used to retrieve storage keys. @@ -135,10 +169,18 @@ public interface StorageAccounts { * @param resourceGroupName The name of the resource group within the user's subscription. * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall getPropertiesAsync(String resourceGroupName, String accountName, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall getPropertiesAsync(String resourceGroupName, String accountName, final ServiceCallback serviceCallback); + + /** + * Returns the properties for the specified storage account including but not limited to name, account type, location, and account status. The ListKeys operation should be used to retrieve storage keys. + * + * @param resourceGroupName The name of the resource group within the user's subscription. + * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + * @return the observable to the StorageAccount object + */ + Observable> getPropertiesAsync(String resourceGroupName, String accountName); /** * Updates the account type or tags for a storage account. It can also be used to add a custom domain (note that custom domains cannot be added via the Create operation). Only one custom domain is supported per storage account. In order to replace a custom domain, the old value must be cleared before a new value may be set. To clear a custom domain, simply update the custom domain with empty string. Then call update again with the new cutsom domain name. The update API can only be used to update one of tags, accountType, or customDomain per call. To update multiple of these properties, call the API multiple times with one change per call. This call does not change the storage keys for the account. If you want to change storage account keys, use the RegenerateKey operation. The location and name of the storage account cannot be changed after creation. @@ -160,10 +202,19 @@ public interface StorageAccounts { * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. * @param parameters The parameters to update on the account. Note that only one property can be changed at a time using this API. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall updateAsync(String resourceGroupName, String accountName, StorageAccountUpdateParameters parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall updateAsync(String resourceGroupName, String accountName, StorageAccountUpdateParameters parameters, final ServiceCallback serviceCallback); + + /** + * Updates the account type or tags for a storage account. It can also be used to add a custom domain (note that custom domains cannot be added via the Create operation). Only one custom domain is supported per storage account. In order to replace a custom domain, the old value must be cleared before a new value may be set. To clear a custom domain, simply update the custom domain with empty string. Then call update again with the new cutsom domain name. The update API can only be used to update one of tags, accountType, or customDomain per call. To update multiple of these properties, call the API multiple times with one change per call. This call does not change the storage keys for the account. If you want to change storage account keys, use the RegenerateKey operation. The location and name of the storage account cannot be changed after creation. + * + * @param resourceGroupName The name of the resource group within the user's subscription. + * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + * @param parameters The parameters to update on the account. Note that only one property can be changed at a time using this API. + * @return the observable to the StorageAccount object + */ + Observable> updateAsync(String resourceGroupName, String accountName, StorageAccountUpdateParameters parameters); /** * Lists the access keys for the specified storage account. @@ -183,10 +234,18 @@ public interface StorageAccounts { * @param resourceGroupName The name of the resource group. * @param accountName The name of the storage account. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall listKeysAsync(String resourceGroupName, String accountName, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall listKeysAsync(String resourceGroupName, String accountName, final ServiceCallback serviceCallback); + + /** + * Lists the access keys for the specified storage account. + * + * @param resourceGroupName The name of the resource group. + * @param accountName The name of the storage account. + * @return the observable to the StorageAccountKeys object + */ + Observable> listKeysAsync(String resourceGroupName, String accountName); /** * Lists all the storage accounts available under the subscription. Note that storage keys are not returned; use the ListKeys operation for this. @@ -202,10 +261,16 @@ public interface StorageAccounts { * Lists all the storage accounts available under the subscription. Note that storage keys are not returned; use the ListKeys operation for this. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall> listAsync(final ServiceCallback> serviceCallback) throws IllegalArgumentException; + ServiceCall> listAsync(final ServiceCallback> serviceCallback); + + /** + * Lists all the storage accounts available under the subscription. Note that storage keys are not returned; use the ListKeys operation for this. + * + * @return the observable to the List<StorageAccount> object + */ + Observable>> listAsync(); /** * Lists all the storage accounts available under the given resource group. Note that storage keys are not returned; use the ListKeys operation for this. @@ -223,10 +288,17 @@ public interface StorageAccounts { * * @param resourceGroupName The name of the resource group within the user's subscription. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall> listByResourceGroupAsync(String resourceGroupName, final ServiceCallback> serviceCallback) throws IllegalArgumentException; + ServiceCall> listByResourceGroupAsync(String resourceGroupName, final ServiceCallback> serviceCallback); + + /** + * Lists all the storage accounts available under the given resource group. Note that storage keys are not returned; use the ListKeys operation for this. + * + * @param resourceGroupName The name of the resource group within the user's subscription. + * @return the observable to the List<StorageAccount> object + */ + Observable>> listByResourceGroupAsync(String resourceGroupName); /** * Regenerates the access keys for the specified storage account. @@ -248,9 +320,18 @@ public interface StorageAccounts { * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. * @param regenerateKey Specifies name of the key which should be regenerated. key1 or key2 for the default keys * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall regenerateKeyAsync(String resourceGroupName, String accountName, StorageAccountRegenerateKeyParameters regenerateKey, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall regenerateKeyAsync(String resourceGroupName, String accountName, StorageAccountRegenerateKeyParameters regenerateKey, final ServiceCallback serviceCallback); + + /** + * Regenerates the access keys for the specified storage account. + * + * @param resourceGroupName The name of the resource group within the user's subscription. + * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + * @param regenerateKey Specifies name of the key which should be regenerated. key1 or key2 for the default keys + * @return the observable to the StorageAccountKeys object + */ + Observable> regenerateKeyAsync(String resourceGroupName, String accountName, StorageAccountRegenerateKeyParameters regenerateKey); } diff --git a/Samples/azure-storage/Azure.Java/Usages.java b/Samples/azure-storage/Azure.Java/Usages.java index e357702b54..3c1ebd66cc 100644 --- a/Samples/azure-storage/Azure.Java/Usages.java +++ b/Samples/azure-storage/Azure.Java/Usages.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.util.List; import petstore.models.Usage; +import rx.Observable; /** * An instance of this class provides access to all the operations defined @@ -30,9 +31,15 @@ public interface Usages { * Gets the current usage count and the limit for the resources under the subscription. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall> listAsync(final ServiceCallback> serviceCallback) throws IllegalArgumentException; + ServiceCall> listAsync(final ServiceCallback> serviceCallback); + + /** + * Gets the current usage count and the limit for the resources under the subscription. + * + * @return the observable to the List<Usage> object + */ + Observable>> listAsync(); } diff --git a/Samples/azure-storage/Azure.Java/implementation/StorageAccountsImpl.java b/Samples/azure-storage/Azure.Java/implementation/StorageAccountsImpl.java index da04acfd47..61ba77f32a 100644 --- a/Samples/azure-storage/Azure.Java/implementation/StorageAccountsImpl.java +++ b/Samples/azure-storage/Azure.Java/implementation/StorageAccountsImpl.java @@ -11,7 +11,6 @@ import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; -import com.microsoft.rest.ServiceResponseCallback; import com.microsoft.rest.Validator; import java.io.IOException; import java.util.List; @@ -24,8 +23,6 @@ import petstore.models.StorageAccountKeys; import petstore.models.StorageAccountRegenerateKeyParameters; import petstore.models.StorageAccountUpdateParameters; -import retrofit2.Call; -import retrofit2.Callback; import retrofit2.http.Body; import retrofit2.http.GET; import retrofit2.http.Header; @@ -37,6 +34,8 @@ 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 @@ -66,43 +65,43 @@ public StorageAccountsImpl(Retrofit retrofit, StorageManagementClientImpl client interface StorageAccountsService { @Headers("Content-Type: application/json; charset=utf-8") @POST("subscriptions/{subscriptionId}/providers/Microsoft.Storage/checkNameAvailability") - Call checkNameAvailability(@Path("subscriptionId") String subscriptionId, @Body StorageAccountCheckNameAvailabilityParameters accountName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> checkNameAvailability(@Path("subscriptionId") String subscriptionId, @Body StorageAccountCheckNameAvailabilityParameters accountName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @PUT("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}") - Call create(@Path("resourceGroupName") String resourceGroupName, @Path("accountName") String accountName, @Path("subscriptionId") String subscriptionId, @Body StorageAccountCreateParameters parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> create(@Path("resourceGroupName") String resourceGroupName, @Path("accountName") String accountName, @Path("subscriptionId") String subscriptionId, @Body StorageAccountCreateParameters parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @PUT("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}") - Call beginCreate(@Path("resourceGroupName") String resourceGroupName, @Path("accountName") String accountName, @Path("subscriptionId") String subscriptionId, @Body StorageAccountCreateParameters parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> beginCreate(@Path("resourceGroupName") String resourceGroupName, @Path("accountName") String accountName, @Path("subscriptionId") String subscriptionId, @Body StorageAccountCreateParameters parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @HTTP(path = "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}", method = "DELETE", hasBody = true) - Call 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); + 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") @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}") - Call getProperties(@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); + Observable> getProperties(@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") @PATCH("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}") - Call update(@Path("resourceGroupName") String resourceGroupName, @Path("accountName") String accountName, @Path("subscriptionId") String subscriptionId, @Body StorageAccountUpdateParameters parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> update(@Path("resourceGroupName") String resourceGroupName, @Path("accountName") String accountName, @Path("subscriptionId") String subscriptionId, @Body StorageAccountUpdateParameters parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/listKeys") - Call 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); + 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") @GET("subscriptions/{subscriptionId}/providers/Microsoft.Storage/storageAccounts") - Call list(@Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> list(@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") @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts") - Call listByResourceGroup(@Path("resourceGroupName") String resourceGroupName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> listByResourceGroup(@Path("resourceGroupName") String resourceGroupName, @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") @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/regenerateKey") - Call regenerateKey(@Path("resourceGroupName") String resourceGroupName, @Path("accountName") String accountName, @Path("subscriptionId") String subscriptionId, @Body StorageAccountRegenerateKeyParameters regenerateKey, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> regenerateKey(@Path("resourceGroupName") String resourceGroupName, @Path("accountName") String accountName, @Path("subscriptionId") String subscriptionId, @Body StorageAccountRegenerateKeyParameters regenerateKey, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); } @@ -116,18 +115,7 @@ interface StorageAccountsService { * @return the CheckNameAvailabilityResult object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse checkNameAvailability(StorageAccountCheckNameAvailabilityParameters accountName) throws CloudException, IOException, IllegalArgumentException { - if (this.client.subscriptionId() == null) { - throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); - } - if (accountName == null) { - throw new IllegalArgumentException("Parameter accountName 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(accountName); - Call call = service.checkNameAvailability(this.client.subscriptionId(), accountName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return checkNameAvailabilityDelegate(call.execute()); + return checkNameAvailabilityAsync(accountName).toBlocking().single(); } /** @@ -135,9 +123,19 @@ public ServiceResponse checkNameAvailability(Storag * * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall checkNameAvailabilityAsync(StorageAccountCheckNameAvailabilityParameters accountName, final ServiceCallback serviceCallback) { + return ServiceCall.create(checkNameAvailabilityAsync(accountName), serviceCallback); + } + + /** + * Checks that account name is valid and is not in use. + * + * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + * @return the observable to the CheckNameAvailabilityResult object + */ + public Observable> checkNameAvailabilityAsync(StorageAccountCheckNameAvailabilityParameters accountName) { if (this.client.subscriptionId() == null) { throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); } @@ -148,26 +146,18 @@ public ServiceCall checkNameAvailabilityAsync(Stora throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } Validator.validate(accountName); - Call call = service.checkNameAvailability(this.client.subscriptionId(), accountName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = checkNameAvailabilityDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); + return service.checkNameAvailability(this.client.subscriptionId(), accountName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = checkNameAvailabilityDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.success(clientResponse); - } catch (CloudException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse checkNameAvailabilityDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -190,24 +180,7 @@ private ServiceResponse checkNameAvailabilityDelega * @return the StorageAccount object wrapped in ServiceResponse if successful. */ public ServiceResponse create(String resourceGroupName, String accountName, StorageAccountCreateParameters parameters) throws CloudException, IOException, IllegalArgumentException, InterruptedException { - 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); - Response result = service.create(resourceGroupName, accountName, this.client.subscriptionId(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()).execute(); - return client.getAzureClient().getPutOrPatchResult(result, new TypeToken() { }.getType()); + return createAsync(resourceGroupName, accountName, parameters).toBlocking().last(); } /** @@ -220,6 +193,18 @@ public ServiceResponse create(String resourceGroupName, String a * @return the {@link ServiceCall} object */ public ServiceCall createAsync(String resourceGroupName, String accountName, StorageAccountCreateParameters parameters, final ServiceCallback serviceCallback) { + return ServiceCall.create(createAsync(resourceGroupName, accountName, parameters), serviceCallback); + } + + /** + * Asynchronously creates a new storage account with the specified parameters. Existing accounts cannot be updated with this API and should instead use the Update Storage Account API. If an account is already created and subsequent PUT request is issued with exact same set of properties, then HTTP 200 would be returned. + * + * @param resourceGroupName The name of the resource group within the user's subscription. + * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + * @param parameters The parameters to provide for the created account. + * @return the observable for the request + */ + public Observable> createAsync(String resourceGroupName, String accountName, StorageAccountCreateParameters parameters) { if (resourceGroupName == null) { throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } @@ -236,22 +221,8 @@ public ServiceCall createAsync(String resourceGroupName, String throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } Validator.validate(parameters); - Call call = service.create(resourceGroupName, accountName, this.client.subscriptionId(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new Callback() { - @Override - public void onFailure(Call call, Throwable t) { - if (serviceCallback != null) { - serviceCallback.failure(t); - } - serviceCall.failure(t); - } - @Override - public void onResponse(Call call, Response response) { - client.getAzureClient().getPutOrPatchResultAsync(response, new TypeToken() { }.getType(), serviceCall, serviceCallback); - } - }); - return serviceCall; + Observable> observable = service.create(resourceGroupName, accountName, this.client.subscriptionId(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return client.getAzureClient().getPutOrPatchResultAsync(observable, new TypeToken() { }.getType()); } /** @@ -266,24 +237,7 @@ public void onResponse(Call call, Response response) * @return the StorageAccount object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse beginCreate(String resourceGroupName, String accountName, StorageAccountCreateParameters parameters) throws CloudException, IOException, IllegalArgumentException { - 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); - Call call = service.beginCreate(resourceGroupName, accountName, this.client.subscriptionId(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return beginCreateDelegate(call.execute()); + return beginCreateAsync(resourceGroupName, accountName, parameters).toBlocking().single(); } /** @@ -293,9 +247,21 @@ public ServiceResponse beginCreate(String resourceGroupName, Str * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. * @param parameters The parameters to provide for the created account. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall beginCreateAsync(String resourceGroupName, String accountName, StorageAccountCreateParameters parameters, final ServiceCallback serviceCallback) { + return ServiceCall.create(beginCreateAsync(resourceGroupName, accountName, parameters), serviceCallback); + } + + /** + * Asynchronously creates a new storage account with the specified parameters. Existing accounts cannot be updated with this API and should instead use the Update Storage Account API. If an account is already created and subsequent PUT request is issued with exact same set of properties, then HTTP 200 would be returned. + * + * @param resourceGroupName The name of the resource group within the user's subscription. + * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + * @param parameters The parameters to provide for the created account. + * @return the observable to the StorageAccount object + */ + public Observable> beginCreateAsync(String resourceGroupName, String accountName, StorageAccountCreateParameters parameters) { if (resourceGroupName == null) { throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } @@ -312,26 +278,18 @@ public ServiceCall beginCreateAsync(String resourceGroupName, St throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } Validator.validate(parameters); - Call call = service.beginCreate(resourceGroupName, accountName, this.client.subscriptionId(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = beginCreateDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (CloudException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.beginCreate(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 = beginCreateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse beginCreateDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -353,20 +311,7 @@ private ServiceResponse beginCreateDelegate(Response delete(String resourceGroupName, String accountName) throws CloudException, IOException, IllegalArgumentException { - 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."); - } - Call call = service.delete(resourceGroupName, accountName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return deleteDelegate(call.execute()); + return deleteAsync(resourceGroupName, accountName).toBlocking().single(); } /** @@ -375,9 +320,20 @@ public ServiceResponse delete(String resourceGroupName, String accountName * @param resourceGroupName The name of the resource group within the user's subscription. * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall deleteAsync(String resourceGroupName, String accountName, final ServiceCallback serviceCallback) { + return ServiceCall.create(deleteAsync(resourceGroupName, accountName), serviceCallback); + } + + /** + * Deletes a storage account in Microsoft Azure. + * + * @param resourceGroupName The name of the resource group within the user's subscription. + * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> deleteAsync(String resourceGroupName, String accountName) { if (resourceGroupName == null) { throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } @@ -390,26 +346,18 @@ public ServiceCall deleteAsync(String resourceGroupName, String accountNam if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.delete(resourceGroupName, accountName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = deleteDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (CloudException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + 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); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse deleteDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -430,20 +378,7 @@ private ServiceResponse deleteDelegate(Response response) th * @return the StorageAccount object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse getProperties(String resourceGroupName, String accountName) throws CloudException, IOException, IllegalArgumentException { - 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."); - } - Call call = service.getProperties(resourceGroupName, accountName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return getPropertiesDelegate(call.execute()); + return getPropertiesAsync(resourceGroupName, accountName).toBlocking().single(); } /** @@ -452,9 +387,20 @@ public ServiceResponse getProperties(String resourceGroupName, S * @param resourceGroupName The name of the resource group within the user's subscription. * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall getPropertiesAsync(String resourceGroupName, String accountName, final ServiceCallback serviceCallback) { + return ServiceCall.create(getPropertiesAsync(resourceGroupName, accountName), serviceCallback); + } + + /** + * Returns the properties for the specified storage account including but not limited to name, account type, location, and account status. The ListKeys operation should be used to retrieve storage keys. + * + * @param resourceGroupName The name of the resource group within the user's subscription. + * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + * @return the observable to the StorageAccount object + */ + public Observable> getPropertiesAsync(String resourceGroupName, String accountName) { if (resourceGroupName == null) { throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } @@ -467,26 +413,18 @@ public ServiceCall getPropertiesAsync(String resourceGroupName, if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.getProperties(resourceGroupName, accountName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = getPropertiesDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); + return service.getProperties(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 = getPropertiesDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.success(clientResponse); - } catch (CloudException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse getPropertiesDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -508,24 +446,7 @@ private ServiceResponse getPropertiesDelegate(Response update(String resourceGroupName, String accountName, StorageAccountUpdateParameters parameters) throws CloudException, IOException, IllegalArgumentException { - 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); - Call call = service.update(resourceGroupName, accountName, this.client.subscriptionId(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return updateDelegate(call.execute()); + return updateAsync(resourceGroupName, accountName, parameters).toBlocking().single(); } /** @@ -535,9 +456,21 @@ public ServiceResponse update(String resourceGroupName, String a * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. * @param parameters The parameters to update on the account. Note that only one property can be changed at a time using this API. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall updateAsync(String resourceGroupName, String accountName, StorageAccountUpdateParameters parameters, final ServiceCallback serviceCallback) { + return ServiceCall.create(updateAsync(resourceGroupName, accountName, parameters), serviceCallback); + } + + /** + * Updates the account type or tags for a storage account. It can also be used to add a custom domain (note that custom domains cannot be added via the Create operation). Only one custom domain is supported per storage account. In order to replace a custom domain, the old value must be cleared before a new value may be set. To clear a custom domain, simply update the custom domain with empty string. Then call update again with the new cutsom domain name. The update API can only be used to update one of tags, accountType, or customDomain per call. To update multiple of these properties, call the API multiple times with one change per call. This call does not change the storage keys for the account. If you want to change storage account keys, use the RegenerateKey operation. The location and name of the storage account cannot be changed after creation. + * + * @param resourceGroupName The name of the resource group within the user's subscription. + * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + * @param parameters The parameters to update on the account. Note that only one property can be changed at a time using this API. + * @return the observable to the StorageAccount object + */ + public Observable> updateAsync(String resourceGroupName, String accountName, StorageAccountUpdateParameters parameters) { if (resourceGroupName == null) { throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } @@ -554,26 +487,18 @@ public ServiceCall updateAsync(String resourceGroupName, String throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } Validator.validate(parameters); - Call call = service.update(resourceGroupName, accountName, this.client.subscriptionId(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = updateDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (CloudException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.update(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 = updateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse updateDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -594,20 +519,7 @@ private ServiceResponse updateDelegate(Response re * @return the StorageAccountKeys object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse listKeys(String resourceGroupName, String accountName) throws CloudException, IOException, IllegalArgumentException { - 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."); - } - Call call = service.listKeys(resourceGroupName, accountName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return listKeysDelegate(call.execute()); + return listKeysAsync(resourceGroupName, accountName).toBlocking().single(); } /** @@ -616,9 +528,20 @@ public ServiceResponse listKeys(String resourceGroupName, St * @param resourceGroupName The name of the resource group. * @param accountName The name of the storage account. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall listKeysAsync(String resourceGroupName, String accountName, final ServiceCallback serviceCallback) { + return ServiceCall.create(listKeysAsync(resourceGroupName, accountName), serviceCallback); + } + + /** + * Lists the access keys for the specified storage account. + * + * @param resourceGroupName The name of the resource group. + * @param accountName The name of the storage account. + * @return the observable to the StorageAccountKeys object + */ + public Observable> listKeysAsync(String resourceGroupName, String accountName) { if (resourceGroupName == null) { throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } @@ -631,26 +554,18 @@ public ServiceCall listKeysAsync(String resourceGroupName, S if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.listKeys(resourceGroupName, accountName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = listKeysDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); + 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); } - serviceCall.success(clientResponse); - } catch (CloudException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse listKeysDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -669,48 +584,44 @@ private ServiceResponse listKeysDelegate(Response> list() throws CloudException, IOException, IllegalArgumentException { - 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."); - } - Call call = service.list(this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - List result = response.getBody().getItems(); - return new ServiceResponse<>(result, response.getResponse()); + return listAsync().toBlocking().single(); } /** * Lists all the storage accounts available under the subscription. Note that storage keys are not returned; use the ListKeys operation for this. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall> listAsync(final ServiceCallback> serviceCallback) { + return ServiceCall.create(listAsync(), serviceCallback); + } + + /** + * Lists all the storage accounts available under the subscription. Note that storage keys are not returned; use the ListKeys operation for this. + * + * @return the observable to the List<StorageAccount> object + */ + public Observable>> listAsync() { 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."); } - Call call = service.list(this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); - } catch (CloudException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.list(this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + ServiceResponse> clientResponse = new ServiceResponse>(result.getBody().getItems(), result.getResponse()); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse> listDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -730,19 +641,7 @@ private ServiceResponse> listDelegate(Response> listByResourceGroup(String resourceGroupName) throws CloudException, IOException, IllegalArgumentException { - if (resourceGroupName == null) { - throw new IllegalArgumentException("Parameter resourceGroupName 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."); - } - Call call = service.listByResourceGroup(resourceGroupName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listByResourceGroupDelegate(call.execute()); - List result = response.getBody().getItems(); - return new ServiceResponse<>(result, response.getResponse()); + return listByResourceGroupAsync(resourceGroupName).toBlocking().single(); } /** @@ -750,9 +649,19 @@ public ServiceResponse> listByResourceGroup(String resource * * @param resourceGroupName The name of the resource group within the user's subscription. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall> listByResourceGroupAsync(String resourceGroupName, final ServiceCallback> serviceCallback) { + return ServiceCall.create(listByResourceGroupAsync(resourceGroupName), serviceCallback); + } + + /** + * Lists all the storage accounts available under the given resource group. Note that storage keys are not returned; use the ListKeys operation for this. + * + * @param resourceGroupName The name of the resource group within the user's subscription. + * @return the observable to the List<StorageAccount> object + */ + public Observable>> listByResourceGroupAsync(String resourceGroupName) { if (resourceGroupName == null) { throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } @@ -762,23 +671,19 @@ public ServiceCall> listByResourceGroupAsync(String resourc if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.listByResourceGroup(resourceGroupName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listByResourceGroupDelegate(response); - serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); - } catch (CloudException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.listByResourceGroup(resourceGroupName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByResourceGroupDelegate(response); + ServiceResponse> clientResponse = new ServiceResponse>(result.getBody().getItems(), result.getResponse()); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse> listByResourceGroupDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -800,24 +705,7 @@ private ServiceResponse> listByResourceGroupDelegate(Re * @return the StorageAccountKeys object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse regenerateKey(String resourceGroupName, String accountName, StorageAccountRegenerateKeyParameters regenerateKey) throws CloudException, IOException, IllegalArgumentException { - 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 (regenerateKey == null) { - throw new IllegalArgumentException("Parameter regenerateKey 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(regenerateKey); - Call call = service.regenerateKey(resourceGroupName, accountName, this.client.subscriptionId(), regenerateKey, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return regenerateKeyDelegate(call.execute()); + return regenerateKeyAsync(resourceGroupName, accountName, regenerateKey).toBlocking().single(); } /** @@ -827,9 +715,21 @@ public ServiceResponse regenerateKey(String resourceGroupNam * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. * @param regenerateKey Specifies name of the key which should be regenerated. key1 or key2 for the default keys * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall regenerateKeyAsync(String resourceGroupName, String accountName, StorageAccountRegenerateKeyParameters regenerateKey, final ServiceCallback serviceCallback) { + return ServiceCall.create(regenerateKeyAsync(resourceGroupName, accountName, regenerateKey), serviceCallback); + } + + /** + * Regenerates the access keys for the specified storage account. + * + * @param resourceGroupName The name of the resource group within the user's subscription. + * @param accountName The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + * @param regenerateKey Specifies name of the key which should be regenerated. key1 or key2 for the default keys + * @return the observable to the StorageAccountKeys object + */ + public Observable> regenerateKeyAsync(String resourceGroupName, String accountName, StorageAccountRegenerateKeyParameters regenerateKey) { if (resourceGroupName == null) { throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } @@ -846,26 +746,18 @@ public ServiceCall regenerateKeyAsync(String resourceGroupNa throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } Validator.validate(regenerateKey); - Call call = service.regenerateKey(resourceGroupName, accountName, this.client.subscriptionId(), regenerateKey, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = regenerateKeyDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (CloudException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.regenerateKey(resourceGroupName, accountName, this.client.subscriptionId(), regenerateKey, this.client.apiVersion(), this.client.acceptLanguage(), 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); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse regenerateKeyDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { diff --git a/Samples/azure-storage/Azure.Java/implementation/UsagesImpl.java b/Samples/azure-storage/Azure.Java/implementation/UsagesImpl.java index 0da043ea54..156eeac5b3 100644 --- a/Samples/azure-storage/Azure.Java/implementation/UsagesImpl.java +++ b/Samples/azure-storage/Azure.Java/implementation/UsagesImpl.java @@ -11,19 +11,19 @@ import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; -import com.microsoft.rest.ServiceResponseCallback; import java.io.IOException; import java.util.List; import okhttp3.ResponseBody; import petstore.models.PageImpl; import petstore.models.Usage; -import retrofit2.Call; import retrofit2.http.GET; import retrofit2.http.Header; import retrofit2.http.Headers; import retrofit2.http.Path; 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 @@ -53,7 +53,7 @@ public UsagesImpl(Retrofit retrofit, StorageManagementClientImpl client) { interface UsagesService { @Headers("Content-Type: application/json; charset=utf-8") @GET("subscriptions/{subscriptionId}/providers/Microsoft.Storage/usages") - Call list(@Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> list(@Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); } @@ -66,48 +66,44 @@ interface UsagesService { * @return the List<Usage> object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse> list() throws CloudException, IOException, IllegalArgumentException { - 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."); - } - Call call = service.list(this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - List result = response.getBody().getItems(); - return new ServiceResponse<>(result, response.getResponse()); + return listAsync().toBlocking().single(); } /** * Gets the current usage count and the limit for the resources under the subscription. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall> listAsync(final ServiceCallback> serviceCallback) { + return ServiceCall.create(listAsync(), serviceCallback); + } + + /** + * Gets the current usage count and the limit for the resources under the subscription. + * + * @return the observable to the List<Usage> object + */ + public Observable>> listAsync() { 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."); } - Call call = service.list(this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); - } catch (CloudException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.list(this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + ServiceResponse> clientResponse = new ServiceResponse>(result.getBody().getItems(), result.getResponse()); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse> listDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { diff --git a/Samples/azure-storage/Azure.Python/storagemanagementclient/models/check_name_availability_result.py b/Samples/azure-storage/Azure.Python/storagemanagementclient/models/check_name_availability_result.py index 560fcbd890..a168d16684 100644 --- a/Samples/azure-storage/Azure.Python/storagemanagementclient/models/check_name_availability_result.py +++ b/Samples/azure-storage/Azure.Python/storagemanagementclient/models/check_name_availability_result.py @@ -15,7 +15,7 @@ class CheckNameAvailabilityResult(Model): :param reason: Gets the reason that a storage account name could not be used. The Reason element is only returned if NameAvailable is false. Possible values include: 'AccountNameInvalid', 'AlreadyExists' - :type reason: str or :class:`Reason ` + :type reason: str or :class:`Reason ` :param message: Gets an error message explaining the Reason value in more detail. :type message: str diff --git a/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account.py b/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account.py index 8cce44fb9b..d459311b2d 100644 --- a/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account.py +++ b/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account.py @@ -23,7 +23,7 @@ class StorageAccount(Resource): :type tags: dict :param properties: :type properties: :class:`StorageAccountProperties - ` + ` """ _validation = { diff --git a/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account_create_parameters.py b/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account_create_parameters.py index bf2224d39a..af7ab96915 100644 --- a/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account_create_parameters.py +++ b/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account_create_parameters.py @@ -14,7 +14,7 @@ class StorageAccountCreateParameters(Model): :type tags: dict :param properties: :type properties: :class:`StorageAccountPropertiesCreateParameters - ` + ` """ _validation = { diff --git a/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account_properties.py b/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account_properties.py index d74c6bdc16..2d1e4311ee 100644 --- a/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account_properties.py +++ b/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account_properties.py @@ -12,16 +12,16 @@ class StorageAccountProperties(Model): time the operation was called. Possible values include: 'Creating', 'ResolvingDNS', 'Succeeded' :type provisioning_state: str or :class:`ProvisioningState - ` + ` :param account_type: Gets the type of the storage account. Possible values include: 'Standard_LRS', 'Standard_ZRS', 'Standard_GRS', 'Standard_RAGRS', 'Premium_LRS' :type account_type: str or :class:`AccountType - ` + ` :param primary_endpoints: Gets the URLs that are used to perform a retrieval of a public blob, queue or table object.Note that StandardZRS and PremiumLRS accounts only return the blob endpoint. - :type primary_endpoints: :class:`Endpoints ` + :type primary_endpoints: :class:`Endpoints ` :param primary_location: Gets the location of the primary for the storage account. :type primary_location: str @@ -29,7 +29,7 @@ class StorageAccountProperties(Model): location of the storage account is available or unavailable. Possible values include: 'Available', 'Unavailable' :type status_of_primary: str or :class:`AccountStatus - ` + ` :param last_geo_failover_time: Gets the timestamp of the most recent instance of a failover to the secondary location. Only the most recent timestamp is retained. This element is not returned if there has never @@ -45,18 +45,18 @@ class StorageAccountProperties(Model): Only available if the accountType is StandardGRS or StandardRAGRS. Possible values include: 'Available', 'Unavailable' :type status_of_secondary: str or :class:`AccountStatus - ` + ` :param creation_time: Gets the creation date and time of the storage account in UTC. :type creation_time: datetime :param custom_domain: Gets the user assigned custom domain assigned to this storage account. - :type custom_domain: :class:`CustomDomain ` + :type custom_domain: :class:`CustomDomain ` :param secondary_endpoints: Gets the URLs that are used to perform a retrieval of a public blob, queue or table object from the secondary location of the storage account. Only available if the accountType is StandardRAGRS. - :type secondary_endpoints: :class:`Endpoints ` + :type secondary_endpoints: :class:`Endpoints ` """ _attribute_map = { diff --git a/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account_properties_create_parameters.py b/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account_properties_create_parameters.py index 63586d2d74..253b720906 100644 --- a/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account_properties_create_parameters.py +++ b/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account_properties_create_parameters.py @@ -12,7 +12,7 @@ class StorageAccountPropertiesCreateParameters(Model): include: 'Standard_LRS', 'Standard_ZRS', 'Standard_GRS', 'Standard_RAGRS', 'Premium_LRS' :type account_type: str or :class:`AccountType - ` + ` """ _validation = { diff --git a/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account_properties_update_parameters.py b/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account_properties_update_parameters.py index d313849a64..3249775cfa 100644 --- a/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account_properties_update_parameters.py +++ b/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account_properties_update_parameters.py @@ -14,12 +14,12 @@ class StorageAccountPropertiesUpdateParameters(Model): Possible values include: 'Standard_LRS', 'Standard_ZRS', 'Standard_GRS', 'Standard_RAGRS', 'Premium_LRS' :type account_type: str or :class:`AccountType - ` + ` :param custom_domain: User domain assigned to the storage account. Name is the CNAME source. Only one custom domain is supported per storage account at this time. To clear the existing custom domain, use an empty string for the custom domain name property. - :type custom_domain: :class:`CustomDomain ` + :type custom_domain: :class:`CustomDomain ` """ _attribute_map = { diff --git a/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account_update_parameters.py b/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account_update_parameters.py index c41ef7f991..fd8725cb8e 100644 --- a/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account_update_parameters.py +++ b/Samples/azure-storage/Azure.Python/storagemanagementclient/models/storage_account_update_parameters.py @@ -12,7 +12,7 @@ class StorageAccountUpdateParameters(Model): :type tags: dict :param properties: :type properties: :class:`StorageAccountPropertiesUpdateParameters - ` + ` """ _attribute_map = { diff --git a/Samples/azure-storage/Azure.Python/storagemanagementclient/models/usage.py b/Samples/azure-storage/Azure.Python/storagemanagementclient/models/usage.py index 3d65d89d02..7335e083cb 100644 --- a/Samples/azure-storage/Azure.Python/storagemanagementclient/models/usage.py +++ b/Samples/azure-storage/Azure.Python/storagemanagementclient/models/usage.py @@ -11,7 +11,7 @@ class Usage(Model): :param unit: Gets the unit of measurement. Possible values include: 'Count', 'Bytes', 'Seconds', 'Percent', 'CountsPerSecond', 'BytesPerSecond' - :type unit: str or :class:`UsageUnit ` + :type unit: str or :class:`UsageUnit ` :param current_value: Gets the current count of the allocated resources in the subscription. :type current_value: int @@ -19,7 +19,7 @@ class Usage(Model): allocated in the subscription. :type limit: int :param name: Gets the name of the type of usage. - :type name: :class:`UsageName ` + :type name: :class:`UsageName ` """ _validation = { diff --git a/Samples/azure-storage/Azure.Python/storagemanagementclient/operations/storage_accounts_operations.py b/Samples/azure-storage/Azure.Python/storagemanagementclient/operations/storage_accounts_operations.py index 88650d34f0..c796c3707e 100644 --- a/Samples/azure-storage/Azure.Python/storagemanagementclient/operations/storage_accounts_operations.py +++ b/Samples/azure-storage/Azure.Python/storagemanagementclient/operations/storage_accounts_operations.py @@ -37,14 +37,14 @@ def check_name_availability( only. :type account_name: :class:`StorageAccountCheckNameAvailabilityParameters - ` + ` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides`. :rtype: :class:`CheckNameAvailabilityResult - ` + ` :rtype: :class:`ClientRawResponse` if raw=true """ @@ -111,14 +111,14 @@ def create( :type account_name: str :param parameters: The parameters to provide for the created account. :type parameters: :class:`StorageAccountCreateParameters - ` + ` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :rtype: :class:`AzureOperationPoller` instance that returns :class:`StorageAccount - ` + ` :rtype: :class:`ClientRawResponse` if raw=true """ @@ -268,7 +268,7 @@ def get_properties( deserialized response :param operation_config: :ref:`Operation configuration overrides`. - :rtype: :class:`StorageAccount ` + :rtype: :class:`StorageAccount ` :rtype: :class:`ClientRawResponse` if raw=true """ @@ -342,13 +342,13 @@ def update( :param parameters: The parameters to update on the account. Note that only one property can be changed at a time using this API. :type parameters: :class:`StorageAccountUpdateParameters - ` + ` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides`. - :rtype: :class:`StorageAccount ` + :rtype: :class:`StorageAccount ` :rtype: :class:`ClientRawResponse` if raw=true """ @@ -413,7 +413,7 @@ def list_keys( :param operation_config: :ref:`Operation configuration overrides`. :rtype: :class:`StorageAccountKeys - ` + ` :rtype: :class:`ClientRawResponse` if raw=true """ @@ -472,7 +472,7 @@ def list( :param operation_config: :ref:`Operation configuration overrides`. :rtype: :class:`StorageAccountPaged - ` + ` """ def internal_paging(next_link=None, raw=False): @@ -539,7 +539,7 @@ def list_by_resource_group( :param operation_config: :ref:`Operation configuration overrides`. :rtype: :class:`StorageAccountPaged - ` + ` """ def internal_paging(next_link=None, raw=False): @@ -607,14 +607,14 @@ def regenerate_key( :param regenerate_key: Specifies name of the key which should be regenerated. key1 or key2 for the default keys :type regenerate_key: :class:`StorageAccountRegenerateKeyParameters - ` + ` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides`. :rtype: :class:`StorageAccountKeys - ` + ` :rtype: :class:`ClientRawResponse` if raw=true """ diff --git a/Samples/azure-storage/Azure.Python/storagemanagementclient/operations/usage_operations.py b/Samples/azure-storage/Azure.Python/storagemanagementclient/operations/usage_operations.py index cd5aa68c1a..98be396244 100644 --- a/Samples/azure-storage/Azure.Python/storagemanagementclient/operations/usage_operations.py +++ b/Samples/azure-storage/Azure.Python/storagemanagementclient/operations/usage_operations.py @@ -36,7 +36,7 @@ def list( deserialized response :param operation_config: :ref:`Operation configuration overrides`. - :rtype: :class:`UsagePaged ` + :rtype: :class:`UsagePaged ` """ def internal_paging(next_link=None, raw=False): diff --git a/Samples/petstore/Java/SwaggerPetstore.java b/Samples/petstore/Java/SwaggerPetstore.java index a12c255455..720353fd6a 100644 --- a/Samples/petstore/Java/SwaggerPetstore.java +++ b/Samples/petstore/Java/SwaggerPetstore.java @@ -13,6 +13,7 @@ import petstore.models.Order; import petstore.models.Pet; import petstore.models.User; +import rx.Observable; /** * The interface for SwaggerPetstore class. @@ -36,10 +37,9 @@ public interface SwaggerPetstore { * Fake endpoint to test byte array in body parameter for adding a new pet to the store. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall addPetUsingByteArrayAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall addPetUsingByteArrayAsync(final ServiceCallback serviceCallback); /** * Fake endpoint to test byte array in body parameter for adding a new pet to the store. * @@ -55,10 +55,17 @@ public interface SwaggerPetstore { * * @param body Pet object in the form of byte array * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall addPetUsingByteArrayAsync(String body, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall addPetUsingByteArrayAsync(String body, final ServiceCallback serviceCallback); + + /** + * Fake endpoint to test byte array in body parameter for adding a new pet to the store. + * + * @param body Pet object in the form of byte array + * @return the {@link ServiceResponse} object if successful. + */ + Observable> addPetUsingByteArrayAsync(String body); /** * Add a new pet to the store. @@ -75,10 +82,9 @@ public interface SwaggerPetstore { * Adds a new pet to the store. You may receive an HTTP invalid input if your pet is invalid. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall addPetAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall addPetAsync(final ServiceCallback serviceCallback); /** * Add a new pet to the store. * Adds a new pet to the store. You may receive an HTTP invalid input if your pet is invalid. @@ -96,10 +102,18 @@ public interface SwaggerPetstore { * * @param body Pet object that needs to be added to the store * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall addPetAsync(Pet body, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall addPetAsync(Pet body, final ServiceCallback serviceCallback); + + /** + * Add a new pet to the store. + * Adds a new pet to the store. You may receive an HTTP invalid input if your pet is invalid. + * + * @param body Pet object that needs to be added to the store + * @return the {@link ServiceResponse} object if successful. + */ + Observable> addPetAsync(Pet body); /** * Update an existing pet. @@ -114,10 +128,9 @@ public interface SwaggerPetstore { * Update an existing pet. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall updatePetAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall updatePetAsync(final ServiceCallback serviceCallback); /** * Update an existing pet. * @@ -133,10 +146,17 @@ public interface SwaggerPetstore { * * @param body Pet object that needs to be added to the store * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall updatePetAsync(Pet body, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall updatePetAsync(Pet body, final ServiceCallback serviceCallback); + + /** + * Update an existing pet. + * + * @param body Pet object that needs to be added to the store + * @return the {@link ServiceResponse} object if successful. + */ + Observable> updatePetAsync(Pet body); /** * Finds Pets by status. @@ -153,10 +173,9 @@ public interface SwaggerPetstore { * Multiple status values can be provided with comma seperated strings. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall> findPetsByStatusAsync(final ServiceCallback> serviceCallback) throws IllegalArgumentException; + ServiceCall> findPetsByStatusAsync(final ServiceCallback> serviceCallback); /** * Finds Pets by status. * Multiple status values can be provided with comma seperated strings. @@ -174,10 +193,18 @@ public interface SwaggerPetstore { * * @param status Status values that need to be considered for filter * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall> findPetsByStatusAsync(List status, final ServiceCallback> serviceCallback) throws IllegalArgumentException; + ServiceCall> findPetsByStatusAsync(List status, final ServiceCallback> serviceCallback); + + /** + * Finds Pets by status. + * Multiple status values can be provided with comma seperated strings. + * + * @param status Status values that need to be considered for filter + * @return the observable to the List<Pet> object + */ + Observable>> findPetsByStatusAsync(List status); /** * Finds Pets by tags. @@ -194,10 +221,9 @@ public interface SwaggerPetstore { * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall> findPetsByTagsAsync(final ServiceCallback> serviceCallback) throws IllegalArgumentException; + ServiceCall> findPetsByTagsAsync(final ServiceCallback> serviceCallback); /** * Finds Pets by tags. * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. @@ -215,10 +241,18 @@ public interface SwaggerPetstore { * * @param tags Tags to filter by * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall> findPetsByTagsAsync(List tags, final ServiceCallback> serviceCallback) throws IllegalArgumentException; + ServiceCall> findPetsByTagsAsync(List tags, final ServiceCallback> serviceCallback); + + /** + * Finds Pets by tags. + * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + * + * @param tags Tags to filter by + * @return the observable to the List<Pet> object + */ + Observable>> findPetsByTagsAsync(List tags); /** * Fake endpoint to test byte array return by 'Find pet by ID'. @@ -237,10 +271,18 @@ public interface SwaggerPetstore { * * @param petId ID of pet that needs to be fetched * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall findPetsWithByteArrayAsync(long petId, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall findPetsWithByteArrayAsync(long petId, final ServiceCallback serviceCallback); + + /** + * Fake endpoint to test byte array return by 'Find pet by ID'. + * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions. + * + * @param petId ID of pet that needs to be fetched + * @return the observable to the String object + */ + Observable> findPetsWithByteArrayAsync(long petId); /** * Find pet by ID. @@ -259,10 +301,18 @@ public interface SwaggerPetstore { * * @param petId ID of pet that needs to be fetched * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall getPetByIdAsync(long petId, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall getPetByIdAsync(long petId, final ServiceCallback serviceCallback); + + /** + * Find pet by ID. + * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions. + * + * @param petId ID of pet that needs to be fetched + * @return the observable to the Pet object + */ + Observable> getPetByIdAsync(long petId); /** * Updates a pet in the store with form data. @@ -280,10 +330,9 @@ public interface SwaggerPetstore { * * @param petId ID of pet that needs to be updated * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall updatePetWithFormAsync(String petId, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall updatePetWithFormAsync(String petId, final ServiceCallback serviceCallback); /** * Updates a pet in the store with form data. * @@ -304,10 +353,19 @@ public interface SwaggerPetstore { * @param name Updated name of the pet * @param status Updated status of the pet * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall updatePetWithFormAsync(String petId, String name, String status, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall updatePetWithFormAsync(String petId, String name, String status, final ServiceCallback serviceCallback); + + /** + * Updates a pet in the store with form data. + * + * @param petId ID of pet that needs to be updated + * @param name Updated name of the pet + * @param status Updated status of the pet + * @return the {@link ServiceResponse} object if successful. + */ + Observable> updatePetWithFormAsync(String petId, String name, String status); /** * Deletes a pet. @@ -324,10 +382,9 @@ public interface SwaggerPetstore { * * @param petId Pet id to delete * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall deletePetAsync(long petId, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall deletePetAsync(long petId, final ServiceCallback serviceCallback); /** * Deletes a pet. * @@ -345,10 +402,18 @@ public interface SwaggerPetstore { * @param petId Pet id to delete * @param apiKey * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall deletePetAsync(long petId, String apiKey, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall deletePetAsync(long petId, String apiKey, final ServiceCallback serviceCallback); + + /** + * Deletes a pet. + * + * @param petId Pet id to delete + * @param apiKey the String value + * @return the {@link ServiceResponse} object if successful. + */ + Observable> deletePetAsync(long petId, String apiKey); /** * uploads an image. @@ -365,10 +430,9 @@ public interface SwaggerPetstore { * * @param petId ID of pet to update * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall uploadFileAsync(long petId, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall uploadFileAsync(long petId, final ServiceCallback serviceCallback); /** * uploads an image. * @@ -388,10 +452,19 @@ public interface SwaggerPetstore { * @param additionalMetadata Additional data to pass to server * @param file file to upload * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall uploadFileAsync(long petId, String additionalMetadata, byte[] file, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall uploadFileAsync(long petId, String additionalMetadata, byte[] file, final ServiceCallback serviceCallback); + + /** + * uploads an image. + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server + * @param file file to upload + * @return the {@link ServiceResponse} object if successful. + */ + Observable> uploadFileAsync(long petId, String additionalMetadata, byte[] file); /** * Returns pet inventories by status. @@ -408,10 +481,17 @@ public interface SwaggerPetstore { * Returns a map of status codes to quantities. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall> getInventoryAsync(final ServiceCallback> serviceCallback) throws IllegalArgumentException; + ServiceCall> getInventoryAsync(final ServiceCallback> serviceCallback); + + /** + * Returns pet inventories by status. + * Returns a map of status codes to quantities. + * + * @return the observable to the Map<String, Integer> object + */ + Observable>> getInventoryAsync(); /** * Place an order for a pet. @@ -426,10 +506,9 @@ public interface SwaggerPetstore { * Place an order for a pet. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall placeOrderAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall placeOrderAsync(final ServiceCallback serviceCallback); /** * Place an order for a pet. * @@ -445,10 +524,17 @@ public interface SwaggerPetstore { * * @param body order placed for purchasing the pet * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall placeOrderAsync(Order body, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall placeOrderAsync(Order body, final ServiceCallback serviceCallback); + + /** + * Place an order for a pet. + * + * @param body order placed for purchasing the pet + * @return the observable to the Order object + */ + Observable> placeOrderAsync(Order body); /** * Find purchase order by ID. @@ -468,10 +554,18 @@ public interface SwaggerPetstore { * * @param orderId ID of pet that needs to be fetched * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall getOrderByIdAsync(String orderId, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall getOrderByIdAsync(String orderId, final ServiceCallback serviceCallback); + + /** + * Find purchase order by ID. + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions. + * + * @param orderId ID of pet that needs to be fetched + * @return the observable to the Order object + */ + Observable> getOrderByIdAsync(String orderId); /** * Delete purchase order by ID. @@ -491,10 +585,18 @@ public interface SwaggerPetstore { * * @param orderId ID of the order that needs to be deleted * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall deleteOrderAsync(String orderId, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall deleteOrderAsync(String orderId, final ServiceCallback serviceCallback); + + /** + * Delete purchase order by ID. + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors. + * + * @param orderId ID of the order that needs to be deleted + * @return the {@link ServiceResponse} object if successful. + */ + Observable> deleteOrderAsync(String orderId); /** * Create user. @@ -511,10 +613,9 @@ public interface SwaggerPetstore { * This can only be done by the logged in user. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall createUserAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall createUserAsync(final ServiceCallback serviceCallback); /** * Create user. * This can only be done by the logged in user. @@ -532,10 +633,18 @@ public interface SwaggerPetstore { * * @param body Created user object * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall createUserAsync(User body, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall createUserAsync(User body, final ServiceCallback serviceCallback); + + /** + * Create user. + * This can only be done by the logged in user. + * + * @param body Created user object + * @return the {@link ServiceResponse} object if successful. + */ + Observable> createUserAsync(User body); /** * Creates list of users with given input array. @@ -550,10 +659,9 @@ public interface SwaggerPetstore { * Creates list of users with given input array. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall createUsersWithArrayInputAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall createUsersWithArrayInputAsync(final ServiceCallback serviceCallback); /** * Creates list of users with given input array. * @@ -569,10 +677,17 @@ public interface SwaggerPetstore { * * @param body List of user object * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall createUsersWithArrayInputAsync(List body, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall createUsersWithArrayInputAsync(List body, final ServiceCallback serviceCallback); + + /** + * Creates list of users with given input array. + * + * @param body List of user object + * @return the {@link ServiceResponse} object if successful. + */ + Observable> createUsersWithArrayInputAsync(List body); /** * Creates list of users with given input array. @@ -587,10 +702,9 @@ public interface SwaggerPetstore { * Creates list of users with given input array. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall createUsersWithListInputAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall createUsersWithListInputAsync(final ServiceCallback serviceCallback); /** * Creates list of users with given input array. * @@ -606,10 +720,17 @@ public interface SwaggerPetstore { * * @param body List of user object * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall createUsersWithListInputAsync(List body, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall createUsersWithListInputAsync(List body, final ServiceCallback serviceCallback); + + /** + * Creates list of users with given input array. + * + * @param body List of user object + * @return the {@link ServiceResponse} object if successful. + */ + Observable> createUsersWithListInputAsync(List body); /** * Logs user into the system. @@ -624,10 +745,9 @@ public interface SwaggerPetstore { * Logs user into the system. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall loginUserAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall loginUserAsync(final ServiceCallback serviceCallback); /** * Logs user into the system. * @@ -645,10 +765,18 @@ public interface SwaggerPetstore { * @param username The user name for login * @param password The password for login in clear text * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall loginUserAsync(String username, String password, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall loginUserAsync(String username, String password, final ServiceCallback serviceCallback); + + /** + * Logs user into the system. + * + * @param username The user name for login + * @param password The password for login in clear text + * @return the observable to the String object + */ + Observable> loginUserAsync(String username, String password); /** * Logs out current logged in user session. @@ -663,10 +791,16 @@ public interface SwaggerPetstore { * Logs out current logged in user session. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall logoutUserAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall logoutUserAsync(final ServiceCallback serviceCallback); + + /** + * Logs out current logged in user session. + * + * @return the {@link ServiceResponse} object if successful. + */ + Observable> logoutUserAsync(); /** * Get user by user name. @@ -684,10 +818,17 @@ public interface SwaggerPetstore { * * @param username The name that needs to be fetched. Use user1 for testing. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall getUserByNameAsync(String username, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall getUserByNameAsync(String username, final ServiceCallback serviceCallback); + + /** + * Get user by user name. + * + * @param username The name that needs to be fetched. Use user1 for testing. + * @return the observable to the User object + */ + Observable> getUserByNameAsync(String username); /** * Updated user. @@ -707,10 +848,9 @@ public interface SwaggerPetstore { * * @param username name that need to be deleted * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall updateUserAsync(String username, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall updateUserAsync(String username, final ServiceCallback serviceCallback); /** * Updated user. * This can only be done by the logged in user. @@ -731,10 +871,19 @@ public interface SwaggerPetstore { * @param username name that need to be deleted * @param body Updated user object * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall updateUserAsync(String username, User body, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall updateUserAsync(String username, User body, final ServiceCallback serviceCallback); + + /** + * Updated user. + * This can only be done by the logged in user. + * + * @param username name that need to be deleted + * @param body Updated user object + * @return the {@link ServiceResponse} object if successful. + */ + Observable> updateUserAsync(String username, User body); /** * Delete user. @@ -754,9 +903,17 @@ public interface SwaggerPetstore { * * @param username The name that needs to be deleted * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null * @return the {@link ServiceCall} object */ - ServiceCall deleteUserAsync(String username, final ServiceCallback serviceCallback) throws IllegalArgumentException; + ServiceCall deleteUserAsync(String username, final ServiceCallback serviceCallback); + + /** + * Delete user. + * This can only be done by the logged in user. + * + * @param username The name that needs to be deleted + * @return the {@link ServiceResponse} object if successful. + */ + Observable> deleteUserAsync(String username); } diff --git a/Samples/petstore/Java/implementation/SwaggerPetstoreImpl.java b/Samples/petstore/Java/implementation/SwaggerPetstoreImpl.java index 201af04838..9c39f05bbd 100644 --- a/Samples/petstore/Java/implementation/SwaggerPetstoreImpl.java +++ b/Samples/petstore/Java/implementation/SwaggerPetstoreImpl.java @@ -14,7 +14,6 @@ import com.microsoft.rest.ServiceException; import com.microsoft.rest.ServiceResponse; import com.microsoft.rest.ServiceResponseBuilder; -import com.microsoft.rest.ServiceResponseCallback; import com.microsoft.rest.Validator; import java.io.InputStream; import java.io.IOException; @@ -24,7 +23,6 @@ import petstore.models.Order; import petstore.models.Pet; import petstore.models.User; -import retrofit2.Call; import retrofit2.http.Body; import retrofit2.http.GET; import retrofit2.http.Header; @@ -37,6 +35,8 @@ import retrofit2.http.PUT; import retrofit2.http.Query; import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; /** * Initializes a new instance of the SwaggerPetstore class. @@ -102,91 +102,91 @@ private void initializeService() { interface SwaggerPetstoreService { @Headers("Content-Type: application/json; charset=utf-8") @POST("pet") - Call addPetUsingByteArray(@Body String body); + Observable> addPetUsingByteArray(@Body String body); @Headers("Content-Type: application/json; charset=utf-8") @POST("pet") - Call addPet(@Body Pet body); + Observable> addPet(@Body Pet body); @Headers("Content-Type: application/json; charset=utf-8") @PUT("pet") - Call updatePet(@Body Pet body); + Observable> updatePet(@Body Pet body); @Headers("Content-Type: application/json; charset=utf-8") @GET("pet/findByStatus") - Call findPetsByStatus(@Query("status") String status); + Observable> findPetsByStatus(@Query("status") String status); @Headers("Content-Type: application/json; charset=utf-8") @GET("pet/findByTags") - Call findPetsByTags(@Query("tags") String tags); + Observable> findPetsByTags(@Query("tags") String tags); @Headers("Content-Type: application/json; charset=utf-8") @GET("pet/{petId}") - Call findPetsWithByteArray(@Path("petId") long petId); + Observable> findPetsWithByteArray(@Path("petId") long petId); @Headers("Content-Type: application/json; charset=utf-8") @GET("pet/{petId}") - Call getPetById(@Path("petId") long petId); + Observable> getPetById(@Path("petId") long petId); @Multipart @POST("pet/{petId}") - Call updatePetWithForm(@Path("petId") String petId, @Part("name") String name, @Part("status") String status); + Observable> updatePetWithForm(@Path("petId") String petId, @Part("name") String name, @Part("status") String status); @Headers("Content-Type: application/json; charset=utf-8") @HTTP(path = "pet/{petId}", method = "DELETE", hasBody = true) - Call deletePet(@Path("petId") long petId, @Header("api_key") String apiKey); + Observable> deletePet(@Path("petId") long petId, @Header("api_key") String apiKey); @Multipart @POST("pet/{petId}/uploadImage") - Call uploadFile(@Path("petId") long petId, @Part("additionalMetadata") String additionalMetadata, @Part("file") RequestBody file); + Observable> uploadFile(@Path("petId") long petId, @Part("additionalMetadata") String additionalMetadata, @Part("file") RequestBody file); @Headers("Content-Type: application/json; charset=utf-8") @GET("store/inventory") - Call getInventory(); + Observable> getInventory(); @Headers("Content-Type: application/json; charset=utf-8") @POST("store/order") - Call placeOrder(@Body Order body); + Observable> placeOrder(@Body Order body); @Headers("Content-Type: application/json; charset=utf-8") @GET("store/order/{orderId}") - Call getOrderById(@Path("orderId") String orderId); + Observable> getOrderById(@Path("orderId") String orderId); @Headers("Content-Type: application/json; charset=utf-8") @HTTP(path = "store/order/{orderId}", method = "DELETE", hasBody = true) - Call deleteOrder(@Path("orderId") String orderId); + Observable> deleteOrder(@Path("orderId") String orderId); @Headers("Content-Type: application/json; charset=utf-8") @POST("user") - Call createUser(@Body User body); + Observable> createUser(@Body User body); @Headers("Content-Type: application/json; charset=utf-8") @POST("user/createWithArray") - Call createUsersWithArrayInput(@Body List body); + Observable> createUsersWithArrayInput(@Body List body); @Headers("Content-Type: application/json; charset=utf-8") @POST("user/createWithList") - Call createUsersWithListInput(@Body List body); + Observable> createUsersWithListInput(@Body List body); @Headers("Content-Type: application/json; charset=utf-8") @GET("user/login") - Call loginUser(@Query("username") String username, @Query("password") String password); + Observable> loginUser(@Query("username") String username, @Query("password") String password); @Headers("Content-Type: application/json; charset=utf-8") @GET("user/logout") - Call logoutUser(); + Observable> logoutUser(); @Headers("Content-Type: application/json; charset=utf-8") @GET("user/{username}") - Call getUserByName(@Path("username") String username); + Observable> getUserByName(@Path("username") String username); @Headers("Content-Type: application/json; charset=utf-8") @PUT("user/{username}") - Call updateUser(@Path("username") String username, @Body User body); + Observable> updateUser(@Path("username") String username, @Body User body); @Headers("Content-Type: application/json; charset=utf-8") @HTTP(path = "user/{username}", method = "DELETE", hasBody = true) - Call deleteUser(@Path("username") String username); + Observable> deleteUser(@Path("username") String username); } @@ -198,39 +198,38 @@ interface SwaggerPetstoreService { * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse addPetUsingByteArray() throws ServiceException, IOException { - final String body = null; - Call call = service.addPetUsingByteArray(body); - return addPetUsingByteArrayDelegate(call.execute()); + return addPetUsingByteArrayAsync().toBlocking().single(); } /** * Fake endpoint to test byte array in body parameter for adding a new pet to the store. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall addPetUsingByteArrayAsync(final ServiceCallback serviceCallback) { + return ServiceCall.create(addPetUsingByteArrayAsync(), serviceCallback); + } + + /** + * Fake endpoint to test byte array in body parameter for adding a new pet to the store. + * + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> addPetUsingByteArrayAsync() { final String body = null; - Call call = service.addPetUsingByteArray(body); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = addPetUsingByteArrayDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.addPetUsingByteArray(body) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = addPetUsingByteArrayDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } /** @@ -242,8 +241,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse addPetUsingByteArray(String body) throws ServiceException, IOException { - Call call = service.addPetUsingByteArray(body); - return addPetUsingByteArrayDelegate(call.execute()); + return addPetUsingByteArrayAsync(body).toBlocking().single(); } /** @@ -251,29 +249,31 @@ public ServiceResponse addPetUsingByteArray(String body) throws ServiceExc * * @param body Pet object in the form of byte array * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall addPetUsingByteArrayAsync(String body, final ServiceCallback serviceCallback) { - Call call = service.addPetUsingByteArray(body); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = addPetUsingByteArrayDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return ServiceCall.create(addPetUsingByteArrayAsync(body), serviceCallback); + } + + /** + * Fake endpoint to test byte array in body parameter for adding a new pet to the store. + * + * @param body Pet object in the form of byte array + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> addPetUsingByteArrayAsync(String body) { + return service.addPetUsingByteArray(body) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = addPetUsingByteArrayDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse addPetUsingByteArrayDelegate(Response response) throws ServiceException, IOException { @@ -291,9 +291,7 @@ private ServiceResponse addPetUsingByteArrayDelegate(Response addPet() throws ServiceException, IOException { - final Pet body = null; - Call call = service.addPet(body); - return addPetDelegate(call.execute()); + return addPetAsync().toBlocking().single(); } /** @@ -301,30 +299,32 @@ public ServiceResponse addPet() throws ServiceException, IOException { * Adds a new pet to the store. You may receive an HTTP invalid input if your pet is invalid. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall addPetAsync(final ServiceCallback serviceCallback) { + return ServiceCall.create(addPetAsync(), serviceCallback); + } + + /** + * Add a new pet to the store. + * Adds a new pet to the store. You may receive an HTTP invalid input if your pet is invalid. + * + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> addPetAsync() { final Pet body = null; - Call call = service.addPet(body); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = addPetDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); + return service.addPet(body) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = addPetDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } /** @@ -337,9 +337,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse addPet(Pet body) throws ServiceException, IOException { - Validator.validate(body); - Call call = service.addPet(body); - return addPetDelegate(call.execute()); + return addPetAsync(body).toBlocking().single(); } /** @@ -348,30 +346,33 @@ public ServiceResponse addPet(Pet body) throws ServiceException, IOExcepti * * @param body Pet object that needs to be added to the store * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall addPetAsync(Pet body, final ServiceCallback serviceCallback) { + return ServiceCall.create(addPetAsync(body), serviceCallback); + } + + /** + * Add a new pet to the store. + * Adds a new pet to the store. You may receive an HTTP invalid input if your pet is invalid. + * + * @param body Pet object that needs to be added to the store + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> addPetAsync(Pet body) { Validator.validate(body); - Call call = service.addPet(body); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = addPetDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.addPet(body) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = addPetDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse addPetDelegate(Response response) throws ServiceException, IOException { @@ -388,39 +389,38 @@ private ServiceResponse addPetDelegate(Response response) th * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse updatePet() throws ServiceException, IOException { - final Pet body = null; - Call call = service.updatePet(body); - return updatePetDelegate(call.execute()); + return updatePetAsync().toBlocking().single(); } /** * Update an existing pet. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall updatePetAsync(final ServiceCallback serviceCallback) { + return ServiceCall.create(updatePetAsync(), serviceCallback); + } + + /** + * Update an existing pet. + * + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updatePetAsync() { final Pet body = null; - Call call = service.updatePet(body); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = updatePetDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.updatePet(body) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updatePetDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } /** @@ -432,9 +432,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse updatePet(Pet body) throws ServiceException, IOException { - Validator.validate(body); - Call call = service.updatePet(body); - return updatePetDelegate(call.execute()); + return updatePetAsync(body).toBlocking().single(); } /** @@ -442,30 +440,32 @@ public ServiceResponse updatePet(Pet body) throws ServiceException, IOExce * * @param body Pet object that needs to be added to the store * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall updatePetAsync(Pet body, final ServiceCallback serviceCallback) { + return ServiceCall.create(updatePetAsync(body), serviceCallback); + } + + /** + * Update an existing pet. + * + * @param body Pet object that needs to be added to the store + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updatePetAsync(Pet body) { Validator.validate(body); - Call call = service.updatePet(body); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = updatePetDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); + return service.updatePet(body) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updatePetDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse updatePetDelegate(Response response) throws ServiceException, IOException { @@ -485,10 +485,7 @@ private ServiceResponse updatePetDelegate(Response response) * @return the List<Pet> object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse> findPetsByStatus() throws ServiceException, IOException { - final List status = null; - String statusConverted = this.mapperAdapter().serializeList(status, CollectionFormat.CSV); - Call call = service.findPetsByStatus(statusConverted); - return findPetsByStatusDelegate(call.execute()); + return findPetsByStatusAsync().toBlocking().single(); } /** @@ -496,31 +493,33 @@ public ServiceResponse> findPetsByStatus() throws ServiceException, IO * Multiple status values can be provided with comma seperated strings. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall> findPetsByStatusAsync(final ServiceCallback> serviceCallback) { + return ServiceCall.create(findPetsByStatusAsync(), serviceCallback); + } + + /** + * Finds Pets by status. + * Multiple status values can be provided with comma seperated strings. + * + * @return the observable to the List<Pet> object + */ + public Observable>> findPetsByStatusAsync() { final List status = null; String statusConverted = this.mapperAdapter().serializeList(status, CollectionFormat.CSV); - Call call = service.findPetsByStatus(statusConverted); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> clientResponse = findPetsByStatusDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.findPetsByStatus(statusConverted) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> clientResponse = findPetsByStatusDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } /** @@ -533,10 +532,7 @@ public void onResponse(Call call, Response response) * @return the List<Pet> object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse> findPetsByStatus(List status) throws ServiceException, IOException { - Validator.validate(status); - String statusConverted = this.mapperAdapter().serializeList(status, CollectionFormat.CSV); - Call call = service.findPetsByStatus(statusConverted); - return findPetsByStatusDelegate(call.execute()); + return findPetsByStatusAsync(status).toBlocking().single(); } /** @@ -545,31 +541,34 @@ public ServiceResponse> findPetsByStatus(List status) throws S * * @param status Status values that need to be considered for filter * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall> findPetsByStatusAsync(List status, final ServiceCallback> serviceCallback) { + return ServiceCall.create(findPetsByStatusAsync(status), serviceCallback); + } + + /** + * Finds Pets by status. + * Multiple status values can be provided with comma seperated strings. + * + * @param status Status values that need to be considered for filter + * @return the observable to the List<Pet> object + */ + public Observable>> findPetsByStatusAsync(List status) { Validator.validate(status); String statusConverted = this.mapperAdapter().serializeList(status, CollectionFormat.CSV); - Call call = service.findPetsByStatus(statusConverted); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> clientResponse = findPetsByStatusDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); + return service.findPetsByStatus(statusConverted) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> clientResponse = findPetsByStatusDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse> findPetsByStatusDelegate(Response response) throws ServiceException, IOException { @@ -588,10 +587,7 @@ private ServiceResponse> findPetsByStatusDelegate(Response> findPetsByTags() throws ServiceException, IOException { - final List tags = null; - String tagsConverted = this.mapperAdapter().serializeList(tags, CollectionFormat.CSV); - Call call = service.findPetsByTags(tagsConverted); - return findPetsByTagsDelegate(call.execute()); + return findPetsByTagsAsync().toBlocking().single(); } /** @@ -599,31 +595,33 @@ public ServiceResponse> findPetsByTags() throws ServiceException, IOEx * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall> findPetsByTagsAsync(final ServiceCallback> serviceCallback) { + return ServiceCall.create(findPetsByTagsAsync(), serviceCallback); + } + + /** + * Finds Pets by tags. + * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + * + * @return the observable to the List<Pet> object + */ + public Observable>> findPetsByTagsAsync() { final List tags = null; String tagsConverted = this.mapperAdapter().serializeList(tags, CollectionFormat.CSV); - Call call = service.findPetsByTags(tagsConverted); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> clientResponse = findPetsByTagsDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.findPetsByTags(tagsConverted) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> clientResponse = findPetsByTagsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } /** @@ -636,10 +634,7 @@ public void onResponse(Call call, Response response) * @return the List<Pet> object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse> findPetsByTags(List tags) throws ServiceException, IOException { - Validator.validate(tags); - String tagsConverted = this.mapperAdapter().serializeList(tags, CollectionFormat.CSV); - Call call = service.findPetsByTags(tagsConverted); - return findPetsByTagsDelegate(call.execute()); + return findPetsByTagsAsync(tags).toBlocking().single(); } /** @@ -648,31 +643,34 @@ public ServiceResponse> findPetsByTags(List tags) throws Servi * * @param tags Tags to filter by * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall> findPetsByTagsAsync(List tags, final ServiceCallback> serviceCallback) { + return ServiceCall.create(findPetsByTagsAsync(tags), serviceCallback); + } + + /** + * Finds Pets by tags. + * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + * + * @param tags Tags to filter by + * @return the observable to the List<Pet> object + */ + public Observable>> findPetsByTagsAsync(List tags) { Validator.validate(tags); String tagsConverted = this.mapperAdapter().serializeList(tags, CollectionFormat.CSV); - Call call = service.findPetsByTags(tagsConverted); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> clientResponse = findPetsByTagsDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); + return service.findPetsByTags(tagsConverted) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> clientResponse = findPetsByTagsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse> findPetsByTagsDelegate(Response response) throws ServiceException, IOException { @@ -692,8 +690,7 @@ private ServiceResponse> findPetsByTagsDelegate(Response * @return the String object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse findPetsWithByteArray(long petId) throws ServiceException, IOException { - Call call = service.findPetsWithByteArray(petId); - return findPetsWithByteArrayDelegate(call.execute()); + return findPetsWithByteArrayAsync(petId).toBlocking().single(); } /** @@ -702,29 +699,32 @@ public ServiceResponse findPetsWithByteArray(long petId) throws ServiceE * * @param petId ID of pet that needs to be fetched * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall findPetsWithByteArrayAsync(long petId, final ServiceCallback serviceCallback) { - Call call = service.findPetsWithByteArray(petId); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = findPetsWithByteArrayDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return ServiceCall.create(findPetsWithByteArrayAsync(petId), serviceCallback); + } + + /** + * Fake endpoint to test byte array return by 'Find pet by ID'. + * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions. + * + * @param petId ID of pet that needs to be fetched + * @return the observable to the String object + */ + public Observable> findPetsWithByteArrayAsync(long petId) { + return service.findPetsWithByteArray(petId) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = findPetsWithByteArrayDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse findPetsWithByteArrayDelegate(Response response) throws ServiceException, IOException { @@ -745,8 +745,7 @@ private ServiceResponse findPetsWithByteArrayDelegate(Response getPetById(long petId) throws ServiceException, IOException { - Call call = service.getPetById(petId); - return getPetByIdDelegate(call.execute()); + return getPetByIdAsync(petId).toBlocking().single(); } /** @@ -755,29 +754,32 @@ public ServiceResponse getPetById(long petId) throws ServiceException, IOEx * * @param petId ID of pet that needs to be fetched * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall getPetByIdAsync(long petId, final ServiceCallback serviceCallback) { - Call call = service.getPetById(petId); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = getPetByIdDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return ServiceCall.create(getPetByIdAsync(petId), serviceCallback); + } + + /** + * Find pet by ID. + * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions. + * + * @param petId ID of pet that needs to be fetched + * @return the observable to the Pet object + */ + public Observable> getPetByIdAsync(long petId) { + return service.getPetById(petId) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getPetByIdDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse getPetByIdDelegate(Response response) throws ServiceException, IOException { @@ -798,13 +800,7 @@ private ServiceResponse getPetByIdDelegate(Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse updatePetWithForm(String petId) throws ServiceException, IOException, IllegalArgumentException { - if (petId == null) { - throw new IllegalArgumentException("Parameter petId is required and cannot be null."); - } - final String name = null; - final String status = null; - Call call = service.updatePetWithForm(petId, name, status); - return updatePetWithFormDelegate(call.execute()); + return updatePetWithFormAsync(petId).toBlocking().single(); } /** @@ -812,34 +808,36 @@ public ServiceResponse updatePetWithForm(String petId) throws ServiceExcep * * @param petId ID of pet that needs to be updated * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall updatePetWithFormAsync(String petId, final ServiceCallback serviceCallback) { + return ServiceCall.create(updatePetWithFormAsync(petId), serviceCallback); + } + + /** + * Updates a pet in the store with form data. + * + * @param petId ID of pet that needs to be updated + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updatePetWithFormAsync(String petId) { if (petId == null) { throw new IllegalArgumentException("Parameter petId is required and cannot be null."); } final String name = null; final String status = null; - Call call = service.updatePetWithForm(petId, name, status); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = updatePetWithFormDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); + return service.updatePetWithForm(petId, name, status) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updatePetWithFormDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } /** @@ -854,11 +852,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse updatePetWithForm(String petId, String name, String status) throws ServiceException, IOException, IllegalArgumentException { - if (petId == null) { - throw new IllegalArgumentException("Parameter petId is required and cannot be null."); - } - Call call = service.updatePetWithForm(petId, name, status); - return updatePetWithFormDelegate(call.execute()); + return updatePetWithFormAsync(petId, name, status).toBlocking().single(); } /** @@ -868,32 +862,36 @@ public ServiceResponse updatePetWithForm(String petId, String name, String * @param name Updated name of the pet * @param status Updated status of the pet * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall updatePetWithFormAsync(String petId, String name, String status, final ServiceCallback serviceCallback) { + return ServiceCall.create(updatePetWithFormAsync(petId, name, status), serviceCallback); + } + + /** + * Updates a pet in the store with form data. + * + * @param petId ID of pet that needs to be updated + * @param name Updated name of the pet + * @param status Updated status of the pet + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updatePetWithFormAsync(String petId, String name, String status) { if (petId == null) { throw new IllegalArgumentException("Parameter petId is required and cannot be null."); } - Call call = service.updatePetWithForm(petId, name, status); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = updatePetWithFormDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.updatePetWithForm(petId, name, status) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updatePetWithFormDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse updatePetWithFormDelegate(Response response) throws ServiceException, IOException, IllegalArgumentException { @@ -911,9 +909,7 @@ private ServiceResponse updatePetWithFormDelegate(Response r * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse deletePet(long petId) throws ServiceException, IOException { - final String apiKey = null; - Call call = service.deletePet(petId, apiKey); - return deletePetDelegate(call.execute()); + return deletePetAsync(petId).toBlocking().single(); } /** @@ -921,30 +917,32 @@ public ServiceResponse deletePet(long petId) throws ServiceException, IOEx * * @param petId Pet id to delete * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall deletePetAsync(long petId, final ServiceCallback serviceCallback) { + return ServiceCall.create(deletePetAsync(petId), serviceCallback); + } + + /** + * Deletes a pet. + * + * @param petId Pet id to delete + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> deletePetAsync(long petId) { final String apiKey = null; - Call call = service.deletePet(petId, apiKey); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = deletePetDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); + return service.deletePet(petId, apiKey) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = deletePetDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } /** @@ -957,8 +955,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse deletePet(long petId, String apiKey) throws ServiceException, IOException { - Call call = service.deletePet(petId, apiKey); - return deletePetDelegate(call.execute()); + return deletePetAsync(petId, apiKey).toBlocking().single(); } /** @@ -967,29 +964,32 @@ public ServiceResponse deletePet(long petId, String apiKey) throws Service * @param petId Pet id to delete * @param apiKey the String value * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall deletePetAsync(long petId, String apiKey, final ServiceCallback serviceCallback) { - Call call = service.deletePet(petId, apiKey); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = deletePetDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return ServiceCall.create(deletePetAsync(petId, apiKey), serviceCallback); + } + + /** + * Deletes a pet. + * + * @param petId Pet id to delete + * @param apiKey the String value + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> deletePetAsync(long petId, String apiKey) { + return service.deletePet(petId, apiKey) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = deletePetDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse deletePetDelegate(Response response) throws ServiceException, IOException { @@ -1007,14 +1007,7 @@ private ServiceResponse deletePetDelegate(Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse uploadFile(long petId) throws ServiceException, IOException { - final String additionalMetadata = null; - final byte[] file = new byte[0]; - RequestBody fileConverted = RequestBody.create(MediaType.parse("multipart/form-data"), new byte[0]); - if (file != null) { - fileConverted = RequestBody.create(MediaType.parse("multipart/form-data"), file); - } - Call call = service.uploadFile(petId, additionalMetadata, fileConverted); - return uploadFileDelegate(call.execute()); + return uploadFileAsync(petId).toBlocking().single(); } /** @@ -1022,35 +1015,37 @@ public ServiceResponse uploadFile(long petId) throws ServiceException, IOE * * @param petId ID of pet to update * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall uploadFileAsync(long petId, final ServiceCallback serviceCallback) { + return ServiceCall.create(uploadFileAsync(petId), serviceCallback); + } + + /** + * uploads an image. + * + * @param petId ID of pet to update + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> uploadFileAsync(long petId) { final String additionalMetadata = null; final byte[] file = new byte[0]; RequestBody fileConverted = RequestBody.create(MediaType.parse("multipart/form-data"), new byte[0]); if (file != null) { fileConverted = RequestBody.create(MediaType.parse("multipart/form-data"), file); } - Call call = service.uploadFile(petId, additionalMetadata, fileConverted); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = uploadFileDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.uploadFile(petId, additionalMetadata, fileConverted) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = uploadFileDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } /** @@ -1064,12 +1059,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse uploadFile(long petId, String additionalMetadata, byte[] file) throws ServiceException, IOException { - RequestBody fileConverted = RequestBody.create(MediaType.parse("multipart/form-data"), new byte[0]); - if (file != null) { - fileConverted = RequestBody.create(MediaType.parse("multipart/form-data"), file); - } - Call call = service.uploadFile(petId, additionalMetadata, fileConverted); - return uploadFileDelegate(call.execute()); + return uploadFileAsync(petId, additionalMetadata, file).toBlocking().single(); } /** @@ -1079,33 +1069,37 @@ public ServiceResponse uploadFile(long petId, String additionalMetadata, b * @param additionalMetadata Additional data to pass to server * @param file file to upload * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall uploadFileAsync(long petId, String additionalMetadata, byte[] file, final ServiceCallback serviceCallback) { + return ServiceCall.create(uploadFileAsync(petId, additionalMetadata, file), serviceCallback); + } + + /** + * uploads an image. + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server + * @param file file to upload + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> uploadFileAsync(long petId, String additionalMetadata, byte[] file) { RequestBody fileConverted = RequestBody.create(MediaType.parse("multipart/form-data"), new byte[0]); if (file != null) { fileConverted = RequestBody.create(MediaType.parse("multipart/form-data"), file); } - Call call = service.uploadFile(petId, additionalMetadata, fileConverted); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = uploadFileDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.uploadFile(petId, additionalMetadata, fileConverted) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = uploadFileDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse uploadFileDelegate(Response response) throws ServiceException, IOException { @@ -1122,8 +1116,7 @@ private ServiceResponse uploadFileDelegate(Response response * @return the Map<String, Integer> object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse> getInventory() throws ServiceException, IOException { - Call call = service.getInventory(); - return getInventoryDelegate(call.execute()); + return getInventoryAsync().toBlocking().single(); } /** @@ -1131,29 +1124,31 @@ public ServiceResponse> getInventory() throws ServiceExcept * Returns a map of status codes to quantities. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall> getInventoryAsync(final ServiceCallback> serviceCallback) { - Call call = service.getInventory(); - final ServiceCall> serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback>(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> clientResponse = getInventoryDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return ServiceCall.create(getInventoryAsync(), serviceCallback); + } + + /** + * Returns pet inventories by status. + * Returns a map of status codes to quantities. + * + * @return the observable to the Map<String, Integer> object + */ + public Observable>> getInventoryAsync() { + return service.getInventory() + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> clientResponse = getInventoryDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse> getInventoryDelegate(Response response) throws ServiceException, IOException { @@ -1170,39 +1165,38 @@ private ServiceResponse> getInventoryDelegate(Response placeOrder() throws ServiceException, IOException { - final Order body = null; - Call call = service.placeOrder(body); - return placeOrderDelegate(call.execute()); + return placeOrderAsync().toBlocking().single(); } /** * Place an order for a pet. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall placeOrderAsync(final ServiceCallback serviceCallback) { + return ServiceCall.create(placeOrderAsync(), serviceCallback); + } + + /** + * Place an order for a pet. + * + * @return the observable to the Order object + */ + public Observable> placeOrderAsync() { final Order body = null; - Call call = service.placeOrder(body); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = placeOrderDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); + return service.placeOrder(body) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = placeOrderDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } /** @@ -1214,9 +1208,7 @@ public void onResponse(Call call, Response response) * @return the Order object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse placeOrder(Order body) throws ServiceException, IOException { - Validator.validate(body); - Call call = service.placeOrder(body); - return placeOrderDelegate(call.execute()); + return placeOrderAsync(body).toBlocking().single(); } /** @@ -1224,30 +1216,32 @@ public ServiceResponse placeOrder(Order body) throws ServiceException, IO * * @param body order placed for purchasing the pet * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall placeOrderAsync(Order body, final ServiceCallback serviceCallback) { + return ServiceCall.create(placeOrderAsync(body), serviceCallback); + } + + /** + * Place an order for a pet. + * + * @param body order placed for purchasing the pet + * @return the observable to the Order object + */ + public Observable> placeOrderAsync(Order body) { Validator.validate(body); - Call call = service.placeOrder(body); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = placeOrderDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); + return service.placeOrder(body) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = placeOrderDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse placeOrderDelegate(Response response) throws ServiceException, IOException { @@ -1268,11 +1262,7 @@ private ServiceResponse placeOrderDelegate(Response respons * @return the Order object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse getOrderById(String orderId) throws ServiceException, IOException, IllegalArgumentException { - if (orderId == null) { - throw new IllegalArgumentException("Parameter orderId is required and cannot be null."); - } - Call call = service.getOrderById(orderId); - return getOrderByIdDelegate(call.execute()); + return getOrderByIdAsync(orderId).toBlocking().single(); } /** @@ -1281,32 +1271,35 @@ public ServiceResponse getOrderById(String orderId) throws ServiceExcepti * * @param orderId ID of pet that needs to be fetched * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall getOrderByIdAsync(String orderId, final ServiceCallback serviceCallback) { + return ServiceCall.create(getOrderByIdAsync(orderId), serviceCallback); + } + + /** + * Find purchase order by ID. + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions. + * + * @param orderId ID of pet that needs to be fetched + * @return the observable to the Order object + */ + public Observable> getOrderByIdAsync(String orderId) { if (orderId == null) { throw new IllegalArgumentException("Parameter orderId is required and cannot be null."); } - Call call = service.getOrderById(orderId); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = getOrderByIdDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); + return service.getOrderById(orderId) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getOrderByIdDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse getOrderByIdDelegate(Response response) throws ServiceException, IOException, IllegalArgumentException { @@ -1328,11 +1321,7 @@ private ServiceResponse getOrderByIdDelegate(Response respo * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse deleteOrder(String orderId) throws ServiceException, IOException, IllegalArgumentException { - if (orderId == null) { - throw new IllegalArgumentException("Parameter orderId is required and cannot be null."); - } - Call call = service.deleteOrder(orderId); - return deleteOrderDelegate(call.execute()); + return deleteOrderAsync(orderId).toBlocking().single(); } /** @@ -1341,32 +1330,35 @@ public ServiceResponse deleteOrder(String orderId) throws ServiceException * * @param orderId ID of the order that needs to be deleted * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall deleteOrderAsync(String orderId, final ServiceCallback serviceCallback) { + return ServiceCall.create(deleteOrderAsync(orderId), serviceCallback); + } + + /** + * Delete purchase order by ID. + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors. + * + * @param orderId ID of the order that needs to be deleted + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> deleteOrderAsync(String orderId) { if (orderId == null) { throw new IllegalArgumentException("Parameter orderId is required and cannot be null."); } - Call call = service.deleteOrder(orderId); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = deleteOrderDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.deleteOrder(orderId) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = deleteOrderDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse deleteOrderDelegate(Response response) throws ServiceException, IOException, IllegalArgumentException { @@ -1385,9 +1377,7 @@ private ServiceResponse deleteOrderDelegate(Response respons * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse createUser() throws ServiceException, IOException { - final User body = null; - Call call = service.createUser(body); - return createUserDelegate(call.execute()); + return createUserAsync().toBlocking().single(); } /** @@ -1395,30 +1385,32 @@ public ServiceResponse createUser() throws ServiceException, IOException { * This can only be done by the logged in user. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall createUserAsync(final ServiceCallback serviceCallback) { + return ServiceCall.create(createUserAsync(), serviceCallback); + } + + /** + * Create user. + * This can only be done by the logged in user. + * + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> createUserAsync() { final User body = null; - Call call = service.createUser(body); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = createUserDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.createUser(body) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createUserDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } /** @@ -1431,9 +1423,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse createUser(User body) throws ServiceException, IOException { - Validator.validate(body); - Call call = service.createUser(body); - return createUserDelegate(call.execute()); + return createUserAsync(body).toBlocking().single(); } /** @@ -1442,30 +1432,33 @@ public ServiceResponse createUser(User body) throws ServiceException, IOEx * * @param body Created user object * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall createUserAsync(User body, final ServiceCallback serviceCallback) { + return ServiceCall.create(createUserAsync(body), serviceCallback); + } + + /** + * Create user. + * This can only be done by the logged in user. + * + * @param body Created user object + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> createUserAsync(User body) { Validator.validate(body); - Call call = service.createUser(body); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = createUserDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.createUser(body) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createUserDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse createUserDelegate(Response response) throws ServiceException, IOException { @@ -1481,39 +1474,38 @@ private ServiceResponse createUserDelegate(Response response * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse createUsersWithArrayInput() throws ServiceException, IOException { - final List body = null; - Call call = service.createUsersWithArrayInput(body); - return createUsersWithArrayInputDelegate(call.execute()); + return createUsersWithArrayInputAsync().toBlocking().single(); } /** * Creates list of users with given input array. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall createUsersWithArrayInputAsync(final ServiceCallback serviceCallback) { + return ServiceCall.create(createUsersWithArrayInputAsync(), serviceCallback); + } + + /** + * Creates list of users with given input array. + * + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> createUsersWithArrayInputAsync() { final List body = null; - Call call = service.createUsersWithArrayInput(body); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = createUsersWithArrayInputDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.createUsersWithArrayInput(body) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createUsersWithArrayInputDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } /** @@ -1525,9 +1517,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse createUsersWithArrayInput(List body) throws ServiceException, IOException { - Validator.validate(body); - Call call = service.createUsersWithArrayInput(body); - return createUsersWithArrayInputDelegate(call.execute()); + return createUsersWithArrayInputAsync(body).toBlocking().single(); } /** @@ -1535,30 +1525,32 @@ public ServiceResponse createUsersWithArrayInput(List body) throws S * * @param body List of user object * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall createUsersWithArrayInputAsync(List body, final ServiceCallback serviceCallback) { + return ServiceCall.create(createUsersWithArrayInputAsync(body), serviceCallback); + } + + /** + * Creates list of users with given input array. + * + * @param body List of user object + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> createUsersWithArrayInputAsync(List body) { Validator.validate(body); - Call call = service.createUsersWithArrayInput(body); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = createUsersWithArrayInputDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.createUsersWithArrayInput(body) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createUsersWithArrayInputDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse createUsersWithArrayInputDelegate(Response response) throws ServiceException, IOException { @@ -1574,39 +1566,38 @@ private ServiceResponse createUsersWithArrayInputDelegate(Response createUsersWithListInput() throws ServiceException, IOException { - final List body = null; - Call call = service.createUsersWithListInput(body); - return createUsersWithListInputDelegate(call.execute()); + return createUsersWithListInputAsync().toBlocking().single(); } /** * Creates list of users with given input array. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall createUsersWithListInputAsync(final ServiceCallback serviceCallback) { + return ServiceCall.create(createUsersWithListInputAsync(), serviceCallback); + } + + /** + * Creates list of users with given input array. + * + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> createUsersWithListInputAsync() { final List body = null; - Call call = service.createUsersWithListInput(body); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = createUsersWithListInputDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); + return service.createUsersWithListInput(body) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createUsersWithListInputDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } /** @@ -1618,9 +1609,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse createUsersWithListInput(List body) throws ServiceException, IOException { - Validator.validate(body); - Call call = service.createUsersWithListInput(body); - return createUsersWithListInputDelegate(call.execute()); + return createUsersWithListInputAsync(body).toBlocking().single(); } /** @@ -1628,30 +1617,32 @@ public ServiceResponse createUsersWithListInput(List body) throws Se * * @param body List of user object * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall createUsersWithListInputAsync(List body, final ServiceCallback serviceCallback) { + return ServiceCall.create(createUsersWithListInputAsync(body), serviceCallback); + } + + /** + * Creates list of users with given input array. + * + * @param body List of user object + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> createUsersWithListInputAsync(List body) { Validator.validate(body); - Call call = service.createUsersWithListInput(body); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = createUsersWithListInputDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.createUsersWithListInput(body) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createUsersWithListInputDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse createUsersWithListInputDelegate(Response response) throws ServiceException, IOException { @@ -1667,41 +1658,39 @@ private ServiceResponse createUsersWithListInputDelegate(Response loginUser() throws ServiceException, IOException { - final String username = null; - final String password = null; - Call call = service.loginUser(username, password); - return loginUserDelegate(call.execute()); + return loginUserAsync().toBlocking().single(); } /** * Logs user into the system. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall loginUserAsync(final ServiceCallback serviceCallback) { + return ServiceCall.create(loginUserAsync(), serviceCallback); + } + + /** + * Logs user into the system. + * + * @return the observable to the String object + */ + public Observable> loginUserAsync() { final String username = null; final String password = null; - Call call = service.loginUser(username, password); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = loginUserDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.loginUser(username, password) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = loginUserDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } /** @@ -1714,8 +1703,7 @@ public void onResponse(Call call, Response response) * @return the String object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse loginUser(String username, String password) throws ServiceException, IOException { - Call call = service.loginUser(username, password); - return loginUserDelegate(call.execute()); + return loginUserAsync(username, password).toBlocking().single(); } /** @@ -1724,29 +1712,32 @@ public ServiceResponse loginUser(String username, String password) throw * @param username The user name for login * @param password The password for login in clear text * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall loginUserAsync(String username, String password, final ServiceCallback serviceCallback) { - Call call = service.loginUser(username, password); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = loginUserDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return ServiceCall.create(loginUserAsync(username, password), serviceCallback); + } + + /** + * Logs user into the system. + * + * @param username The user name for login + * @param password The password for login in clear text + * @return the observable to the String object + */ + public Observable> loginUserAsync(String username, String password) { + return service.loginUser(username, password) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = loginUserDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse loginUserDelegate(Response response) throws ServiceException, IOException { @@ -1764,37 +1755,37 @@ private ServiceResponse loginUserDelegate(Response respons * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse logoutUser() throws ServiceException, IOException { - Call call = service.logoutUser(); - return logoutUserDelegate(call.execute()); + return logoutUserAsync().toBlocking().single(); } /** * Logs out current logged in user session. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall logoutUserAsync(final ServiceCallback serviceCallback) { - Call call = service.logoutUser(); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = logoutUserDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return ServiceCall.create(logoutUserAsync(), serviceCallback); + } + + /** + * Logs out current logged in user session. + * + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> logoutUserAsync() { + return service.logoutUser() + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = logoutUserDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse logoutUserDelegate(Response response) throws ServiceException, IOException { @@ -1812,11 +1803,7 @@ private ServiceResponse logoutUserDelegate(Response response * @return the User object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse getUserByName(String username) throws ServiceException, IOException, IllegalArgumentException { - if (username == null) { - throw new IllegalArgumentException("Parameter username is required and cannot be null."); - } - Call call = service.getUserByName(username); - return getUserByNameDelegate(call.execute()); + return getUserByNameAsync(username).toBlocking().single(); } /** @@ -1824,32 +1811,34 @@ public ServiceResponse getUserByName(String username) throws ServiceExcept * * @param username The name that needs to be fetched. Use user1 for testing. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall getUserByNameAsync(String username, final ServiceCallback serviceCallback) { + return ServiceCall.create(getUserByNameAsync(username), serviceCallback); + } + + /** + * Get user by user name. + * + * @param username The name that needs to be fetched. Use user1 for testing. + * @return the observable to the User object + */ + public Observable> getUserByNameAsync(String username) { if (username == null) { throw new IllegalArgumentException("Parameter username is required and cannot be null."); } - Call call = service.getUserByName(username); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = getUserByNameDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.getUserByName(username) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getUserByNameDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse getUserByNameDelegate(Response response) throws ServiceException, IOException, IllegalArgumentException { @@ -1871,12 +1860,7 @@ private ServiceResponse getUserByNameDelegate(Response respo * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse updateUser(String username) throws ServiceException, IOException, IllegalArgumentException { - if (username == null) { - throw new IllegalArgumentException("Parameter username is required and cannot be null."); - } - final User body = null; - Call call = service.updateUser(username, body); - return updateUserDelegate(call.execute()); + return updateUserAsync(username).toBlocking().single(); } /** @@ -1885,33 +1869,36 @@ public ServiceResponse updateUser(String username) throws ServiceException * * @param username name that need to be deleted * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall updateUserAsync(String username, final ServiceCallback serviceCallback) { + return ServiceCall.create(updateUserAsync(username), serviceCallback); + } + + /** + * Updated user. + * This can only be done by the logged in user. + * + * @param username name that need to be deleted + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updateUserAsync(String username) { if (username == null) { throw new IllegalArgumentException("Parameter username is required and cannot be null."); } final User body = null; - Call call = service.updateUser(username, body); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = updateUserDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); + return service.updateUser(username, body) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updateUserDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } /** @@ -1926,12 +1913,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse updateUser(String username, User body) throws ServiceException, IOException, IllegalArgumentException { - if (username == null) { - throw new IllegalArgumentException("Parameter username is required and cannot be null."); - } - Validator.validate(body); - Call call = service.updateUser(username, body); - return updateUserDelegate(call.execute()); + return updateUserAsync(username, body).toBlocking().single(); } /** @@ -1941,33 +1923,37 @@ public ServiceResponse updateUser(String username, User body) throws Servi * @param username name that need to be deleted * @param body Updated user object * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall updateUserAsync(String username, User body, final ServiceCallback serviceCallback) { + return ServiceCall.create(updateUserAsync(username, body), serviceCallback); + } + + /** + * Updated user. + * This can only be done by the logged in user. + * + * @param username name that need to be deleted + * @param body Updated user object + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updateUserAsync(String username, User body) { if (username == null) { throw new IllegalArgumentException("Parameter username is required and cannot be null."); } Validator.validate(body); - Call call = service.updateUser(username, body); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = updateUserDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); + return service.updateUser(username, body) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updateUserDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); - } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse updateUserDelegate(Response response) throws ServiceException, IOException, IllegalArgumentException { @@ -1988,11 +1974,7 @@ private ServiceResponse updateUserDelegate(Response response * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse deleteUser(String username) throws ServiceException, IOException, IllegalArgumentException { - if (username == null) { - throw new IllegalArgumentException("Parameter username is required and cannot be null."); - } - Call call = service.deleteUser(username); - return deleteUserDelegate(call.execute()); + return deleteUserAsync(username).toBlocking().single(); } /** @@ -2001,32 +1983,35 @@ public ServiceResponse deleteUser(String username) throws ServiceException * * @param username The name that needs to be deleted * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ public ServiceCall deleteUserAsync(String username, final ServiceCallback serviceCallback) { + return ServiceCall.create(deleteUserAsync(username), serviceCallback); + } + + /** + * Delete user. + * This can only be done by the logged in user. + * + * @param username The name that needs to be deleted + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> deleteUserAsync(String username) { if (username == null) { throw new IllegalArgumentException("Parameter username is required and cannot be null."); } - Call call = service.deleteUser(username); - final ServiceCall serviceCall = new ServiceCall<>(call); - call.enqueue(new ServiceResponseCallback(serviceCall, serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse clientResponse = deleteUserDelegate(response); - if (serviceCallback != null) { - serviceCallback.success(clientResponse); - } - serviceCall.success(clientResponse); - } catch (ServiceException | IOException exception) { - if (serviceCallback != null) { - serviceCallback.failure(exception); + return service.deleteUser(username) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = deleteUserDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); } - serviceCall.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse deleteUserDelegate(Response response) throws ServiceException, IOException, IllegalArgumentException { diff --git a/Samples/petstore/Python/swaggerpetstore/models/pet.py b/Samples/petstore/Python/swaggerpetstore/models/pet.py index 76ee419ffe..2ed1ea5679 100644 --- a/Samples/petstore/Python/swaggerpetstore/models/pet.py +++ b/Samples/petstore/Python/swaggerpetstore/models/pet.py @@ -14,13 +14,13 @@ class Pet(Model): the pet. :type id: long :param category: - :type category: :class:`Category ` + :type category: :class:`Category ` :param name: :type name: str :param photo_urls: :type photo_urls: list of str :param tags: - :type tags: list of :class:`Tag ` + :type tags: list of :class:`Tag ` :param status: pet status in the store. Possible values include: 'available', 'pending', 'sold' :type status: str diff --git a/Samples/petstore/Python/swaggerpetstore/swagger_petstore.py b/Samples/petstore/Python/swaggerpetstore/swagger_petstore.py index dedf0e39eb..2aab59ccbc 100644 --- a/Samples/petstore/Python/swaggerpetstore/swagger_petstore.py +++ b/Samples/petstore/Python/swaggerpetstore/swagger_petstore.py @@ -105,7 +105,7 @@ def add_pet( your pet is invalid. :param body: Pet object that needs to be added to the store - :type body: :class:`Pet ` + :type body: :class:`Pet ` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response @@ -150,7 +150,7 @@ def update_pet( """Update an existing pet. :param body: Pet object that needs to be added to the store - :type body: :class:`Pet ` + :type body: :class:`Pet ` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response @@ -203,7 +203,7 @@ def find_pets_by_status( deserialized response :param operation_config: :ref:`Operation configuration overrides`. - :rtype: list of :class:`Pet ` + :rtype: list of :class:`Pet ` :rtype: :class:`ClientRawResponse` if raw=true """ @@ -253,7 +253,7 @@ def find_pets_by_tags( deserialized response :param operation_config: :ref:`Operation configuration overrides`. - :rtype: list of :class:`Pet ` + :rtype: list of :class:`Pet ` :rtype: :class:`ClientRawResponse` if raw=true """ @@ -355,7 +355,7 @@ def get_pet_by_id( deserialized response :param operation_config: :ref:`Operation configuration overrides`. - :rtype: :class:`Pet ` + :rtype: :class:`Pet ` :rtype: :class:`ClientRawResponse` if raw=true """ @@ -595,13 +595,13 @@ def place_order( """Place an order for a pet. :param body: order placed for purchasing the pet - :type body: :class:`Order ` + :type body: :class:`Order ` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides`. - :rtype: :class:`Order ` + :rtype: :class:`Order ` :rtype: :class:`ClientRawResponse` if raw=true """ @@ -656,7 +656,7 @@ def get_order_by_id( deserialized response :param operation_config: :ref:`Operation configuration overrides`. - :rtype: :class:`Order ` + :rtype: :class:`Order ` :rtype: :class:`ClientRawResponse` if raw=true """ @@ -746,7 +746,7 @@ def create_user( This can only be done by the logged in user. :param body: Created user object - :type body: :class:`User ` + :type body: :class:`User ` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response @@ -791,7 +791,7 @@ def create_users_with_array_input( """Creates list of users with given input array. :param body: List of user object - :type body: list of :class:`User ` + :type body: list of :class:`User ` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response @@ -836,7 +836,7 @@ def create_users_with_list_input( """Creates list of users with given input array. :param body: List of user object - :type body: list of :class:`User ` + :type body: list of :class:`User ` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response @@ -975,7 +975,7 @@ def get_user_by_name( deserialized response :param operation_config: :ref:`Operation configuration overrides`. - :rtype: :class:`User ` + :rtype: :class:`User ` :rtype: :class:`ClientRawResponse` if raw=true """ @@ -1022,7 +1022,7 @@ def update_user( :param username: name that need to be deleted :type username: str :param body: Updated user object - :type body: :class:`User ` + :type body: :class:`User ` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response diff --git a/src/dev/TestServer/swagger/azure-composite-swagger.json b/src/dev/TestServer/swagger/azure-composite-swagger.json index 39681bdabe..dbc4360ad6 100644 --- a/src/dev/TestServer/swagger/azure-composite-swagger.json +++ b/src/dev/TestServer/swagger/azure-composite-swagger.json @@ -4,7 +4,7 @@ "description": "Composite Swagger Client that represents merging body complex and complex model swagger clients" }, "documents": [ - "src/dev/TestServer/swagger/complex-model.json", - "src/dev/TestServer/swagger/body-complex.json" + "./complex-model.json", + "./body-complex.json" ] } diff --git a/src/dev/TestServer/swagger/composite-swagger.json b/src/dev/TestServer/swagger/composite-swagger.json index 9a5ef720ce..edfad404ae 100644 --- a/src/dev/TestServer/swagger/composite-swagger.json +++ b/src/dev/TestServer/swagger/composite-swagger.json @@ -4,7 +4,7 @@ "description": "Composite Swagger Client that represents merging body boolean and body integer swagger clients" }, "documents": [ - "src/dev/TestServer/swagger/body-boolean.json", - "src/dev/TestServer/swagger/body-integer.json" + "./body-boolean.json", + "./body-integer.json" ] } diff --git a/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-conflict-in-global-param.json b/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-conflict-in-global-param.json index bcf7df8399..4f554620b2 100644 --- a/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-conflict-in-global-param.json +++ b/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-conflict-in-global-param.json @@ -4,7 +4,7 @@ "description": "Swagger 1 documentation." }, "documents": [ - "Swagger/swagger-1.json", - "Swagger/swagger-conflict-in-global-param.json" + "./swagger-1.json", + "./swagger-conflict-in-global-param.json" ] } diff --git a/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-conflict-in-model.json b/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-conflict-in-model.json index 7786cbbe67..495ebf9a1a 100644 --- a/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-conflict-in-model.json +++ b/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-conflict-in-model.json @@ -4,7 +4,7 @@ "description": "Swagger 1 documentation." }, "documents": [ - "Swagger/swagger-1.json", - "Swagger/swagger-conflict-in-model.json" + "./swagger-1.json", + "./swagger-conflict-in-model.json" ] } diff --git a/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-conflict-in-settings.json b/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-conflict-in-settings.json index 494aa6e997..c3dd9f4c79 100644 --- a/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-conflict-in-settings.json +++ b/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-conflict-in-settings.json @@ -4,7 +4,7 @@ "description": "Swagger 1 documentation." }, "documents": [ - "Swagger/swagger-1.json", - "Swagger/swagger-conflict-in-settings.json" + "./swagger-1.json", + "./swagger-conflict-in-settings.json" ] } diff --git a/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-empty2.json b/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-empty2.json index 95ba3550e7..0b3768c982 100644 --- a/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-empty2.json +++ b/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-empty2.json @@ -1,3 +1,3 @@ { - "documents": [ "Swagger/swagger-1.json" ] + "documents": [ "./swagger-1.json" ] } diff --git a/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-good1.json b/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-good1.json index 512ef35680..c41a9df2c2 100644 --- a/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-good1.json +++ b/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-good1.json @@ -4,7 +4,7 @@ "description": "Swagger 1 documentation." }, "documents": [ - "Swagger/swagger-1.json", - "Swagger/swagger-2.json" + "./swagger-1.json", + "./swagger-2.json" ] } diff --git a/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-good2.json b/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-good2.json index 7624dfc799..b622eaf3d0 100644 --- a/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-good2.json +++ b/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-good2.json @@ -4,6 +4,6 @@ "description": "Swagger 1 documentation." }, "documents": [ - "Swagger/swagger-1.json" + "./swagger-1.json" ] } diff --git a/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-good3.json b/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-good3.json index 889a09853b..2f8e4a3b07 100644 --- a/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-good3.json +++ b/src/modeler/AutoRest.CompositeSwagger.Tests/Swagger/composite-swagger-good3.json @@ -4,7 +4,7 @@ "description": "Swagger 1 documentation." }, "documents": [ - "Swagger/swagger-1.json", - "Swagger/swagger-1.json" + "./swagger-1.json", + "./swagger-1.json" ] } diff --git a/src/modeler/AutoRest.CompositeSwagger/CompositeSwaggerModeler.cs b/src/modeler/AutoRest.CompositeSwagger/CompositeSwaggerModeler.cs index 30e6cceb50..2ad28c1917 100644 --- a/src/modeler/AutoRest.CompositeSwagger/CompositeSwaggerModeler.cs +++ b/src/modeler/AutoRest.CompositeSwagger/CompositeSwaggerModeler.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. using System; +using System.IO; using System.Globalization; using System.Linq; using AutoRest.CompositeSwagger.Model; @@ -52,8 +53,27 @@ public override ServiceClient Build() throw ErrorManager.CreateError(Resources.InfoSectionMissing); } - ServiceClient compositeClient = InitializeServiceClient(compositeSwaggerModel); + //Ensure all the docs are absolute paths + var basePath = Directory.GetParent(Settings.Input).FullName; + var isBasePathUri = Uri.IsWellFormedUriString(basePath, UriKind.Absolute); + for (var i = 0; i < compositeSwaggerModel.Documents.Count; i++) + { + if (!(Path.IsPathRooted(compositeSwaggerModel.Documents[i]) || + Uri.IsWellFormedUriString(compositeSwaggerModel.Documents[i], UriKind.Absolute))) + { + var tempPath = Path.Combine(basePath, compositeSwaggerModel.Documents[i]); + if (isBasePathUri) + { + compositeSwaggerModel.Documents[i] = new Uri(tempPath).AbsoluteUri; + } + else + { + compositeSwaggerModel.Documents[i] = Path.GetFullPath(tempPath); + } + } + } + ServiceClient compositeClient = InitializeServiceClient(compositeSwaggerModel); foreach (var childSwaggerPath in compositeSwaggerModel.Documents) { Settings.Input = childSwaggerPath; @@ -98,7 +118,7 @@ private CompositeServiceDefinition Parse(string input) TypeNameHandling = TypeNameHandling.None, MetadataPropertyHandling = MetadataPropertyHandling.Ignore }; - return JsonConvert.DeserializeObject(inputBody, settings); + return JsonConvert.DeserializeObject(inputBody, settings); } catch (JsonException ex) {