2 * Web Services Tutorial
4 * Copyright 2015 SmartThings
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 * in compliance with the License. You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
12 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
13 * for the specific language governing permissions and limitations under the License.
17 name: "Web Services Tutorial",
18 namespace: "smartthings",
19 author: "SmartThings",
20 description: "web services tutorial",
22 iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
23 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
24 iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
25 oauth: [displayName: "web services tutorial ", displayLink: "http://localhost:4567"])
29 section ("Allow external service to control these things...") {
30 input "switches", "capability.switch", multiple: true, required: true
40 path("/switches/:command") {
47 // returns a list like
48 // [[name: "kitchen lamp", value: "off"], [name: "bathroom", value: "on"]]
53 resp << [name: it.displayName, value: it.currentValue("switch")]
58 void updateSwitches() {
59 // use the built-in request object to get the command parameter
60 def command = params.command
62 // all switches have the comand
63 // execute the command on all switches
64 // (note we can do this on the array - the command will be invoked on every element
73 httpError(400, "$command is not a valid command for all switches specified")