cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Groovy Script: Send a Tweet with Location

No ratings

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"

 
Version history
Last update:
‎May 26, 2016 05:52 PM
Updated by:
Labels (2)