Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: nherzing/crowdring
base: fb4ae5f47e
...
head fork: nherzing/crowdring
compare: a4fe83c89a
  • 2 commits
  • 14 files changed
  • 0 commit comments
  • 1 contributor
View
1  lib/crowdring.rb
@@ -33,7 +33,6 @@
require 'crowdring/phone_number_fields'
require 'crowdring/campaign'
-require 'crowdring/response_numbers'
require 'crowdring/ringer'
require 'crowdring/ring'
require 'crowdring/text'
View
2  lib/crowdring/ask.rb
@@ -69,7 +69,7 @@ def initial_price_estimate(ringers=Ringer.all, sms_number)
smss = ringers.map do |ringer|
text = message.for(ringer, sms_number)
- text && OutgoingSMS.new(from: sms_number, to: ringer, text: text)
+ text && OutgoingSMS.new(from: sms_number, to: ringer.phone_number, text: text)
end
PriceEstimate.new(smss.compact)
View
1  lib/crowdring/assigned_phone_number.rb
@@ -61,7 +61,6 @@ def ring(ringer)
class AssignedSMSNumber
include AssignedPhoneNumberFields
include PhoneNumberFields
-
belongs_to :campaign
def text(ringer, message)
View
5 lib/crowdring/crowdring.rb
@@ -22,7 +22,8 @@ def self.service_handler
configure :development do
register Sinatra::Reloader
- service_handler.add('logger', LoggingService.new(['+18001111111', '+18002222222', '+919102764614','+27114891907'], output: true))
+ service_handler.add('voice_logger', VoiceLoggingService.new(['+18001111111', '+555130793000', '+18002222222', '+919102764633','+27114891922'], output: true))
+ service_handler.add('sms_logger', SMSLoggingService.new(['+18001111111', '+18002222222', '27800', '+919102764622', '+27114891911'], output: true))
end
configure :production do
@@ -350,7 +351,7 @@ def process_request(service_name, request, response_type)
@countries = @campaign.ringers.map(&:country).uniq
@all_fields = CsvField.all_fields
@basic_chart = HighChartsBuilder.basic_stats(@campaign)
- @sms_cost = SMSPrices.price_for(CompositeService.instance.service_for(:sms, @campaign.sms_number.raw_number), @campaign.sms_number)
+ @sms_cost = SMSPrices.price_for(CompositeService.instance.service_for(:sms, @campaign.sms_number.raw_number), @campaign.sms_number.raw_number)
haml :campaign, layout: !request.xhr?
else
View
3  lib/crowdring/phone_number_fields.rb
@@ -24,7 +24,8 @@ def area_code
end
def country
- number.country
+ short_code = ShortCode.parse(phone_number)
+ short_code ? short_code.country : number.country
end
def number
View
9 lib/crowdring/response_numbers.rb
@@ -1,9 +0,0 @@
-module Crowdring
- class ResponseNumbers < Struct.new(:voice_number, :sms_number)
- def initialize(params)
- self.voice_number = params[:voice_number]
- self.sms_number = params[:sms_number]
- end
- end
-end
-
View
1  lib/crowdring/short_code.rb
@@ -5,6 +5,7 @@ def self.parse(number)
end
def country
+ Phoner::Country.load
Phoner::Country.find_by_name('Brazil')
end
end
View
6 lib/crowdring/sms_prices.rb
@@ -13,8 +13,10 @@ def default_prices
def price_for(service, number, opts={})
prices = opts[:prices] || default_prices
-
- prices[service] && prices[service][number.country.char_3_code]
+ if prices[service]
+ short_code = ShortCode.parse(number)
+ short_code ? prices[service][short_code.country.char_3_code] : prices[service][number.country.char_3_code]
+ end
end
end
end
View
3  lib/crowdring/telephony_services/composite_service.rb
@@ -49,8 +49,7 @@ def broadcast(from, msg, to_numbers)
end
def service_for(type, number)
- @services.each {|name, service| return name if supports_number(service, number) && service.send("#{type}?") }
-
+ service = @services.each {|name, service| return name if supports_number(service, number) && service.send("#{type}?") }
raise NoServiceError, "No service handler for #{number}"
end
View
49 lib/crowdring/telephony_services/logging_service.rb
@@ -44,4 +44,53 @@ def broadcast(from, msg, to_numbers)
p "Broadcast: from: #{from}, msg: '#{msg}', to: #{to_numbers}" if @do_output
end
end
+
+ class VoiceLoggingService < TelephonyService
+ supports :voice
+ request_handler LoggingRequest
+
+ def initialize(numbers, opts={})
+ @numbers = numbers
+ @do_output = opts[:output]
+ end
+
+ def build_response(from, commands)
+ @last_response = "Reponse: From: #{from}, Commands: #{commands}"
+ p @last_response if @do_output
+ @last_response
+ end
+
+ def numbers
+ @numbers
+ end
+ end
+
+ class SMSLoggingService < TelephonyService
+ supports :sms
+
+ def initialize(numbers, opts={})
+ @numbers = numbers
+ @do_output = opts[:output]
+ end
+
+ def build_response(from, commands)
+ @last_response = "Reponse: From: #{from}, Commands: #{commands}"
+ p @last_response if @do_output
+ @last_response
+ end
+
+ def numbers
+ @numbers
+ end
+
+ def send_sms(params)
+ @last_sms = params
+ p "Send SMS: #{params}" if @do_output
+ end
+
+ def broadcast(from, msg, to_numbers)
+ @last_broadcast = {from: from, msg: msg, to_numbers: to_numbers }
+ p "Broadcast: from: #{from}, msg: '#{msg}', to: #{to_numbers}" if @do_output
+ end
+ end
end
View
2  lib/crowdring/telephony_services/nexmo_service.rb
@@ -26,7 +26,7 @@ def initialize(key, secret)
end
def numbers
- @client.get_account_numbers(size:100).object[:numbers].map {|n| n[:msisdn] }
+ @client.get_account_numbers(size:100).object["numbers"].map{|n| n["msisdn"]}
end
def build_response(from, commands)
View
1  lib/views/asks/send_sms_ask.haml
@@ -1,5 +1,6 @@
%h3 Send SMS Ask
%h4 Initial Cost Estimate
=haml :price_estimate, locals: {price_estimate: ask.initial_price_estimate(@campaign.ringers, @campaign.sms_number.raw_number)}
+
="#{ask.recipients.count} recipients"
=haml :message, locals: {message: ask.message}
View
9 lib/views/campaign.haml
@@ -38,8 +38,11 @@
%h3
-if @campaign.sms_number
=@campaign.sms_number.pretty_phone_number
- %h4="Cost per text message: $#{@sms_cost}"
- %h5="(Assuming messages are sent to #{@campaign.sms_number.country_abbreviation} numbers)"
+ -if @sms_cost
+ %h4="Cost per text message: $#{@sms_cost}"
+ %h5="(Assuming messages are sent to #{@campaign.sms_number.country_abbreviation} numbers)"
+ -else
+ %h4 Cost per text message: Unknown.
-else
No SMS number selected
#campaign-ringers
@@ -56,10 +59,12 @@
#asks
%h2= "ASKS"
-@campaign.asks.each do |ask|
+ %hr
-if @campaign.asks.select{|n| n.triggered_ask && n.triggered_ask == ask}.empty? && ask != @campaign.asks.first
%form{action: "/campaign/#{@campaign.id}/asks/#{ask.id}/trigger", method: "post"}
%button{type:'submit'} Launch the Ask
=haml :ask, locals: {ask: ask, type: ask.class.typesym}
+ %hr
%form{action: "/campaign/#{@campaign.id}/asks/new", method: 'get'}
%button Add new ask
View
4 spec/server_spec.rb
@@ -66,8 +66,8 @@ def app
end
describe 'campaign fetching' do
- it 'should successfully fetch a campaign at campaign/id' do
- CompositeService.instance.add('foo', LoggingService.new([@number]))
+ it 'should successfully fetch a campaign at campaign/id' , focus: true do
+ CompositeService.instance.add('foo', LoggingService.new(@numbers))
c = Campaign.create(title: 'title', voice_numbers: [{phone_number: @number, description: 'desc'}], sms_number: @number)
get "/campaign/#{c.id}"
last_response.should be_ok

No commit comments for this range

Something went wrong with that request. Please try again.