Merge from trunk
[plcapi.git] / trunk / PLC / Methods / AddMessage.py
diff --git a/trunk/PLC/Methods/AddMessage.py b/trunk/PLC/Methods/AddMessage.py
new file mode 100644 (file)
index 0000000..62a2da7
--- /dev/null
@@ -0,0 +1,29 @@
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter
+from PLC.Messages import Message, Messages
+from PLC.Auth import Auth
+
+class AddMessage(Method):
+    """
+    Adds a new message template. Any values specified in
+    message_fields are used, otherwise defaults are used.
+
+    Returns 1 if successful, faults otherwise.
+    """
+
+    roles = ['admin']
+
+    accepts = [
+        Auth(),
+        Message.fields,
+        ]
+
+    returns = Parameter(int, '1 if successful')
+
+
+    def call(self, auth, message_fields):
+        message = Message(self.api, message_fields)
+        message.sync(insert = True)
+
+        return 1