Skip to content

Commit d4f0970

Browse files
chore: added upgrade guide and readme updates (#762)
1 parent 8b957e9 commit d4f0970

File tree

3 files changed

+87
-54
lines changed

3 files changed

+87
-54
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
[2024-06-27] Version 5.0.0-rc.0
5+
--------------------------------
6+
- Release Candidate prep
7+
48
[2024-02-14] Version 4.10.2
59
---------------------------
610
**Library - Chore**

README.md

Lines changed: 72 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -90,94 +90,112 @@ You can just drop the jar file in. It's a fat jar - it has all the dependencies
9090
<a name="quick-start"></a>
9191
# Quick Start
9292

93-
## Hello Email
94-
95-
The following is the minimum needed code to send an email with the [/mail/send Helper](src/main/java/com/sendgrid/helpers) ([here](examples/helpers/mail/Example.java#L30) is a full example):
96-
97-
### With Mail Helper Class
93+
## Alerts API
94+
Sendgrid provides an API for sending alerts. The following is the minimum needed code to send an alert using the Java Helper Library:
9895

96+
### Create Alerts
9997
```java
10098
import com.sendgrid.*;
10199
import java.io.IOException;
102100

103101
public class Example {
104-
public static void main(String[] args) throws IOException {
105-
Email from = new Email("[email protected]");
106-
String subject = "Sending with Twilio SendGrid is Fun";
107-
Email to = new Email("[email protected]");
108-
Content content = new Content("text/plain", "and easy to do anywhere, even with Java");
109-
Mail mail = new Mail(from, subject, to, content);
110-
111-
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
112-
Request request = new Request();
102+
public static void main(String[] args) {
103+
ApiKeySendGrid.init(System.getenv("SENDGRID_API_KEY"));
104+
CreateAlertRequest createAlertRequest = new CreateAlertRequest.Builder(Type.USAGE_LIMIT, "[email protected]").percentage(50).build();
113105
try {
114-
request.setMethod(Method.POST);
115-
request.setEndpoint("mail/send");
116-
request.setBody(mail.build());
117-
Response response = sg.api(request);
118-
System.out.println(response.getStatusCode());
119-
System.out.println(response.getBody());
120-
System.out.println(response.getHeaders());
121-
} catch (IOException ex) {
122-
throw ex;
106+
CreateAlert createAlert = new CreateAlert();
107+
createAlert.setCreateAlertRequest(createAlertRequest);
108+
ApiResponse apiResponse = createAlert.send();
109+
System.out.println(response.getStatusCode());
110+
System.out.println(response.getBody());
111+
System.out.println(response.getHeaders());
112+
} catch (ApiErrorResponse apiErrorResponse) {
113+
System.out.println(apiErrorResponse.getMessage());
123114
}
124115
}
125116
}
126117
```
127118

128-
The `Mail` constructor creates a [personalization object](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html) for you. [Here](examples/helpers/mail/Example.java#L221) is an example of how to add to it.
129-
130-
### Without Mail Helper Class
131-
132-
The following is the minimum needed code to send an email without the /mail/send Helper ([here](examples/mail/mail.java#L54) is a full example):
133-
119+
### Fetch a specific alert
134120
```java
135121
import com.sendgrid.*;
136122
import java.io.IOException;
137123

138124
public class Example {
139-
public static void main(String[] args) throws IOException {
125+
public static void main(String[] args) {
126+
ApiKeySendGrid.init(System.getenv("SENDGRID_API_KEY"));
127+
GetAlert getAlert = new GetAlert(xxxxxxx); // alert id
128+
ApiResponse getAlertResponse = null;
140129
try {
141-
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
142-
Request request = new Request();
143-
request.setMethod(Method.POST);
144-
request.setEndpoint("mail/send");
145-
request.setBody("{\"personalizations\":[{\"to\":[{\"email\":\"[email protected]\"}],\"subject\":\"Sending with Twilio SendGrid is Fun\"}],\"from\":{\"email\":\"[email protected]\"},\"content\":[{\"type\":\"text/plain\",\"value\": \"and easy to do anywhere, even with Java\"}]}");
146-
Response response = sg.api(request);
147-
System.out.println(response.getStatusCode());
148-
System.out.println(response.getBody());
149-
System.out.println(response.getHeaders());
150-
} catch (IOException ex) {
151-
throw ex;
130+
getAlertResponse = getAlert.send();
131+
GetAlert200Response alert = (GetAlert200Response) getAlertResponse.getBody();
132+
System.out.println(alert);
133+
} catch (ApiErrorResponse apiErrorResponse) {
134+
System.out.println(apiErrorResponse.getMessage());
152135
}
153136
}
154137
}
155138
```
156139

157-
## General v3 Web API Usage
158-
140+
### List all alerts
159141
```java
160142
import com.sendgrid.*;
161143
import java.io.IOException;
162144

163145
public class Example {
164-
public static void main(String[] args) throws IOException {
165-
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
146+
public static void main(String[] args) {
147+
ApiKeySendGrid.init(System.getenv("SENDGRID_API_KEY"));
148+
ListAlert listAlert = new ListAlert();
149+
ApiResponse getAlert = null;
166150
try {
167-
Request request = new Request();
168-
request.setMethod(Method.GET);
169-
request.setEndpoint("api_keys");
170-
Response response = sg.api(request);
171-
System.out.println(response.getStatusCode());
172-
System.out.println(response.getBody());
173-
System.out.println(response.getHeaders());
174-
} catch (IOException ex) {
175-
throw ex;
151+
getAlert = listAlert.send();
152+
List<ListAlert200ResponseInner> body = (List<ListAlert200ResponseInner>)getAlert.getBody();
153+
System.out.println(body);
154+
} catch (ApiErrorResponse apiErrorResponse) {
155+
System.out.println(apiErrorResponse.getMessage());
176156
}
177157
}
178158
}
179159
```
180160

161+
### Delete a specific alert
162+
```java
163+
import com.sendgrid.*;
164+
import java.io.IOException;
165+
166+
public class Example {
167+
public static void main(String[] args) {
168+
ApiKeySendGrid.init(System.getenv("SENDGRID_API_KEY"));
169+
DeleteAlert deleteAlert = new DeleteAlert(xxxxxxx); // alert id
170+
ApiResponse deleteAlertResponse;
171+
try {
172+
deleteAlertResponse = deleteAlert.send();
173+
System.out.println(deleteAlertResponse.getStatusCode());
174+
System.out.println(deleteAlertResponse.getBody());
175+
System.out.println(deleteAlertResponse.getHeaders());
176+
177+
} catch (ApiErrorResponse apiErrorResponse) {
178+
System.out.println(apiErrorResponse.getMessage());
179+
}
180+
}
181+
}
182+
```
183+
184+
## Hello Email
185+
186+
You can send an email with the [/mail/send Helper](src/main/java/com/sendgrid/helpers) ([here](examples/helpers/mail/Example.java#L30) is a full example).
187+
188+
### With Mail Helper Class
189+
The `Mail` constructor creates a [personalization object](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html) for you. [Here](examples/helpers/mail/Example.java#L221) is an example of how to add to it.
190+
191+
### Without Mail Helper Class
192+
193+
You can also send an email without the /mail/send Helper ([here](examples/mail/mail.java#L54) is a full example).
194+
195+
## General v3 Web API Usage
196+
197+
[Here](examples/apikeys/apikeys.java) is the full example of using v3 web API.
198+
181199
<a name="usage"></a>
182200
# Usage
183201

UPGRADE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Upgrade Guide
2+
3+
_`MAJOR` version bumps will have upgrade notes posted here._
4+
5+
[2023-10-XX] 4.x.x to 5.x.x-rc.x
6+
--------------------------------
7+
### Overview
8+
9+
#### Sendgrid Java Helper Library’s major version 5.0.0-rc.x is now available. We ensured that you can upgrade to Java helper Library 5.0.0-rc.x version without any breaking changes
10+
11+
Behind the scenes Java Helper is now auto-generated via OpenAPI with this release. This enables us to rapidly add new features and enhance consistency across versions and languages.

0 commit comments

Comments
 (0)