Permalink
Browse files

Adding text ask to receive sms from ringer.

  • Loading branch information...
Willa
Willa committed Oct 31, 2012
1 parent cb02ac3 commit e3eda53ea415642727e0d2bdbf08287f2a22385a
View
@@ -20,6 +20,10 @@ def self.create_double_opt_in(message)
offline_ask
end
+ def handle?(type, ringer)
+ ringer.tags.include? recipient_tag
+ end
+
def recipient_tag
Tag.from_str("#{id}:recipient")
end
@@ -57,8 +61,8 @@ def trigger(ringers, response_numbers)
class OfflineAsk < Ask
- def handle?(ringer)
- true
+ def handle?(type, ringer)
+ type == :voice
end
def typesym
@@ -67,12 +71,31 @@ def typesym
end
class JoinAsk < Ask
- def handle?(ringer)
- ringer.tags.include? recipient_tag
+ def handle?(type, ringer)
+ type == :voice && super(type, ringer)
end
def typesym
:join_ask
end
end
+
+ class TextAsk < Ask
+ has n, :texts, through: Resource
+
+ def handle?(type, ringer)
+ type == :sms && super(type, ringer)
+ end
+
+ def text(ringer, text, response_numbers)
+ texts << text
+ self.save
+
+ respond(ringer, response_numbers)
+ end
+
+ def typesym
+ :text_ask
+ end
+ end
end
@@ -40,12 +40,14 @@ def response_numbers
def ring(ringer)
return unless rings.create(ringer: ringer).saved?
- ask = asks.reverse.find {|ask| ask.handle?(ringer) }
+ ask = asks.reverse.find {|ask| ask.handle?(:voice, ringer) }
ask.respond(ringer, response_numbers) if ask
end
def text(ringer, message)
- texts.create(ringer: ringer, message: message)
+ text = texts.create(ringer: ringer, message: message)
+ ask = asks.reverse.find {|ask| ask.handle?(:sms, ringer) }
+ ask.text(ringer, text, response_numbers) if ask
end
def unique_rings
@@ -1,10 +1,11 @@
module Crowdring
class LoggingRequest
- attr_reader :from, :to
+ attr_reader :from, :to, :message
def initialize(request)
@to = request.GET['to']
@from = request.GET['from']
+ @message = request.GET['msg'] if request.GET['msg']
end
def callback?
View
@@ -7,7 +7,7 @@ class Text
property :created_at, DateTime
property :message, String, length: 160
- belongs_to :campaign
+ belongs_to :campaign, required: false
belongs_to :ringer
def phone_number
@@ -0,0 +1,4 @@
+%h3 Text Ask
+="#{ask.respondents.count} recipients / #{ask.recipients.count} respondents"
+-ask.texts.each do |t|
+ %li= t.message
View
@@ -49,7 +49,7 @@
%h2= "ASKS"
-@campaign.asks.each do |ask|
=haml :ask, locals: {ask: ask, type: ask.typesym}
-
+
#broadcast.form-box
%h3 Broadcast
View
@@ -23,13 +23,12 @@
it 'should trigger the join ask upon receiving a response' do
ask = Crowdring::Ask.create_double_opt_in(nil)
ask.respond(@ringer, @response_numbers)
-
ask.triggered_ask.recipients(Crowdring::Ringer.all).should eq([@ringer])
end
it 'should handle any incoming ring' do
ask = Crowdring::OfflineAsk.create
- ask.handle?(@ringer).should be_true
+ ask.handle?(:voice, @ringer).should be_true
end
end
@@ -44,10 +43,23 @@
it 'should handle an incoming ring that it has sent a join ask to' do
ask = Crowdring::JoinAsk.create
- ask.handle?(@ringer).should be_false
+ ask.handle?(:voice, @ringer).should be_false
ask.trigger_for(@ringer, @response_numbers)
- ask.handle?(@ringer).should be_true
+ ask.handle?(:voice, @ringer).should be_true
end
end
+ describe 'text ask' do
+ it 'should record response from ringer' do
+ message = Crowdring::Message.new(default_message: 'blah')
+ text = Crowdring::Text.new(message: 'BLAH', ringer: @ringer)
+ ask = Crowdring::TextAsk.new(message: message)
+
+ ask.trigger_for(@ringer, @response_numbers)
+ ask.text(@ringer, text, @response_numbers)
+
+ ask.texts.count.should eq(1)
+ ask.texts.first.should eq(text)
+ end
+ end
end

0 comments on commit e3eda53

Please sign in to comment.