Skip to content
Browse files

Added system configs MVC plus restricted OV to one profile

  • Loading branch information...
1 parent 08e2198 commit 6d29741a5ed09d70c9a90eb1b67dc07eaffb6f42 Topher committed May 11, 2010
View
5 README.textile
@@ -50,7 +50,6 @@ mislav-will_paginate
To start working with GAE directly, you can pull this code down to your system from https://github.com/chrismatthieu/OpenVoice.
-Update OUTBOUND_VOICE_TEMP and OUTBOUND_MESSAGING_TEMP Tropo token keys located in config/environment.rb
-Update SERVER_URL in config/environments/development.rb and production.rb
-
If all goes well, you can run ./script/server.sh to run it local on your system and ./script/publish.sh to publish your update to GAE!
+
+Once your application is running and you log in for the first time to create your profile account, click on the System Configuration link on your Profile page and enter your Voice and SMS Tokens from your Tropo account as well as the domain portion of URL where you will be running your instance of the application. For instance, server URL is "http://myopenvoice.appspot.com".
View
2 WEB-INF/appengine-generated/datastore-indexes-auto.xml
@@ -1,4 +1,4 @@
-<!-- Indices written at Tue, 11 May 2010 00:05:28 UTC -->
+<!-- Indices written at Wed, 12 May 2010 00:39:06 UTC -->
<datastore-indexes/>
View
BIN WEB-INF/appengine-generated/local_db.bin
Binary file not shown.
View
7 app/controllers/communications_controller.rb
@@ -91,14 +91,17 @@ def answer
render :json => tropo.response
when 'voicemail'
+
+ sys_config = SysConfig.first
+
tropo = Tropo::Generator.new do
record( :say => [:value => 'please speak after the beep to leave a voicemail'],
:beep => true,
:maxTime => 30,
:format => "audio/mp3",
:name => "voicemail",
- :url => SERVER_URL + "/voicemails/create?caller_id=#{caller_id}&user_id=#{user_id}")#,
-# :transcriptionOutURI => SERVER_URL + "/voicemails/set_transcription&voicemail_id=1",
+ :url => sys_config.server_url + "/voicemails/create?caller_id=#{caller_id}&user_id=#{user_id}")#,
+# :transcriptionOutURI => sys_config.server_url + "/voicemails/set_transcription&voicemail_id=1",
# :transcriptionID => '1234' )
end
render :json => tropo.response
View
12 app/controllers/incoming_call_controller.rb
@@ -30,14 +30,16 @@ def index
# return redirect_to "/incoming_call/start_transfer?user_id=#{user.id}&caller_id=#{caller_id}"
#end
+ sys_config = SysConfig.first
+
tropo = Tropo::Generator.new do
on(:event => 'hangup', :next => "hangup")
on(:event => 'incomplete', :next => "hangup")
on(:event => 'continue', :next => "/incoming_call/start_transfer?user_id=#{user.id}&caller_id=#{caller_id}")
record( :attempts => 2,
:beep => true,
:name => 'record-name',
- :url => "#{SERVER_URL}/incoming_call/store_contact_recording?user_id=#{user.id}&caller_id=#{caller_id}",
+ :url => "#{sys_config.server_url}/incoming_call/store_contact_recording?user_id=#{user.id}&caller_id=#{caller_id}",
:format => "audio/mp3",
:choices => "#",
:say => { :value => "Before being connected please record your name" })
@@ -106,8 +108,10 @@ def start_transfer
caller_id = params[:caller_id]
user_id = params[:user_id]
+
+ sys_config = SysConfig.first
- # call_url = "http://api.tropo.com/1.0/sessions?action=create&token=#{OUTBOUND_VOICE_TEMP}&caller_id=#{params[:caller_id]}&user_id=#{params[:user_id]}&dialog=user_menu"
+ # call_url = "http://api.tropo.com/1.0/sessions?action=create&token=#{sys_config.voice.token}&caller_id=#{params[:caller_id]}&user_id=#{params[:user_id]}&dialog=user_menu"
#
# begin
# AppEngine::URLFetch.fetch(call_url, :method => :get, :deadline => 10)
@@ -131,9 +135,11 @@ def token
#user = User.get(user_id)
+ sys_config = SysConfig.first
+
tropo = Tropo::Generator.new do
call( :to => "sip:bling@192.168.11.7")
- say("Incoming call from #{SERVER_URL}/incoming_call/get_contact_recording?caller_id=#{caller_id}&amp;user_id=#{user_id}")
+ say("Incoming call from #{sys_config.server_url}/incoming_call/get_contact_recording?caller_id=#{caller_id}&amp;user_id=#{user_id}")
conference(:name => "conference", :id => user_id + "<--->" + caller_id)
end
View
4 app/controllers/messagings_controller.rb
@@ -154,7 +154,9 @@ def create
if outgoing
- msg_url = 'http://api.tropo.com/1.0/sessions?action=create&token=' + OUTBOUND_MESSAGING_TEMP + '&from='+ from + '&to=' + to + '&text=' + CGI::escape(text)
+ sys_config = SysConfig.first
+
+ msg_url = 'http://api.tropo.com/1.0/sessions?action=create&token=' + sys_config.sms_token + '&from='+ from + '&to=' + to + '&text=' + CGI::escape(text)
result = AppEngine::URLFetch.fetch(msg_url,
:method => :get,
View
81 app/controllers/profiles_controller.rb
@@ -4,57 +4,74 @@ class ProfilesController < ApplicationController
def index
+ usercount = 0
+
# Execute at Login - TODO: Move to method
current_user = AppEngine::Users.current_user
if current_user
user = User.find_by_email(current_user.email)
if user
- user.attributes = {
- :email => current_user.email,
- :nickname => current_user.nickname,
- :updated_at => Time.now()
- }
- user.save
+ # user.attributes = {
+ # :email => current_user.email,
+ # :nickname => current_user.nickname,
+ # :updated_at => Time.now()
+ # }
+ # user.save
session[:current_user_id] = user.id
+ usercount = 1
else
- # Generate API Key
- require 'sha1'
- srand
- seed = "--#{rand(10000)}--#{Time.now}--"
- apikey = Digest::SHA1.hexdigest(seed)
+ usercount = User.all
- user = User.new
- user.attributes = {
- :email => current_user.email,
- :nickname => current_user.nickname,
- :apikey => apikey,
- :created_at => Time.now()
- }
- user.save
- session[:current_user_id] = user.id
+ if usercount.length == 0
+
+ # Generate API Key
+ require 'sha1'
+ srand
+ seed = "--#{rand(10000)}--#{Time.now}--"
+ apikey = Digest::SHA1.hexdigest(seed)
+
+ user = User.new
+ user.attributes = {
+ :email => current_user.email,
+ :nickname => current_user.nickname,
+ :apikey => apikey,
+ :created_at => Time.now()
+ }
+ user.save
+ session[:current_user_id] = user.id
+ usercount = 1
+
+ end
+
end
- session[:nickname] = current_user.nickname
- session[:email] = current_user.email
- session[:apikey] = user.apikey
end
+ if usercount == 1
+ session[:nickname] = current_user.nickname
+ session[:email] = current_user.email
+ session[:apikey] = user.apikey
+
+ # @profiles = Profile.all
+ @profiles = Profile.first(:user_id => session[:current_user_id])
+ @call_screening = @profiles.call_screening rescue false
- # @profiles = Profile.all
- @profiles = Profile.first(:user_id => session[:current_user_id])
- @call_screening = @profiles.call_screening
+ if !@profiles
+ redirect_to('/profiles/new')
+ else
+ respond_to do |format|
+ format.html
+ format.xml { render :xml => @profiles }
+ end
+ end
- if !@profiles
- redirect_to('/profiles/new')
else
- respond_to do |format|
- format.html
- format.xml { render :xml => @profiles }
- end
+ logout_url = AppEngine::Users.create_logout_url('/logout')
+ redirect_to(logout_url)
end
end
View
89 app/controllers/sys_configs_controller.rb
@@ -0,0 +1,89 @@
+class SysConfigsController < ApplicationController
+ # GET /sys_configs
+ # GET /sys_configs.xml
+ def index
+ @sys_configs = SysConfig.all
+
+ if @sys_configs.length > 0
+ respond_to do |format|
+ format.html # index.html.erb
+ format.xml { render :xml => @sys_configs }
+ end
+ else
+ redirect_to :action=> 'new'
+ end
+ end
+
+ # GET /sys_configs/1
+ # GET /sys_configs/1.xml
+ def show
+ @sys_config = SysConfig.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.xml { render :xml => @sys_config }
+ end
+ end
+
+ # GET /sys_configs/new
+ # GET /sys_configs/new.xml
+ def new
+ @sys_config = SysConfig.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.xml { render :xml => @sys_config }
+ end
+ end
+
+ # GET /sys_configs/1/edit
+ def edit
+ @sys_config = SysConfig.find(params[:id])
+ end
+
+ # POST /sys_configs
+ # POST /sys_configs.xml
+ def create
+ @sys_config = SysConfig.new(params[:sys_config])
+
+ respond_to do |format|
+ if @sys_config.save
+ flash[:notice] = 'SysConfig was successfully created.'
+ format.html { redirect_to(sys_configs_path) }
+ format.xml { render :xml => @sys_config, :status => :created, :location => @sys_config }
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @sys_config.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /sys_configs/1
+ # PUT /sys_configs/1.xml
+ def update
+ @sys_config = SysConfig.find(params[:id])
+
+ respond_to do |format|
+ if @sys_config.update_attributes(params[:sys_config])
+ flash[:notice] = 'SysConfig was successfully updated.'
+ format.html { redirect_to(@sys_config) }
+ format.xml { head :ok }
+ else
+ format.html { render :action => "edit" }
+ format.xml { render :xml => @sys_config.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /sys_configs/1
+ # DELETE /sys_configs/1.xml
+ def destroy
+ @sys_config = SysConfig.find(params[:id])
+ @sys_config.destroy
+
+ respond_to do |format|
+ format.html { redirect_to(sys_configs_url) }
+ format.xml { head :ok }
+ end
+ end
+end
View
4 app/controllers/voice_calls_controller.rb
@@ -108,8 +108,10 @@ def create
# firstnumber = '+14152739939'
firstnumber = '14152739939'
end
+
+ sys_config = SysConfig.first
- call_url = 'http://api.tropo.com/1.0/sessions?action=create&token=' + OUTBOUND_VOICE_TEMP + '&to=' + callto + '&from=' + firstnumber + '&ov_action=call&user_id=' + current_user.to_s
+ call_url = 'http://api.tropo.com/1.0/sessions?action=create&token=' + sys_config.voice_token + '&to=' + callto + '&from=' + firstnumber + '&ov_action=call&user_id=' + current_user.to_s
result = AppEngine::URLFetch.fetch(call_url,
:method => :get,
View
2 app/helpers/sys_configs_helper.rb
@@ -0,0 +1,2 @@
+module SysConfigsHelper
+end
View
15 app/models/sys_config.rb
@@ -0,0 +1,15 @@
+class SysConfig
+ include DataMapper::Resource
+
+ property :id, Serial
+ property :voice_token, Text
+ property :sms_token, Text
+ property :server_url, Text
+ property :created_at, DateTime
+ property :updated_at, DateTime
+
+ validates_present :voice_token
+ validates_present :sms_token
+ validates_present :server_url
+
+end
View
2 app/views/profiles/index.html.erb
@@ -50,6 +50,8 @@ Screen your calls?
<%= observe_field 'call_screening', :url => { :action => "update_checkbox" }, :with => 'call_screening' %>
<p><a href="http://gmail.com">Gmail</a></p>
+<hr/>
+<p><%= link_to 'System Configuration', sys_configs_path %></p>
</td><td style="border:0px solid #FFFFFF;border-left:0px solid #FFFFFF;border-right:0px solid #FFFFFF;">
View
25 app/views/sys_configs/edit.html.erb
@@ -0,0 +1,25 @@
+<h1>Editing System Configuration</h1>
+
+<% form_for(@sys_config) do |f| %>
+ <%= f.error_messages %>
+
+ <p>
+ <%= f.label :voice_token %><br />
+ <%= f.text_field :voice_token %>
+ </p>
+ <p>
+ <%= f.label :sms_token %><br />
+ <%= f.text_field :sms_token %>
+ </p>
+ <p>
+ <%= f.label :server_url %><br />
+ <%= f.text_field :server_url %>
+ </p>
+ <p>
+ <%= f.submit 'Update' %>
+ </p>
+<% end %>
+
+
+<%# link_to 'Show', @sys_config %>
+<%= link_to 'Back', sys_configs_path %>
View
14 app/views/sys_configs/index.html.erb
@@ -0,0 +1,14 @@
+<h1>System Configuration</h1>
+
+
+<% @sys_configs.each do |sys_config| %>
+<p>Tropo Voice Token: <%= sys_config.voice_token %></p>
+<p>Tropo SMS Token: <%= sys_config.sms_token %></p>
+<p>OpenVoice Server URL: <%= sys_config.server_url %></p>
+<p><%= link_to 'Edit', edit_sys_config_path(sys_config) %> | <%= link_to 'Back', profiles_path %></p>
+<%# link_to 'Delete', sys_config_path(sys_config), :confirm => 'Are you sure?', :method => :delete %>
+<% end %>
+
+<br />
+
+<%# link_to 'New sys_config', new_sys_config_path %>
View
25 app/views/sys_configs/new.html.erb
@@ -0,0 +1,25 @@
+<h1>New System Configuration</h1>
+
+<% form_for(@sys_config) do |f| %>
+ <%= f.error_messages %>
+
+ <p>
+ <%= f.label :voice_token %><br />
+ <%= f.text_field :voice_token %>
+ </p>
+ <p>
+ <%= f.label :sms_token %><br />
+ <%= f.text_field :sms_token %>
+ </p>
+ <p>
+ <%= f.label :server_url %><br />
+ <%= f.text_field :server_url %>
+ </p>
+ <p>
+ <%= f.submit 'Create' %>
+ </p>
+<% end %>
+
+
+
+<%# link_to 'Back', sys_configs_path %>
View
3 app/views/sys_configs/show.html.erb
@@ -0,0 +1,3 @@
+
+<%= link_to 'Edit', edit_sys_config_path(@sys_config) %> |
+<%= link_to 'Back', sys_configs_path %>
View
10 config/environment.rb
@@ -53,12 +53,8 @@
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
# config.i18n.default_locale = :de
-
- # OUTBOUND_MESSAGING_TEMP = "6495a7105bda7c41902027cb67c734c0445cbf5acade80d61b4b9a61b2097bdc62630ea6ef9f0854bb9d96a6"
- # OUTBOUND_VOICE_TEMP = "c7a69e058363c544bb52e93f69c5db3841d0736b971818dfbf6d5e6c4000526f41b269e9c06238899bd770f5"
-
-
- OUTBOUND_MESSAGING_TEMP = "4209df9d948c7a4bbeb07a8117c62b5f5614c13dd25919b855b08645dfeb69787685bb8bf3bb58456ee0ac17"
- OUTBOUND_VOICE_TEMP = "1556a3d0acbaee4b809d61d2630170de1ac687735f6d6f05ea7d616589c3eac49d2b09fc444b23fc1d4d825d"
+
+ # OUTBOUND_MESSAGING_TEMP = "4209df9d948c7a4bbeb07a8117c62b5f5614c13dd25919b855b08645dfeb69787685bb8bf3bb58456ee0ac17"
+ # OUTBOUND_VOICE_TEMP = "1556a3d0acbaee4b809d61d2630170de1ac687735f6d6f05ea7d616589c3eac49d2b09fc444b23fc1d4d825d"
end
View
2 config/environments/development.rb
@@ -16,4 +16,4 @@
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
-SERVER_URL = "http://web1.tunnlr.com:11053"
+# SERVER_URL = "http://web1.tunnlr.com:11053"
View
2 config/environments/production.rb
@@ -27,4 +27,4 @@
# Enable threaded mode
# config.threadsafe!
-SERVER_URL = "http://myopenvoice.appspot.com"
+# SERVER_URL = "http://myopenvoice.appspot.com"
View
2 config/routes.rb
@@ -1,4 +1,6 @@
ActionController::Routing::Routes.draw do |map|
+ map.resources :sys_configs
+
# The priority is based upon order of creation: first created -> highest priority.
# Sample of regular route:
View
12 db/migrate/20100511232854_create_sys_configs.rb
@@ -0,0 +1,12 @@
+class CreateSysConfigs < ActiveRecord::Migration
+ def self.up
+ create_table :sys_configs do |t|
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :sys_configs
+ end
+end
View
7 test/fixtures/sys_configs.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# one:
+# column: value
+#
+# two:
+# column: value
View
45 test/functional/sys_configs_controller_test.rb
@@ -0,0 +1,45 @@
+require 'test_helper'
+
+class SysConfigsControllerTest < ActionController::TestCase
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:sys_configs)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create sys_config" do
+ assert_difference('SysConfig.count') do
+ post :create, :sys_config => { }
+ end
+
+ assert_redirected_to sys_config_path(assigns(:sys_config))
+ end
+
+ test "should show sys_config" do
+ get :show, :id => sys_configs(:one).to_param
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, :id => sys_configs(:one).to_param
+ assert_response :success
+ end
+
+ test "should update sys_config" do
+ put :update, :id => sys_configs(:one).to_param, :sys_config => { }
+ assert_redirected_to sys_config_path(assigns(:sys_config))
+ end
+
+ test "should destroy sys_config" do
+ assert_difference('SysConfig.count', -1) do
+ delete :destroy, :id => sys_configs(:one).to_param
+ end
+
+ assert_redirected_to sys_configs_path
+ end
+end
View
4 test/unit/helpers/sys_configs_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class SysConfigsHelperTest < ActionView::TestCase
+end
View
8 test/unit/sys_config_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class SysConfigTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end

0 comments on commit 6d29741

Please sign in to comment.
Something went wrong with that request. Please try again.