Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 14 files changed
  • 0 comments
  • 1 contributor
1  lib/crowdring.rb
@@ -33,7 +33,6 @@
33 33
34 34 require 'crowdring/phone_number_fields'
35 35 require 'crowdring/campaign'
36   -require 'crowdring/response_numbers'
37 36 require 'crowdring/ringer'
38 37 require 'crowdring/ring'
39 38 require 'crowdring/text'
2  lib/crowdring/ask.rb
@@ -69,7 +69,7 @@ def initial_price_estimate(ringers=Ringer.all, sms_number)
69 69
70 70 smss = ringers.map do |ringer|
71 71 text = message.for(ringer, sms_number)
72   - text && OutgoingSMS.new(from: sms_number, to: ringer, text: text)
  72 + text && OutgoingSMS.new(from: sms_number, to: ringer.phone_number, text: text)
73 73 end
74 74
75 75 PriceEstimate.new(smss.compact)
1  lib/crowdring/assigned_phone_number.rb
@@ -61,7 +61,6 @@ def ring(ringer)
61 61 class AssignedSMSNumber
62 62 include AssignedPhoneNumberFields
63 63 include PhoneNumberFields
64   -
65 64 belongs_to :campaign
66 65
67 66 def text(ringer, message)
5 lib/crowdring/crowdring.rb
@@ -22,7 +22,8 @@ def self.service_handler
22 22
23 23 configure :development do
24 24 register Sinatra::Reloader
25   - service_handler.add('logger', LoggingService.new(['+18001111111', '+18002222222', '+919102764614','+27114891907'], output: true))
  25 + service_handler.add('voice_logger', VoiceLoggingService.new(['+18001111111', '+555130793000', '+18002222222', '+919102764633','+27114891922'], output: true))
  26 + service_handler.add('sms_logger', SMSLoggingService.new(['+18001111111', '+18002222222', '27800', '+919102764622', '+27114891911'], output: true))
26 27 end
27 28
28 29 configure :production do
@@ -350,7 +351,7 @@ def process_request(service_name, request, response_type)
350 351 @countries = @campaign.ringers.map(&:country).uniq
351 352 @all_fields = CsvField.all_fields
352 353 @basic_chart = HighChartsBuilder.basic_stats(@campaign)
353   - @sms_cost = SMSPrices.price_for(CompositeService.instance.service_for(:sms, @campaign.sms_number.raw_number), @campaign.sms_number)
  354 + @sms_cost = SMSPrices.price_for(CompositeService.instance.service_for(:sms, @campaign.sms_number.raw_number), @campaign.sms_number.raw_number)
354 355
355 356 haml :campaign, layout: !request.xhr?
356 357 else
3  lib/crowdring/phone_number_fields.rb
@@ -24,7 +24,8 @@ def area_code
24 24 end
25 25
26 26 def country
27   - number.country
  27 + short_code = ShortCode.parse(phone_number)
  28 + short_code ? short_code.country : number.country
28 29 end
29 30
30 31 def number
9 lib/crowdring/response_numbers.rb
... ... @@ -1,9 +0,0 @@
1   -module Crowdring
2   - class ResponseNumbers < Struct.new(:voice_number, :sms_number)
3   - def initialize(params)
4   - self.voice_number = params[:voice_number]
5   - self.sms_number = params[:sms_number]
6   - end
7   - end
8   -end
9   -
1  lib/crowdring/short_code.rb
@@ -5,6 +5,7 @@ def self.parse(number)
5 5 end
6 6
7 7 def country
  8 + Phoner::Country.load
8 9 Phoner::Country.find_by_name('Brazil')
9 10 end
10 11 end
6 lib/crowdring/sms_prices.rb
@@ -13,8 +13,10 @@ def default_prices
13 13
14 14 def price_for(service, number, opts={})
15 15 prices = opts[:prices] || default_prices
16   -
17   - prices[service] && prices[service][number.country.char_3_code]
  16 + if prices[service]
  17 + short_code = ShortCode.parse(number)
  18 + short_code ? prices[service][short_code.country.char_3_code] : prices[service][number.country.char_3_code]
  19 + end
18 20 end
19 21 end
20 22 end
3  lib/crowdring/telephony_services/composite_service.rb
@@ -49,8 +49,7 @@ def broadcast(from, msg, to_numbers)
49 49 end
50 50
51 51 def service_for(type, number)
52   - @services.each {|name, service| return name if supports_number(service, number) && service.send("#{type}?") }
53   -
  52 + service = @services.each {|name, service| return name if supports_number(service, number) && service.send("#{type}?") }
54 53 raise NoServiceError, "No service handler for #{number}"
55 54 end
56 55
49 lib/crowdring/telephony_services/logging_service.rb
@@ -44,4 +44,53 @@ def broadcast(from, msg, to_numbers)
44 44 p "Broadcast: from: #{from}, msg: '#{msg}', to: #{to_numbers}" if @do_output
45 45 end
46 46 end
  47 +
  48 + class VoiceLoggingService < TelephonyService
  49 + supports :voice
  50 + request_handler LoggingRequest
  51 +
  52 + def initialize(numbers, opts={})
  53 + @numbers = numbers
  54 + @do_output = opts[:output]
  55 + end
  56 +
  57 + def build_response(from, commands)
  58 + @last_response = "Reponse: From: #{from}, Commands: #{commands}"
  59 + p @last_response if @do_output
  60 + @last_response
  61 + end
  62 +
  63 + def numbers
  64 + @numbers
  65 + end
  66 + end
  67 +
  68 + class SMSLoggingService < TelephonyService
  69 + supports :sms
  70 +
  71 + def initialize(numbers, opts={})
  72 + @numbers = numbers
  73 + @do_output = opts[:output]
  74 + end
  75 +
  76 + def build_response(from, commands)
  77 + @last_response = "Reponse: From: #{from}, Commands: #{commands}"
  78 + p @last_response if @do_output
  79 + @last_response
  80 + end
  81 +
  82 + def numbers
  83 + @numbers
  84 + end
  85 +
  86 + def send_sms(params)
  87 + @last_sms = params
  88 + p "Send SMS: #{params}" if @do_output
  89 + end
  90 +
  91 + def broadcast(from, msg, to_numbers)
  92 + @last_broadcast = {from: from, msg: msg, to_numbers: to_numbers }
  93 + p "Broadcast: from: #{from}, msg: '#{msg}', to: #{to_numbers}" if @do_output
  94 + end
  95 + end
47 96 end
2  lib/crowdring/telephony_services/nexmo_service.rb
@@ -26,7 +26,7 @@ def initialize(key, secret)
26 26 end
27 27
28 28 def numbers
29   - @client.get_account_numbers(size:100).object[:numbers].map {|n| n[:msisdn] }
  29 + @client.get_account_numbers(size:100).object["numbers"].map{|n| n["msisdn"]}
30 30 end
31 31
32 32 def build_response(from, commands)
1  lib/views/asks/send_sms_ask.haml
... ... @@ -1,5 +1,6 @@
1 1 %h3 Send SMS Ask
2 2 %h4 Initial Cost Estimate
3 3 =haml :price_estimate, locals: {price_estimate: ask.initial_price_estimate(@campaign.ringers, @campaign.sms_number.raw_number)}
  4 +
4 5 ="#{ask.recipients.count} recipients"
5 6 =haml :message, locals: {message: ask.message}
9 lib/views/campaign.haml
@@ -38,8 +38,11 @@
38 38 %h3
39 39 -if @campaign.sms_number
40 40 =@campaign.sms_number.pretty_phone_number
41   - %h4="Cost per text message: $#{@sms_cost}"
42   - %h5="(Assuming messages are sent to #{@campaign.sms_number.country_abbreviation} numbers)"
  41 + -if @sms_cost
  42 + %h4="Cost per text message: $#{@sms_cost}"
  43 + %h5="(Assuming messages are sent to #{@campaign.sms_number.country_abbreviation} numbers)"
  44 + -else
  45 + %h4 Cost per text message: Unknown.
43 46 -else
44 47 No SMS number selected
45 48 #campaign-ringers
@@ -56,10 +59,12 @@
56 59 #asks
57 60 %h2= "ASKS"
58 61 -@campaign.asks.each do |ask|
  62 + %hr
59 63 -if @campaign.asks.select{|n| n.triggered_ask && n.triggered_ask == ask}.empty? && ask != @campaign.asks.first
60 64 %form{action: "/campaign/#{@campaign.id}/asks/#{ask.id}/trigger", method: "post"}
61 65 %button{type:'submit'} Launch the Ask
62 66 =haml :ask, locals: {ask: ask, type: ask.class.typesym}
  67 + %hr
63 68 %form{action: "/campaign/#{@campaign.id}/asks/new", method: 'get'}
64 69 %button Add new ask
65 70
4 spec/server_spec.rb
@@ -66,8 +66,8 @@ def app
66 66 end
67 67
68 68 describe 'campaign fetching' do
69   - it 'should successfully fetch a campaign at campaign/id' do
70   - CompositeService.instance.add('foo', LoggingService.new([@number]))
  69 + it 'should successfully fetch a campaign at campaign/id' , focus: true do
  70 + CompositeService.instance.add('foo', LoggingService.new(@numbers))
71 71 c = Campaign.create(title: 'title', voice_numbers: [{phone_number: @number, description: 'desc'}], sms_number: @number)
72 72 get "/campaign/#{c.id}"
73 73 last_response.should be_ok

No commit comments for this range

Something went wrong with that request. Please try again.