|
| 1 | +/* |
| 2 | + * This code was generated by |
| 3 | + * |
| 4 | + * SENDGRID-OAI-GENERATOR |
| 5 | + * |
| 6 | + * Twilio SendGrid Account Provisioning API |
| 7 | + * The Twilio SendGrid Account Provisioning API provides a platform for Twilio SendGrid resellers to manage their customer accounts. This API is for companies that have a formal reseller partnership with Twilio SendGrid. You can access Twilio SendGrid sub-account functionality without becoming a reseller. If you require sub-account functionality, see the Twilio [SendGrid Subusers](https://docs.sendgrid.com/ui/account-and-settings/subusers) feature, which is available with [Pro and Premier plans](https://sendgrid.com/pricing/). |
| 8 | + * |
| 9 | + * NOTE: This class is auto generated by OpenAPI Generator. |
| 10 | + * https://openapi-generator.tech |
| 11 | + * Do not edit the class manually. |
| 12 | + */ |
| 13 | + |
| 14 | +package com.sendgrid.rest.api.v3.accountprovisioning; |
| 15 | + |
| 16 | +import com.sendgrid.base.apikey.ApiKeyBase; |
| 17 | +import com.sendgrid.constant.ApplicationConstants; |
| 18 | +import com.sendgrid.constant.Domains; |
| 19 | +import com.sendgrid.exception.ApiConnectionException; |
| 20 | +import com.sendgrid.exception.ApiErrorResponse; |
| 21 | +import com.sendgrid.exception.GenericApiError; |
| 22 | +import com.sendgrid.http.ApiKeyRestClient; |
| 23 | +import com.sendgrid.http.ApiResponse; |
| 24 | +import com.sendgrid.http.HttpMethod; |
| 25 | +import com.sendgrid.http.Request; |
| 26 | +import com.sendgrid.http.Response; |
| 27 | +import com.sendgrid.rest.api.v3.accountprovisioning.models.AccountProvisioningAccountId; |
| 28 | +import com.sendgrid.rest.api.v3.accountprovisioning.models.CreateAccountParams; |
| 29 | +import com.sendgrid.util.JsonUtil; |
| 30 | +import com.sendgrid.util.Matcher; |
| 31 | +import lombok.RequiredArgsConstructor; |
| 32 | +import lombok.Setter; |
| 33 | + |
| 34 | +@RequiredArgsConstructor |
| 35 | +public class CreateAccount extends ApiKeyBase { |
| 36 | + |
| 37 | + @Setter |
| 38 | + private String tTestAccount; |
| 39 | + |
| 40 | + @Setter |
| 41 | + private CreateAccountParams createAccountParams; |
| 42 | + |
| 43 | + public ApiResponse<AccountProvisioningAccountId> send( |
| 44 | + final ApiKeyRestClient client |
| 45 | + ) { |
| 46 | + String path = "/v3/partners/accounts"; |
| 47 | + Request request = new Request( |
| 48 | + HttpMethod.POST, |
| 49 | + path, |
| 50 | + Domains.API.toString() |
| 51 | + ); |
| 52 | + addHeaderParams(request); |
| 53 | + addBody(request); |
| 54 | + Response response = client.request(request); |
| 55 | + |
| 56 | + if (response == null) { |
| 57 | + throw new ApiConnectionException( |
| 58 | + "CreateAccount creation failed: Unable to connect to server" |
| 59 | + ); |
| 60 | + } else if ( |
| 61 | + !ApplicationConstants.SUCCESS.test(response.getStatusCode()) |
| 62 | + ) { |
| 63 | + int statusCode = response.getStatusCode(); |
| 64 | + if (Matcher.matches(Integer.toString(statusCode), "400")) { |
| 65 | + Object error = JsonUtil.fromJson( |
| 66 | + response.getStream(), |
| 67 | + Object.class |
| 68 | + ); |
| 69 | + throw new ApiErrorResponse( |
| 70 | + statusCode, |
| 71 | + null, |
| 72 | + error, |
| 73 | + response.getHeaders() |
| 74 | + ); |
| 75 | + } |
| 76 | + |
| 77 | + if (Matcher.matches(Integer.toString(statusCode), "401")) { |
| 78 | + Object error = JsonUtil.fromJson( |
| 79 | + response.getStream(), |
| 80 | + Object.class |
| 81 | + ); |
| 82 | + throw new ApiErrorResponse( |
| 83 | + statusCode, |
| 84 | + null, |
| 85 | + error, |
| 86 | + response.getHeaders() |
| 87 | + ); |
| 88 | + } |
| 89 | + |
| 90 | + if (Matcher.matches(Integer.toString(statusCode), "403")) { |
| 91 | + Object error = JsonUtil.fromJson( |
| 92 | + response.getStream(), |
| 93 | + Object.class |
| 94 | + ); |
| 95 | + throw new ApiErrorResponse( |
| 96 | + statusCode, |
| 97 | + null, |
| 98 | + error, |
| 99 | + response.getHeaders() |
| 100 | + ); |
| 101 | + } |
| 102 | + |
| 103 | + GenericApiError error = JsonUtil.fromJson( |
| 104 | + response.getStream(), |
| 105 | + GenericApiError.class |
| 106 | + ); |
| 107 | + throw new ApiErrorResponse( |
| 108 | + statusCode, |
| 109 | + null, |
| 110 | + error, |
| 111 | + response.getHeaders() |
| 112 | + ); |
| 113 | + } |
| 114 | + int statusCode = response.getStatusCode(); |
| 115 | + return new ApiResponse( |
| 116 | + statusCode, |
| 117 | + JsonUtil.fromJson( |
| 118 | + response.getStream(), |
| 119 | + AccountProvisioningAccountId.class |
| 120 | + ), |
| 121 | + response.getHeaders() |
| 122 | + ); |
| 123 | + } |
| 124 | + |
| 125 | + private void addHeaderParams(Request request) { |
| 126 | + if (tTestAccount != null) { |
| 127 | + request.addHeaderParam("T-Test-Account", tTestAccount.toString()); |
| 128 | + } |
| 129 | + } |
| 130 | + |
| 131 | + private void addBody(final Request request) { |
| 132 | + if (createAccountParams != null) { |
| 133 | + request.addBody(JsonUtil.toJson(createAccountParams)); |
| 134 | + } |
| 135 | + } |
| 136 | +} |
0 commit comments