Groovy for Domain-specific Languages - Second Edition
Example DSL – GeeTwitter [ 118 ] You will find full documentation for using Grape and the @Grab annotation at http://docs.groovy ...
Chapter 6 [ 119 ] Direct messages Twitter has a direct message feature that allows you to send messages directly to another Twit ...
Example DSL – GeeTwitter [ 120 ] Searching The Twitter APIs have a powerful search capability that allows us to search for what ...
Chapter 6 [ 121 ] Amid this cacophony of tweets, you might see comments from glaforge, the Groovy project manager. We might also ...
Example DSL – GeeTwitter [ 122 ] The Twitter4J APIs refer to the users you follow as friends and those following you as follower ...
Chapter 6 [ 123 ] } friendsList = { user -> TwitterFactory.singleton.getFriendsList(user,-1) } cachedFriendsList = friendsLis ...
Example DSL – GeeTwitter [ 124 ] We can write a neat auto-follow script. In the following example, we will use eachFollower to a ...
Chapter 6 [ 125 ] Or we can use the follow method to follow the tweets of any user who posts about the search terms that we are ...
Example DSL – GeeTwitter [ 126 ] Even the one useful line in the Java version is burdened with boilerplate. We have to explicitl ...
Chapter 6 [ 127 ] TwitterFactory.singleton.search(query).tweets.each { println it.text } } void search(terms, Closure c) { def q ...
Example DSL – GeeTwitter [ 128 ] To use this method, we can write the following script: GeeTwitter.search ("Groovy DSL") { from, ...
Chapter 6 [ 129 ] c.call(it.screenName) } } // Method to apply a closure to each follower static void eachFollower(Closure c) { ...
Example DSL – GeeTwitter [ 130 ] Improving search Earlier on, in this chapter, we searched for Tweets from Guillaume LaForge to ...
Chapter 6 [ 131 ] Adding a command-line interface One more step in making our DSL roadworthy is to add a command-line interface ...
Example DSL – GeeTwitter [ 132 ] We can now try out our DSL from the command line. To run a script to search for tweets about th ...
Chapter 6 [ 133 ] Instead of calling Script.evaluate() in the launch script, we can use the GroovyScript class to do the same th ...
Example DSL – GeeTwitter [ 134 ] import static twitter4j.TwitterFactory.* abstract class GeeTwitterScript extends Script { def s ...
Chapter 6 [ 135 ] } } void search(Map args, String terms = "") { def queryString = "" args.each { arg -> switch (arg.key.toSt ...
Example DSL – GeeTwitter [ 136 ] shell.evaluate (new File(args[0])) } else println "Usage: GTweet_2.1 <script>" With this ...
Chapter 6 [ 137 ] Summary We have now built our first fully-fledged, albeit simple, Groovy DSL. We've seen how we can start with ...
«
3
4
5
6
7
8
9
10
11
12
»
Free download pdf