<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to UpdateScript</title><link>https://sourceforge.net/p/m2mlabs/wiki/UpdateScript/</link><description>Recent changes to UpdateScript</description><atom:link href="https://sourceforge.net/p/m2mlabs/wiki/UpdateScript/feed" rel="self"/><language>en</language><lastBuildDate>Sun, 23 Sep 2012 13:17:37 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/m2mlabs/wiki/UpdateScript/feed" rel="self" type="application/rss+xml"/><item><title>WikiPage UpdateScript modified by Jim</title><link>https://sourceforge.net/p/m2mlabs/wiki/UpdateScript/</link><description>&lt;pre&gt;--- v1
+++ v2
@@ -53,7 +53,9 @@
 
 Errors:
 
-* 401 NOT FOUND if script does not exist
+* 401 UNAUTHORIZED if key is invalid or not admin key
+* 404 NOT FOUND if script does not exist
+* 406 NOT ACCEPTABLE if the script can not be compiled
 
 Example
 
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jim</dc:creator><pubDate>Sun, 23 Sep 2012 13:17:37 -0000</pubDate><guid>https://sourceforge.neta7106cadd1fe2b21397f10efca7be69a445659cd</guid></item><item><title>WikiPage UpdateScript modified by Jim</title><link>https://sourceforge.net/p/m2mlabs/wiki/UpdateScript/</link><description>### Update an existing Script ###

Updates an existing script in the domain of the owner identified by the apikey.

There are two kinds of scripts:

* scripts implementing IScriptRunner are called when ever sensor data is received. They must be assigned to a device model in order to be executed. They are used to implement application specific sensor data processing like data validation, interpolation, threshold checks or triggers.

~~~~~~
    public interface IScriptRunner {
    
       public void run(String apikey, 
                       String deviceName, 
                       SensorData sensor) throws ScriptException;
    
    }
 
~~~~~~

* scripts implementing IHttpConnectorScript are assigned to the HttpConnector and are executed automatically when ever the HttpConnector receives sensor data. They are used to transform the received sensor data to the standard Moments representation

~~~~~~
    public interface IHttpConnectorScript {
    
        public String getDevice (HttpServletRequest request) throws ScriptException;
    
        public List&lt;SensorData&gt; getSensorData 
                                    (String apikey, 
                                     String deviceModel,
                                     DeviceModelManager deviceModelManager,
                                     SensorModelManager sensorModelManager,           
                                     HttpServletRequest request) 
                                throws ScriptException;
        }
    }
~~~~~~

Path: cs-ws/resources/admin/script        Method: PUT

Parameters

* apikey

Data

~~~~~~
&lt;script&gt;
   &lt;code&gt;...&lt;/code&gt;
   &lt;name&gt;...&lt;/name&gt;
   &lt;version&gt;...&lt;/version&gt;
&lt;/script&gt;
~~~~~~

Errors:

* 401 NOT FOUND if script does not exist

Example

~~~~~~
PUT http://localhost/cs-ws/resources/admin/script/?apikey=1234 HTTP/1.1
&lt;script&gt;
   &lt;code&gt;import com.m2mlabs.cs.manager.IScriptRunner;
       import com.m2mlabs.cs.model.SensorData;
       class MyGreeter implements IScriptRunner {
          public void run(String apikey, String deviceName, SensorData sensor) throws       
              ScriptException {println (deviceName) ;
          }
       }
   &lt;/code&gt;
   &lt;name&gt;TestScript3&lt;/name&gt;
   &lt;version&gt;1&lt;/version&gt;
&lt;/script&gt;

HTTP/1.1 200 OK
~~~~~~
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jim</dc:creator><pubDate>Sun, 23 Sep 2012 13:13:48 -0000</pubDate><guid>https://sourceforge.net83cc98514cb978713abb8b1c69be38e0c1720db1</guid></item></channel></rss>