Skip to content

Commit

Permalink
twilio client dialler
Browse files Browse the repository at this point in the history
  • Loading branch information
stevegraham committed Aug 30, 2011
1 parent c666c20 commit 18df741
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 256 deletions.
5 changes: 3 additions & 2 deletions Gemfile
@@ -1,8 +1,9 @@
source 'http://rubygems.org'

gem 'rails', '3.0.10'
gem 'twilio-rb', git: 'git://github.com/stevegraham/twilio-rb'
gem 'rails', '3.0.10'
gem 'twilio-rb', git: 'git://github.com/stevegraham/twilio-rb'
gem 'settingslogic'
gem 'haml'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
Expand Down
10 changes: 9 additions & 1 deletion Gemfile.lock
@@ -1,12 +1,14 @@
GIT
remote: git://github.com/stevegraham/twilio-rb
revision: 5d8f7174d6e333909c8fdd481d44e6a7c2a5e216
revision: 00b99470c96d5678f9c9c5c2bda29424e9ce5e3a
specs:
twilio-rb (1.0beta3)
activesupport (>= 3.0.0)
builder (>= 2.1.2)
httparty (>= 0.6.1)
i18n (~> 0.5.0)
jwt (>= 0.1.3)
timecop (>= 0.3.5)
yajl-ruby (>= 0.7.7)

GEM
Expand Down Expand Up @@ -44,9 +46,13 @@ GEM
crack (0.1.8)
erubis (2.6.6)
abstract (>= 1.0.0)
haml (3.1.2)
httparty (0.7.8)
crack (= 0.1.8)
i18n (0.5.0)
json (1.5.3)
jwt (0.1.3)
json (>= 1.2.4)
mail (2.2.19)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
Expand Down Expand Up @@ -78,6 +84,7 @@ GEM
settingslogic (2.0.6)
sqlite3 (1.3.4)
thor (0.14.6)
timecop (0.3.5)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
Expand All @@ -88,6 +95,7 @@ PLATFORMS
ruby

DEPENDENCIES
haml
rails (= 3.0.10)
settingslogic
sqlite3
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/application_controller.rb
@@ -1,3 +1,11 @@
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :authenticate

private
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == Settings.user.email && password == Settings.user.password
end
end
end
5 changes: 5 additions & 0 deletions app/controllers/home_controller.rb
@@ -0,0 +1,5 @@
class HomeController < ApplicationController
def index
@capability_token = Twilio::CapabilityToken.create allow_outgoing: Settings.twilio.app_sid
end
end
2 changes: 2 additions & 0 deletions app/helpers/home_helper.rb
@@ -0,0 +1,2 @@
module HomeHelper
end
44 changes: 44 additions & 0 deletions app/views/home/index.html.haml
@@ -0,0 +1,44 @@
= form_tag('#', id: 'dialler') do
= phone_field_tag 'number'
= submit_tag 'Call', id: 'dial'
= submit_tag 'Hangup', id: 'hangup', style: 'display:none;'

= content_for :javascript do
:javascript
$(document).ready(function() {
Twilio.Device.setup("#{@capability_token}")

Twilio.Device.disconnect(function(connection) {
$('#hangup').hide()
$('#dial').show()
})

$('#dialler').submit(function(ev) {
ev.stopImmediatePropagation()
ev.preventDefault()
})

$('#number').click(function(ev) {
$(this).val(null)
})

$('#dial').click(function(ev) {
var number = $('#number').val()
if(number.match(/\+?\d{10,}/)) {
Twilio.Device.connect({ 'phone_number' : number })
$(this).hide()
$('#hangup').show()
} else {
alert('Please enter a legit phone number.')
}
ev.stopImmediatePropagation()
ev.preventDefault()
})

$('#hangup').click(function(ev) {
Twilio.Device.disconnectAll()
ev.stopImmediatePropagation()
ev.preventDefault()
})

})
14 changes: 0 additions & 14 deletions app/views/layouts/application.html.erb

This file was deleted.

17 changes: 17 additions & 0 deletions app/views/layouts/application.html.haml
@@ -0,0 +1,17 @@
!!!
%html
%head
%title
CheapDate &mdash; Call your old lady back home using Twilio's LOW LOW international rates!
= stylesheet_link_tag :all
= javascript_include_tag :defaults
= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'
= javascript_include_tag 'http://static.twilio.com/libs/twiliojs/1.0/twilio.min.js'
= csrf_meta_tag
%body
%header
%h1
= link_to 'CheapDate', root_path
= yield
= yield :javascript

3 changes: 3 additions & 0 deletions config/application.yml.example
Expand Up @@ -2,6 +2,9 @@ defaults: &defaults
twilio:
account_sid: ACXXXXXXXXXXXXXXXXXXXXXXXX
auth_token: XXXXXXXXXXXXXXXXXXXXXXXXXX
user:
email: you@example.com
password: password123

development:
<<: *defaults
4 changes: 4 additions & 0 deletions config/initializers/twilio.rb
@@ -0,0 +1,4 @@
Twilio::Config.setup do
account_sid Settings.twilio.account_sid
auth_token Settings.twilio.auth_token
end
2 changes: 2 additions & 0 deletions config/routes.rb
@@ -1,4 +1,6 @@
Cheapdate::Application.routes.draw do
root to: 'home#index'

# The priority is based upon order of creation:
# first created -> highest priority.

Expand Down

0 comments on commit 18df741

Please sign in to comment.