Browse files

Added location object usage to example plugin

  • Loading branch information...
1 parent b918855 commit 924bad3d4d665589f102a6651a8d5b85d79e6f9b @chendo chendo committed Dec 15, 2011
Showing with 24 additions and 20 deletions.
  1. +24 −20 plugins/siriproxy-example/lib/siriproxy-example.rb
View
44 plugins/siriproxy-example/lib/siriproxy-example.rb
@@ -4,9 +4,9 @@
#######
# This is a "hello world" style plugin. It simply intercepts the phrase "test siri proxy" and responds
-# with a message about the proxy being up and running (along with a couple other core features). This
+# with a message about the proxy being up and running (along with a couple other core features). This
# is good base code for other plugins.
-#
+#
# Remember to add other plugins to the "config.yml" file if you create them!
######
@@ -19,60 +19,64 @@ def initialize(config)
#filters are still in their early stages. Their interface may be modified
filter "SetRequestOrigin", direction: :from_iphone do |object|
puts "[Info - User Location] lat: #{object["properties"]["latitude"]}, long: #{object["properties"]["longitude"]}"
-
+
#Note about returns from filters:
# - Return false to stop the object from being forwarded
# - Return a Hash to substitute or update the object
- # - Return nil (or anything not a Hash or false) to have the object forwarded (along with any
+ # - Return nil (or anything not a Hash or false) to have the object forwarded (along with any
# modifications made to it)
- end
+ end
+
+ listen_for /where am i/i do
+ say "Your location is: #{location.address}"
+ end
listen_for /test siri proxy/i do
say "Siri Proxy is up and running!" #say something to the user!
-
+
request_completed #always complete your request! Otherwise the phone will "spin" at the user!
end
-
+
#Demonstrate that you can have Siri say one thing and write another"!
listen_for /you don't say/i do
say "Sometimes I don't write what I say", spoken: "Sometimes I don't say what I write"
- end
+ end
#demonstrate state change
listen_for /siri proxy test state/i do
set_state :some_state #set a state... this is useful when you want to change how you respond after certain conditions are met!
say "I set the state, try saying 'confirm state change'"
-
+
request_completed #always complete your request! Otherwise the phone will "spin" at the user!
end
-
+
listen_for /confirm state change/i, within_state: :some_state do #this only gets processed if you're within the :some_state state!
say "State change works fine!"
set_state nil #clear out the state!
-
+
request_completed #always complete your request! Otherwise the phone will "spin" at the user!
end
-
+
#demonstrate asking a question
listen_for /siri proxy test question/i do
response = ask "Is this thing working?" #ask the user for something
-
+
if(response =~ /yes/i) #process their response
- say "Great!"
+ say "Great!"
else
say "You could have just said 'yes'!"
end
-
+
request_completed #always complete your request! Otherwise the phone will "spin" at the user!
end
-
+
#demonstrate capturing data from the user (e.x. "Siri proxy number 15")
listen_for /siri proxy number ([0-9,]*[0-9])/i do |number|
say "Detected number: #{number}"
-
+
request_completed #always complete your request! Otherwise the phone will "spin" at the user!
end
-
+
#demonstrate injection of more complex objects without shortcut methods.
listen_for /test map/i do
add_views = SiriAddViews.new
@@ -82,10 +86,10 @@ def initialize(config)
utterance = SiriAssistantUtteranceView.new("Testing map injection!")
add_views.views << utterance
add_views.views << map_snippet
-
+
#you can also do "send_object object, target: :guzzoni" in order to send an object to guzzoni
send_object add_views #send_object takes a hash or a SiriObject object
-
+
request_completed #always complete your request! Otherwise the phone will "spin" at the user!
end
end

0 comments on commit 924bad3

Please sign in to comment.