Skip to content

Commit

Permalink
Merge pull request #91 from GoogleCloudPlatform/checkstyle
Browse files Browse the repository at this point in the history
Fix checkstyle in twilio and sendgrid samples.
  • Loading branch information
tswast committed Feb 11, 2016
2 parents 97968e6 + d4a8de9 commit 7ce1a32
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 30 deletions.
4 changes: 0 additions & 4 deletions managed_vms/sendgrid/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
<target>1.8</target>
</configuration>
</plugin>
<!--
The sendgrid sample currently (2016-01-22) fails the Google Style
checks. We can uncomment this block when it is fixed.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
Expand All @@ -65,7 +62,6 @@
<execution><goals><goal>check</goal></goals></execution>
</executions>
</plugin>
-->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ public class SendEmailServlet extends HttpServlet {
@Override
public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException,
ServletException {
final String SENDGRID_API_KEY = System.getenv("SENDGRID_API_KEY");
final String SENDGRID_SENDER = System.getenv("SENDGRID_SENDER");
final String TO_EMAIL = req.getParameter("to");
if (TO_EMAIL == null) {
resp.getWriter().print("Please provide an email address in the \"to\" query string"
+ " parameter.");
final String sendgridApiKey = System.getenv("SENDGRID_API_KEY");
final String sendgridSender = System.getenv("SENDGRID_SENDER");
final String toEmail = req.getParameter("to");
if (toEmail == null) {
resp.getWriter()
.print("Please provide an email address in the \"to\" query string parameter.");
return;
}

SendGrid sendgrid = new SendGrid(SENDGRID_API_KEY);
SendGrid sendgrid = new SendGrid(sendgridApiKey);
SendGrid.Email email = new SendGrid.Email();
email.addTo(TO_EMAIL);
email.setFrom(SENDGRID_SENDER);
email.addTo(toEmail);
email.setFrom(sendgridSender);
email.setSubject("This is a test email");
email.setText("Example text body.");

Expand All @@ -58,8 +58,7 @@ public void service(HttpServletRequest req, HttpServletResponse resp) throws IOE
return;
}
resp.getWriter().print("Email sent.");
}
catch (SendGridException e) {
} catch (SendGridException e) {
throw new ServletException("SendGrid error", e);
}
}
Expand Down
4 changes: 0 additions & 4 deletions managed_vms/twilio/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
<target>1.8</target>
</configuration>
</plugin>
<!--
The twilio sample currently (2016-01-22) fails the Google Style
checks. We can uncomment this block when it is fixed.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
Expand All @@ -65,7 +62,6 @@
<execution><goals><goal>check</goal></goals></execution>
</executions>
</plugin>
-->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,21 @@ public class SendSmsServlet extends HttpServlet {
@Override
public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException,
ServletException {
final String TWILIO_ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
final String TWILIO_AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");
final String TWILIO_NUMBER = System.getenv("TWILIO_NUMBER");
final String TO_NUMBER = (String) req.getParameter("to");
if (TO_NUMBER == null) {
resp.getWriter().print("Please provide the number to message in the \"to\" query string"
+ " parameter.");
final String twilioAccountSid = System.getenv("TWILIO_ACCOUNT_SID");
final String twilioAuthToken = System.getenv("TWILIO_AUTH_TOKEN");
final String twilioNumber = System.getenv("TWILIO_NUMBER");
final String toNumber = (String) req.getParameter("to");
if (toNumber == null) {
resp.getWriter()
.print("Please provide the number to message in the \"to\" query string parameter.");
return;
}
TwilioRestClient client = new TwilioRestClient(TWILIO_ACCOUNT_SID,
TWILIO_AUTH_TOKEN);
TwilioRestClient client = new TwilioRestClient(twilioAccountSid, twilioAuthToken);
Account account = client.getAccount();
MessageFactory messageFactory = account.getMessageFactory();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("To", TO_NUMBER));
params.add(new BasicNameValuePair("From", TWILIO_NUMBER));
params.add(new BasicNameValuePair("To", toNumber));
params.add(new BasicNameValuePair("From", twilioNumber));
params.add(new BasicNameValuePair("Body", "Hello from Twilio!"));
try {
Message sms = messageFactory.create(params);
Expand Down

0 comments on commit 7ce1a32

Please sign in to comment.