Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added new append method to TropoBuilder which allows to create more

complex builders by appending existing builder objects.

This closes #2
  • Loading branch information...
commit 07bb7660f73d3fd8aeae1a18cd35ce4c5e265b79 1 parent 45e0445
mpermar mpermar authored
2  TropoWebapiGrailsGrailsPlugin.groovy
View
@@ -1,6 +1,6 @@
class TropoWebapiGrailsGrailsPlugin {
// the plugin version
- def version = "0.1.1"
+ def version = "0.1.2"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "1.3.6 > *"
// the other plugins this plugin depends on
5 src/groovy/com/tropo/grails/TropoBuilder.groovy
View
@@ -303,6 +303,11 @@ class TropoBuilder extends BuilderSupport {
def map = ["value":value]
createNode(name,map)
}
+ } else if (name == "append") {
+ JSONObject tropo = value.root['tropo']
+ tropo.entrySet().each {
+ createNode(it.key, it.value)
+ }
}
return null;
}
36 test/unit/com/tropo/grails/TropoBuilderTests.groovy
View
@@ -685,4 +685,40 @@ class TropoBuilderTests extends GroovyTestCase {
map = new TropoBuilder().parse(map)
assert map.session.userType == 'HUMAN'
}
+
+
+ public void testAppendTropo() {
+
+ def builder1 = new TropoBuilder()
+ builder1.tropo {
+ say('Please say your account number')
+ }
+
+ def builder2 = new TropoBuilder()
+ builder2.tropo {
+ ask(name : 'foo', bargein: true, timeout: 30, required: true, choices: '[5 DIGITS]') {
+ append(builder1)
+ }
+ }
+
+ assert builder2.text() == "{\"tropo\":[{\"ask\":{\"name\":\"foo\",\"bargein\":true,\"timeout\":30,\"required\":true,\"choices\":[\"5 DIGITS\"],\"say\":[{\"value\":\"Please say your account number\"}]}}]}"
+ }
+
+ public void testAppendOnBlock() {
+
+ def builder1 = new TropoBuilder()
+ builder1.tropo {
+ on(event:'success',next:'/result.json')
+ }
+
+ def builder2 = new TropoBuilder()
+ builder2.tropo {
+ ask(name : 'foo', bargein: true, timeout: 30, required: true) {
+ say('Please say your account number')
+ choices(value: '[5 DIGITS]')
+ }
+ append(builder1)
+ }
+ assert builder2.text() == "{\"tropo\":[{\"ask\":{\"name\":\"foo\",\"bargein\":true,\"timeout\":30,\"required\":true,\"say\":[{\"value\":\"Please say your account number\"}],\"choices\":{\"value\":\"[5 DIGITS]\"}}},{\"on\":{\"event\":\"success\",\"next\":\"/result.json\"}}]}"
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.