Groovy for Domain-specific Languages - Second Edition

(nextflipdebug2) #1
[ 113 ]

Example DSL – GeeTwitter


Before we dive any deeper into Groovy's more advanced features, let's take
some time out to build a simple Groovy DSL, using some of the knowledge that
we acquired in the previous chapters. In this chapter, we will use closures to
build a simple and useful DSL that allows us to automate simple scripts that
interact with Twitter.


We will take a stepwise approach to building our DSL. Starting with some vanilla
Java APIs that require Groovy or Java programming skills, we will progressively
apply some cool Groovy features to evolve a simple DSL that anybody can use.


Twitter


Since the first version of this book was released in 2010, Twitter has become an
ubiquitous part of the social media landscape. So ubiquitous in fact, that the Oxford
English Dictionary now recognizes words such as Tweet, Twitter, and Twitterati,
with their own descriptions. Broadsheets, tabloids, and TV news channels now
report what is trending on Twitter as news items in themselves.


Twitter has been variously described as a micro-blogging or social networking
service. Twitter is a synergy between instant messaging, SMS, e-mail, and the Web,
and allows users to make comments—"tweets"—and have them instantly sent to
multiple recipients—"followers".


Using Twitter is the essence of simplicity. Once you have set up an account, you can
log onto the service and set a status message. Status messages are text messages of
up to 140 characters in length. Twitter keeps a log of your status messages so that
you or any other Twitter user can view them. If you follow another user or they
follow you, then you will see their status messages in your updates page, and they
will see yours.

Free download pdf