Last active
June 1, 2016 21:48
-
-
Save xmlking/dcf0f554f25ea42e2021c130982adf3d to your computer and use it in GitHub Desktop.
Example script for Apache NiFi's ExecuteScript Processor using @grab Ref: http://funnifi.blogspot.com/2016/05/using-groovy-grab-with-executescript.html . Set dynamic properties for ExecuteScript with your twitter consumerKey, consumerSecret accessToken and secretToken
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab('org.codehaus.groovy.modules.http-builder:http-builder:0.7') | |
@Grab('oauth.signpost:signpost-core:1.2.1.2') | |
@Grab('oauth.signpost:signpost-commonshttp4:1.2.1.2') | |
import groovy.json.JsonOutput | |
import groovyx.net.http.RESTClient | |
import static groovyx.net.http.ContentType.* | |
import org.apache.http.params.HttpConnectionParams | |
import com.crossbusiness.nifi.processors.NiFiUtils as util | |
//Access dynamic property | |
consumerKey = consumerKey.value | |
consumerSecret = consumerSecret.value | |
accessToken = accessToken.value | |
secretToken = secretToken.value | |
def twitter = new RESTClient( 'https://api.twitter.com/1.1/statuses/' ) | |
twitter.auth.oauth consumerKey, consumerSecret, accessToken, secretToken | |
twitter.contentType = JSON | |
HttpConnectionParams.setSoTimeout twitter.client.params, 15000 | |
def resp = twitter.get( path: 'home_timeline.json' ) | |
assert resp.status == 200 | |
assert resp.contentType == JSON.toString() | |
assert ( resp.data instanceof List ) | |
assert resp.data.status.size() > 0 | |
flowFile = util.stringToFlowFile(JsonOutput.toJson(resp.data), session); | |
session.transfer(flowFile, REL_SUCCESS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment