Skip to content

Commit

Permalink
feat: auto generated code from open api specs
Browse files Browse the repository at this point in the history
  • Loading branch information
sbansla committed Jun 27, 2024
1 parent 907a89f commit 95f830e
Show file tree
Hide file tree
Showing 1,146 changed files with 111,811 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Change Log
All notable changes to this project will be documented in this file.

[2024-06-27] Version 5.0.0-rc.1
--------------------------------
- Generating Sendgrid Code using open api spec.

[2024-06-27] Version 5.0.0-rc.0
--------------------------------
- Release Candidate prep
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ touch Example.java
Add the example you want to test to Example.java, including the headers at the top of the file.

``` bash
javac -classpath ../repo/com/sendgrid/4.10.2/sendgrid-4.10.2-jar.jar:. Example.java && java -classpath ../repo/com/sendgrid/4.10.2/sendgrid-4.10.2-jar.jar:. Example
javac -classpath ../repo/com/sendgrid/5.0.0-rc.1/sendgrid-5.0.0-rc.1-jar.jar:. Example.java && java -classpath ../repo/com/sendgrid/5.0.0-rc.1/sendgrid-5.0.0-rc.1-jar.jar:. Example
```

<a name="understanding-the-codebase"></a>
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Add the following to your build.gradle file in the root of your project.
...
dependencies {
...
implementation 'com.sendgrid:sendgrid-java:4.10.2'
implementation 'com.sendgrid:sendgrid-java:5.0.0-rc.1'
}
repositories {
Expand All @@ -81,7 +81,7 @@ mvn install

You can just drop the jar file in. It's a fat jar - it has all the dependencies built in.

[sendgrid-java.jar](https://github.com/sendgrid/sendgrid-java/releases/download/4.10.2/sendgrid-java.jar)
[sendgrid-java.jar](https://github.com/sendgrid/sendgrid-java/releases/download/5.0.0-rc.1/sendgrid-java.jar)

## Dependencies

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<groupId>com.sendgrid</groupId>
<artifactId>sendgrid-java</artifactId>
<name>Twilio SendGrid Java helper library</name>
<version>4.10.2</version>
<version>5.0.0-rc.1</version>
<description>This Java module allows you to quickly and easily send emails through Twilio SendGrid using Java.</description>
<url>https://github.com/sendgrid/sendgrid-java</url>
<licenses>
Expand All @@ -26,7 +26,7 @@
<url>https://github.com/sendgrid/sendgrid-java</url>
<connection>scm:git:git@github.com:sendgrid/sendgrid-java.git</connection>
<developerConnection>scm:git:git@github.com:sendgrid/sendgrid-java.git</developerConnection>
<tag>4.10.2</tag>
<tag>5.0.0-rc.1</tag>
</scm>
<profiles>
<profile>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/sendgrid/constant/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@UtilityClass
public class Config {
public static final String VERSION = "5.0.0-rc.0";
public static final String VERSION = "5.0.0-rc.1";
public static final String JAVA_VERSION = System.getProperty("java.version");
public static final String OS_NAME = System.getProperty("os.name");
public static final String OS_ARCH = System.getProperty("os.arch");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* This code was generated by
*
* SENDGRID-OAI-GENERATOR
*
* Twilio SendGrid Account Provisioning API
* 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/).
*
* NOTE: This class is auto generated by OpenAPI Generator.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

package com.sendgrid.rest.api.v3.accountprovisioning;

import com.sendgrid.base.apikey.ApiKeyBase;
import com.sendgrid.constant.ApplicationConstants;
import com.sendgrid.constant.Domains;
import com.sendgrid.exception.ApiConnectionException;
import com.sendgrid.exception.ApiErrorResponse;
import com.sendgrid.exception.GenericApiError;
import com.sendgrid.http.ApiKeyRestClient;
import com.sendgrid.http.ApiResponse;
import com.sendgrid.http.HttpMethod;
import com.sendgrid.http.Request;
import com.sendgrid.http.Response;
import com.sendgrid.util.JsonUtil;
import com.sendgrid.util.Matcher;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class AuthenticateAccount extends ApiKeyBase {

private final String accountID;

public ApiResponse<Void> send(final ApiKeyRestClient client) {
String path = "/v3/partners/accounts/{accountID}/sso";
Request request = new Request(
HttpMethod.POST,
path,
Domains.API.toString()
);
addPathParams(request);
Response response = client.request(request);

if (response == null) {
throw new ApiConnectionException(
"AuthenticateAccount creation failed: Unable to connect to server"
);
} else if (
!ApplicationConstants.SUCCESS.test(response.getStatusCode())
) {
int statusCode = response.getStatusCode();
if (Matcher.matches(Integer.toString(statusCode), "401")) {
Object error = JsonUtil.fromJson(
response.getStream(),
Object.class
);
throw new ApiErrorResponse(
statusCode,
null,
error,
response.getHeaders()
);
}

if (Matcher.matches(Integer.toString(statusCode), "403")) {
Object error = JsonUtil.fromJson(
response.getStream(),
Object.class
);
throw new ApiErrorResponse(
statusCode,
null,
error,
response.getHeaders()
);
}

if (Matcher.matches(Integer.toString(statusCode), "404")) {
Object error = JsonUtil.fromJson(
response.getStream(),
Object.class
);
throw new ApiErrorResponse(
statusCode,
null,
error,
response.getHeaders()
);
}

GenericApiError error = JsonUtil.fromJson(
response.getStream(),
GenericApiError.class
);
throw new ApiErrorResponse(
statusCode,
null,
error,
response.getHeaders()
);
}
int statusCode = response.getStatusCode();
return new ApiResponse(statusCode, response.getHeaders());
}

private void addPathParams(Request request) {
if (accountID != null) {
request.addPathParam("accountID", accountID.toString());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* This code was generated by
*
* SENDGRID-OAI-GENERATOR
*
* Twilio SendGrid Account Provisioning API
* 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/).
*
* NOTE: This class is auto generated by OpenAPI Generator.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

package com.sendgrid.rest.api.v3.accountprovisioning;

import com.sendgrid.base.apikey.ApiKeyBase;
import com.sendgrid.constant.ApplicationConstants;
import com.sendgrid.constant.Domains;
import com.sendgrid.exception.ApiConnectionException;
import com.sendgrid.exception.ApiErrorResponse;
import com.sendgrid.exception.GenericApiError;
import com.sendgrid.http.ApiKeyRestClient;
import com.sendgrid.http.ApiResponse;
import com.sendgrid.http.HttpMethod;
import com.sendgrid.http.Request;
import com.sendgrid.http.Response;
import com.sendgrid.rest.api.v3.accountprovisioning.models.AccountProvisioningAccountId;
import com.sendgrid.rest.api.v3.accountprovisioning.models.CreateAccountParams;
import com.sendgrid.util.JsonUtil;
import com.sendgrid.util.Matcher;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

@RequiredArgsConstructor
public class CreateAccount extends ApiKeyBase {

@Setter
private String tTestAccount;

@Setter
private CreateAccountParams createAccountParams;

public ApiResponse<AccountProvisioningAccountId> send(
final ApiKeyRestClient client
) {
String path = "/v3/partners/accounts";
Request request = new Request(
HttpMethod.POST,
path,
Domains.API.toString()
);
addHeaderParams(request);
addBody(request);
Response response = client.request(request);

if (response == null) {
throw new ApiConnectionException(
"CreateAccount creation failed: Unable to connect to server"
);
} else if (
!ApplicationConstants.SUCCESS.test(response.getStatusCode())
) {
int statusCode = response.getStatusCode();
if (Matcher.matches(Integer.toString(statusCode), "400")) {
Object error = JsonUtil.fromJson(
response.getStream(),
Object.class
);
throw new ApiErrorResponse(
statusCode,
null,
error,
response.getHeaders()
);
}

if (Matcher.matches(Integer.toString(statusCode), "401")) {
Object error = JsonUtil.fromJson(
response.getStream(),
Object.class
);
throw new ApiErrorResponse(
statusCode,
null,
error,
response.getHeaders()
);
}

if (Matcher.matches(Integer.toString(statusCode), "403")) {
Object error = JsonUtil.fromJson(
response.getStream(),
Object.class
);
throw new ApiErrorResponse(
statusCode,
null,
error,
response.getHeaders()
);
}

GenericApiError error = JsonUtil.fromJson(
response.getStream(),
GenericApiError.class
);
throw new ApiErrorResponse(
statusCode,
null,
error,
response.getHeaders()
);
}
int statusCode = response.getStatusCode();
return new ApiResponse(
statusCode,
JsonUtil.fromJson(
response.getStream(),
AccountProvisioningAccountId.class
),
response.getHeaders()
);
}

private void addHeaderParams(Request request) {
if (tTestAccount != null) {
request.addHeaderParam("T-Test-Account", tTestAccount.toString());
}
}

private void addBody(final Request request) {
if (createAccountParams != null) {
request.addBody(JsonUtil.toJson(createAccountParams));
}
}
}
Loading

0 comments on commit 95f830e

Please sign in to comment.