Permalink
Browse files

added group sms api

  • Loading branch information...
chrismatthieu committed Jul 23, 2011
1 parent f94ca2e commit 222a3cb2ea744838dbfc710a4a1fce5c7cd6d3f7
@@ -0,0 +1,22 @@
+class ApiController < ApplicationController
+
+ def smsnumbers
+ @did = ""
+
+ @numbers = Voicememo.find(:all, :select => "DISTINCT(callerid)")
+
+ @numbers.each do |number|
+ if isNumeric(number.callerid)
+ @did << number.callerid + ","
+ end
+ end
+
+ @did = @did.chop #remove last comma from @did string
+
+ respond_to do |format|
+ format.xml {}
+ format.json {}
+ end
+ end
+
+end
@@ -1,3 +1,6 @@
class ApplicationController < ActionController::Base
# protect_from_forgery
+ def isNumeric(s)
+ Float(s) != nil rescue false
+ end
end
@@ -0,0 +1,2 @@
+module ApiHelper
+end
@@ -0,0 +1,4 @@
+{"user":{
+ "phones":"<%=@did %>"
+ }
+}
@@ -10,7 +10,8 @@
<meta charset='utf-8'>
<meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1.0' name='viewport'>
-<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js' type='text/javascript'></script>
+<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
+<!-- <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js' type='text/javascript'></script> -->
<script src='/fullScreenMusic/soundmanager/script/soundmanager2.js' type='text/javascript'></script>
<script src='/fullScreenMusic/ttwFullScreenMusic.js' type='text/javascript'></script>
<link href='/fullScreenMusic/css/style.css' rel='stylesheet' type='text/css'>
@@ -26,6 +27,7 @@
soundManager.debugMode = false;
soundManager.autoPlay = true;
soundManager.autoAdvance = true;
+ // soundManager.showPlaylist = true;
soundManager.onload = function() {
// $('.playlist').ttwFullScreenMusic({style:'page-list'});
@@ -35,7 +37,6 @@
</script>
<link type="text/css" rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/themes/ui-blitzer/jquery-ui.css"/>
-<!-- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> -->
<script type="text/javascript" src="http://s.phono.com/releases/0.2/jquery.phono.js"></script>
<script type="text/javascript" src="http://s.phono.com/addons/callme/79a53b7/jquery.callme.js"></script>
View
@@ -5,6 +5,8 @@
match '/uploadfile' => 'upload#uploadFile'
match '/upload' => 'upload#index'
match '/stream/:id' => 'upload#stream'
+
+ match '/api/smsnumbers.:format' => 'api#smsnumbers'
# The priority is based upon order of creation:
# first created -> highest priority.
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class ApiControllerTest < ActionController::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class ApiHelperTest < ActionView::TestCase
+end
View
@@ -0,0 +1,27 @@
+#----------
+# Group sms
+#----------
+require 'open-uri'
+require 'json'
+
+url = 'http://voiceboard.heroku.com/api/smsnumbers.json'
+mymessage = $currentCall.initialText
+
+#JSON data to a Ruby hash
+data = JSON.parse(open(url).read)
+
+#Get the relevant data
+phones = data["user"]["phones"]
+
+#start the blasting
+numbers = phones.split(",")
+numbers.each do |number|
+
+ message(mymessage, {
+ :to => number,
+ :network => "SMS",
+ :callerID => $currentCall.calledID.to_s
+})
+ end
+
+

0 comments on commit 222a3cb

Please sign in to comment.