Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@neetso
neetso / tinyurl.rb
Created November 26, 2016 09:37 — forked from woods/tinyurl.rb
A complete URL-shortening web application, written in Ruby/Sinatra.
#!/usr/bin/env ruby
#
# A complete URL-shortening web application, written in Ruby/Sinatra. Run it
# from the command line, and then visit http://localhost:4567/
#
# Or to run it under apache/passenger, you'll need a config.ru file with the
# following contents:
#
# require 'tinyurl'
# run Sinatra::Application
@neetso
neetso / web.rb
Last active January 26, 2016 07:35
post '/answer' do
user = params[:user]
if user == "voicemail"
notifier.ping "Call from: " + $redis.hget("call:#{params[:callId]}","from") + ". Hotline off.",
attachments: [call_details]
end
end
post '/hangup' do
hangupCause = "#{params[:cause]}"
@neetso
neetso / web.rb
Last active January 26, 2016 07:34
post '/' do
phonenumber = params[:from]
$redis.hset("call:#{params[:callId]}","from",phonenumber[0...-3]+'XXX')
headers 'Content-Type' => "application/xml"
xml = Builder::XmlMarkup.new(:indent => 2)
xml.instruct!
xml.Response("onAnswer" => settings.responseUrl + "answer",
"onHangup" => settings.responseUrl + "hangup")
end
@neetso
neetso / web.rb
Last active January 26, 2016 07:33
require 'slack-notifier'
require 'sinatra'
require 'builder'
require 'redis'
notifier = Slack::Notifier.new "https://hooks.slack.com/services/XXXXXXX/XXXXXXX/XXXXXXX"
call_details = {
fallback: "Call Details in the team <https://secure.live.sipgate.co.uk/|event list>.",
text: "Call Details in the team <https://secure.live.sipgate.co.uk/|event list>.",