Skip to content

Commit

Permalink
added group sms api
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismatthieu committed Jul 23, 2011
1 parent f94ca2e commit 222a3cb
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 2 deletions.
22 changes: 22 additions & 0 deletions app/controllers/api_controller.rb
@@ -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
3 changes: 3 additions & 0 deletions app/controllers/application_controller.rb
@@ -1,3 +1,6 @@
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
# protect_from_forgery # protect_from_forgery
def isNumeric(s)
Float(s) != nil rescue false
end
end end
2 changes: 2 additions & 0 deletions app/helpers/api_helper.rb
@@ -0,0 +1,2 @@
module ApiHelper
end
4 changes: 4 additions & 0 deletions app/views/api/smsnumbers.json
@@ -0,0 +1,4 @@
{"user":{
"phones":"<%=@did %>"
}
}
5 changes: 3 additions & 2 deletions app/views/layouts/application.html.erb
Expand Up @@ -10,7 +10,8 @@
<meta charset='utf-8'> <meta charset='utf-8'>
<meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible'> <meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1.0' name='viewport'> <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/soundmanager/script/soundmanager2.js' type='text/javascript'></script>
<script src='/fullScreenMusic/ttwFullScreenMusic.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'> <link href='/fullScreenMusic/css/style.css' rel='stylesheet' type='text/css'>
Expand All @@ -26,6 +27,7 @@
soundManager.debugMode = false; soundManager.debugMode = false;
soundManager.autoPlay = true; soundManager.autoPlay = true;
soundManager.autoAdvance = true; soundManager.autoAdvance = true;
// soundManager.showPlaylist = true;


soundManager.onload = function() { soundManager.onload = function() {
// $('.playlist').ttwFullScreenMusic({style:'page-list'}); // $('.playlist').ttwFullScreenMusic({style:'page-list'});
Expand All @@ -35,7 +37,6 @@
</script> </script>


<link type="text/css" rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/themes/ui-blitzer/jquery-ui.css"/> <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/releases/0.2/jquery.phono.js"></script>
<script type="text/javascript" src="http://s.phono.com/addons/callme/79a53b7/jquery.callme.js"></script> <script type="text/javascript" src="http://s.phono.com/addons/callme/79a53b7/jquery.callme.js"></script>


Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Expand Up @@ -5,6 +5,8 @@
match '/uploadfile' => 'upload#uploadFile' match '/uploadfile' => 'upload#uploadFile'
match '/upload' => 'upload#index' match '/upload' => 'upload#index'
match '/stream/:id' => 'upload#stream' match '/stream/:id' => 'upload#stream'

match '/api/smsnumbers.:format' => 'api#smsnumbers'


# The priority is based upon order of creation: # The priority is based upon order of creation:
# first created -> highest priority. # first created -> highest priority.
Expand Down
8 changes: 8 additions & 0 deletions test/functional/api_controller_test.rb
@@ -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
4 changes: 4 additions & 0 deletions test/unit/helpers/api_helper_test.rb
@@ -0,0 +1,4 @@
require 'test_helper'

class ApiHelperTest < ActionView::TestCase
end
27 changes: 27 additions & 0 deletions tropo_sms.rb
@@ -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.