lib/contactable.rb in twilio_contactable-0.8.5 vs lib/contactable.rb in twilio_contactable-0.8.7
- old
+ new
@@ -87,18 +87,11 @@
return false if _TC_sms_blocked
return true if sms_confirmed?
return false if _TC_phone_number.blank?
format_phone_number
- confirmation_code =
- if sms_confirmation_attempted &&
- sms_confirmation_code &&
- sms_confirmation_attempted > Time.now.utc - 60*5
- sms_confirmation_code
- else
- TwilioContactable.generate_confirmation_code
- end
+ confirmation_code = TwilioContactable.confirmation_code(self, :sms)
# Use this class' confirmation_message method if it
# exists, otherwise use the generic message
message = (self.class.respond_to?(:confirmation_message) ?
self.class :
@@ -110,38 +103,31 @@
response = TwilioContactable::Gateway.deliver(message, _TC_phone_number)
if response.success?
update_twilio_contactable_sms_confirmation confirmation_code
- else
- false
end
+
+ response
end
# Begins a phone call to the user where they'll need to type
# their confirmation code
def send_voice_confirmation!
return false if _TC_voice_blocked
return true if voice_confirmed?
return false if _TC_phone_number.blank?
format_phone_number
- confirmation_code =
- if voice_confirmation_attempted &&
- voice_confirmation_code &&
- voice_confirmation_attempted > Time.now.utc - 60*5
- voice_confirmation_code
- else
- TwilioContactable.generate_confirmation_code
- end
+ confirmation_code = TwilioContactable.confirmation_code(self, :voice)
response = TwilioContactable::Gateway.initiate_voice_call(self, _TC_formatted_phone_number)
if response.success?
update_twilio_contactable_voice_confirmation confirmation_code
- else
- false
end
+
+ response
end
# Compares user-provided code with the stored confirmation
# code. If they match then the current phone number is set
# as confirmed by the user.
\ No newline at end of file