Groovy Script: Send a Tweet with Location

    This Groovy script is called from an Expression Rule of type Location. For example, in an Expression rule

     

    ExecuteCustomObject("SendTweetWithLocation","user","password","Asset is on the move")

     

    calls the script "SendTweetWithLocation" with the parameters in order. The twitterStatus is the text to send to twitter. Use the user/password for an actual twitter account.  Also, the script uses the implicit objects context and mobileLocation.


    Parameters

     

    Variable Name      Display Name
    twitterUser                twitterUser
    twitterPassword      twitterPassword
    twitterStatus            twitterStatus



    import groovyx.net.http.RESTClient
    import static groovyx.net.http.ContentType.*
    import com.axeda.drm.sdk.geofence.Geofence
    
    twitter = new RESTClient('http://twitter.com/statuses/')
    twitter.auth.basic parameters.twitterUser, parameters.twitterPassword
    twitter.client.params.setBooleanParameter 'http.protocol.expect-continue', false
    
    def statusText = "'${parameters.twitterStatus}' for device: ${context.device.serialNumber} on ${new Date()}"
    
    resp = twitter.post(path: 'update.xml',
            requestContentType: URLENC,
            body: [status: statusText, lat: mobileLocation.lat, long: mobileLocation.lng])
    
    logger.info resp.status
    logger.info "Posted update $statusText"