Permalink
Please sign in to comment.
Showing
with
75 additions
and 2 deletions.
- +22 −0 app/controllers/api_controller.rb
- +3 −0 app/controllers/application_controller.rb
- +2 −0 app/helpers/api_helper.rb
- +4 −0 app/views/api/smsnumbers.json
- +3 −2 app/views/layouts/application.html.erb
- +2 −0 config/routes.rb
- +8 −0 test/functional/api_controller_test.rb
- +4 −0 test/unit/helpers/api_helper_test.rb
- +27 −0 tropo_sms.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 |
@@ -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 %>" | ||
+ } | ||
+} |
@@ -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 |
27
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