Toggle navigation
scriptr
;
Blog
Help
Documentation
How-to
FAQ
Forum
Help
Documentation
How-to
FAQ
Forum
Register | Login
Benefits
Features
Services
Partners
Test it now
Write your own script
var http = require("http"); var ip = request.headers["x-forwarded-for"]; var iplookupUrl = "http://ip-api.com/json/" + ip; var response = http.request({url: iplookupUrl}); if(response.status == "200"){ var result = JSON.parse(response.body); var country = result.country; if(!storage.local[country]){ storage.local[country] = {count :1} }else{ storage.local[country].count += 1; } var message= "Thank you for tweeting from scriptr.io. There are now " + storage.local[country].count + " tweets from " + country +"."; var tweetResult = tweet(message); return "You've just tweeted [" + message + "] from scriptr.io, you can check it
here
." }else{ return "Ooops, we can't figure out your location!"; }
Test Script
This is where the script output will appear.
Click on one of the icons below to learn how to invoke the back-end script above from your favorite platform.
Raspberry Pi
Curl
Kinoma
Arduino
import httplib, urllib params = {} headers = {"Content-type":"application/x-www-form-urlencoded","authorization":"bearer UThEOTkwNkY5OQ=="} conn = httplib.HTTPSConnection("api.scriptrapps.io") conn.request("POST","/welcome",params, headers) response = conn.getresponse() print response.status print response.read()
curl -X POST -H 'Authorization: bearer UThEOTkwNkY5OQ==' 'https://api.scriptrapps.io/welcome'
<?xml version="1.0" encoding="utf-8"?> <program xmlns="http://www.kinoma.com/kpr/1"> <script> <![CDATA[ var url = "https://api.scriptrapps.io/welcome"; // Create completion callback using Kinoma container var container = new Container(); var containerBehavior = new Behavior(); containerBehavior.onComplete = function(container, message, data) { trace("Response " + data); }; container.behavior = containerBehavior; // Build Kinoma Message instance var message = new Message(url); message.method = "POST"; message.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); message.setRequestHeader("Content-Length", 0); message.setRequestHeader("Authorization", "bearer UThEOTkwNkY5OQ=="); container.invoke(message, Message.TEXT); ]]> </script> </program>
android
android
#define SCRIPTR_ENDPOINT "api.scriptrapps.io" #define SERVICE "scriptName" #define TOKEN "XXXXXXXXXXyyyy==" Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIVIDER); void loop(void) { Scriptr scriptr = Scriptr(SCRIPTR_ENDPOINT); String response = ""; scriptr.invoke(cc3000, SERVICE, TOKEN, &response); //pass in a configured cc3000 object\n\ Serial.println(response); delay(10000); } void setup(void) { Serial.begin(115200); cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY); cc3000.checkDHCP();//should happen in a loop } /*** This sample uses the adafruit cc3000 shield to connect to the internet ***/ /*** http://www.adafruit.com/product/1491 ***/
Click to add parameters
What's this?
Your Name
Consumer Key
Consumer Secret
Access Token
Access Token Secret
var http = require("http"); var iplookupUrl = "http://ip-api.com/json/" + request.headers["x-forwarded-for"]; var response = http.request({url: iplookupUrl}); if(response.status == "200"){ var result = JSON.parse(response.body); var country = result.country; var message = "Hello " + request.parameters["name"] + ", thank you for trying scriptr.io from " + country + "."; var tweetResult= tweet(request.parameters["consumerKey"], request.parameters["consumerSecret"],request.parameters["accessToken"], request.parameters["accessTokenSecret"], message); if(tweetResult.id_str){ return "You've just tweeted [" + message + "] from scriptr.io."; }else{ return tweetResult; } }else{ return "Ooops, we can't figure out your location!"; }
Test Script
This is where the script output will appear.
By using the script editor you agree to scriptr.io's
terms of use
Let us know who you are and we will update you on scriptr.io news.
No Spam, Just scriptr.io updates
We are currently unable to send your message. Please try again later or send us an email at
[email protected]
.
Your email address*
Leave us a message
Cancel
Send
Sending...
Message Sent
Subscribe for updates