-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added upgrade guide and readme updates (#762)
- Loading branch information
1 parent
8b957e9
commit d4f0970
Showing
3 changed files
with
87 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,94 +90,112 @@ You can just drop the jar file in. It's a fat jar - it has all the dependencies | |
<a name="quick-start"></a> | ||
# Quick Start | ||
|
||
## Hello Email | ||
|
||
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): | ||
|
||
### With Mail Helper Class | ||
## Alerts API | ||
Sendgrid provides an API for sending alerts. The following is the minimum needed code to send an alert using the Java Helper Library: | ||
|
||
### Create Alerts | ||
```java | ||
import com.sendgrid.*; | ||
import java.io.IOException; | ||
|
||
public class Example { | ||
public static void main(String[] args) throws IOException { | ||
Email from = new Email("[email protected]"); | ||
String subject = "Sending with Twilio SendGrid is Fun"; | ||
Email to = new Email("[email protected]"); | ||
Content content = new Content("text/plain", "and easy to do anywhere, even with Java"); | ||
Mail mail = new Mail(from, subject, to, content); | ||
|
||
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); | ||
Request request = new Request(); | ||
public static void main(String[] args) { | ||
ApiKeySendGrid.init(System.getenv("SENDGRID_API_KEY")); | ||
CreateAlertRequest createAlertRequest = new CreateAlertRequest.Builder(Type.USAGE_LIMIT, "[email protected]").percentage(50).build(); | ||
try { | ||
request.setMethod(Method.POST); | ||
request.setEndpoint("mail/send"); | ||
request.setBody(mail.build()); | ||
Response response = sg.api(request); | ||
System.out.println(response.getStatusCode()); | ||
System.out.println(response.getBody()); | ||
System.out.println(response.getHeaders()); | ||
} catch (IOException ex) { | ||
throw ex; | ||
CreateAlert createAlert = new CreateAlert(); | ||
createAlert.setCreateAlertRequest(createAlertRequest); | ||
ApiResponse apiResponse = createAlert.send(); | ||
System.out.println(response.getStatusCode()); | ||
System.out.println(response.getBody()); | ||
System.out.println(response.getHeaders()); | ||
} catch (ApiErrorResponse apiErrorResponse) { | ||
System.out.println(apiErrorResponse.getMessage()); | ||
} | ||
} | ||
} | ||
``` | ||
|
||
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. | ||
|
||
### Without Mail Helper Class | ||
|
||
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): | ||
|
||
### Fetch a specific alert | ||
```java | ||
import com.sendgrid.*; | ||
import java.io.IOException; | ||
|
||
public class Example { | ||
public static void main(String[] args) throws IOException { | ||
public static void main(String[] args) { | ||
ApiKeySendGrid.init(System.getenv("SENDGRID_API_KEY")); | ||
GetAlert getAlert = new GetAlert(xxxxxxx); // alert id | ||
ApiResponse getAlertResponse = null; | ||
try { | ||
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); | ||
Request request = new Request(); | ||
request.setMethod(Method.POST); | ||
request.setEndpoint("mail/send"); | ||
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\"}]}"); | ||
Response response = sg.api(request); | ||
System.out.println(response.getStatusCode()); | ||
System.out.println(response.getBody()); | ||
System.out.println(response.getHeaders()); | ||
} catch (IOException ex) { | ||
throw ex; | ||
getAlertResponse = getAlert.send(); | ||
GetAlert200Response alert = (GetAlert200Response) getAlertResponse.getBody(); | ||
System.out.println(alert); | ||
} catch (ApiErrorResponse apiErrorResponse) { | ||
System.out.println(apiErrorResponse.getMessage()); | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## General v3 Web API Usage | ||
|
||
### List all alerts | ||
```java | ||
import com.sendgrid.*; | ||
import java.io.IOException; | ||
|
||
public class Example { | ||
public static void main(String[] args) throws IOException { | ||
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); | ||
public static void main(String[] args) { | ||
ApiKeySendGrid.init(System.getenv("SENDGRID_API_KEY")); | ||
ListAlert listAlert = new ListAlert(); | ||
ApiResponse getAlert = null; | ||
try { | ||
Request request = new Request(); | ||
request.setMethod(Method.GET); | ||
request.setEndpoint("api_keys"); | ||
Response response = sg.api(request); | ||
System.out.println(response.getStatusCode()); | ||
System.out.println(response.getBody()); | ||
System.out.println(response.getHeaders()); | ||
} catch (IOException ex) { | ||
throw ex; | ||
getAlert = listAlert.send(); | ||
List<ListAlert200ResponseInner> body = (List<ListAlert200ResponseInner>)getAlert.getBody(); | ||
System.out.println(body); | ||
} catch (ApiErrorResponse apiErrorResponse) { | ||
System.out.println(apiErrorResponse.getMessage()); | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### Delete a specific alert | ||
```java | ||
import com.sendgrid.*; | ||
import java.io.IOException; | ||
|
||
public class Example { | ||
public static void main(String[] args) { | ||
ApiKeySendGrid.init(System.getenv("SENDGRID_API_KEY")); | ||
DeleteAlert deleteAlert = new DeleteAlert(xxxxxxx); // alert id | ||
ApiResponse deleteAlertResponse; | ||
try { | ||
deleteAlertResponse = deleteAlert.send(); | ||
System.out.println(deleteAlertResponse.getStatusCode()); | ||
System.out.println(deleteAlertResponse.getBody()); | ||
System.out.println(deleteAlertResponse.getHeaders()); | ||
|
||
} catch (ApiErrorResponse apiErrorResponse) { | ||
System.out.println(apiErrorResponse.getMessage()); | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Hello Email | ||
|
||
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). | ||
|
||
### With Mail Helper Class | ||
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. | ||
|
||
### Without Mail Helper Class | ||
|
||
You can also send an email without the /mail/send Helper ([here](examples/mail/mail.java#L54) is a full example). | ||
|
||
## General v3 Web API Usage | ||
|
||
[Here](examples/apikeys/apikeys.java) is the full example of using v3 web API. | ||
|
||
<a name="usage"></a> | ||
# Usage | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Upgrade Guide | ||
|
||
_`MAJOR` version bumps will have upgrade notes posted here._ | ||
|
||
[2023-10-XX] 4.x.x to 5.x.x-rc.x | ||
-------------------------------- | ||
### Overview | ||
|
||
#### 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 | ||
|
||
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. |