Sha256: ddf6df7fd4cfdb0de8acc63a769adb0e563d6b7d7c094a7de36b3be4ce6dd642

Contents?: true

Size: 1.48 KB

Versions: 2

Compression:

Stored size: 1.48 KB

Contents

module TwilioContactable
  unless defined?(CONFIRMATION_CODE_LENGTH)
    CONFIRMATION_CODE_LENGTH = 4
  end
  class << self
    def numerize(numberish)
      numberish.to_s.scan(/\d+/).join
    end

    def internationalize(given_number)
      number = numerize(given_number)
      case number.size
      when 10
        "+1#{number}"
      when 11,12
        "+#{number}"
      else
        nil
      end
    end

    def confirmation_message(confirmation_code)
      "Code: #{confirmation_code} Enter code on web to verify phone. Msg&data rates may apply. Freq set by u. T&C & support on web site. Txt HELP for help"
    end

    def confirmation_code(record, type)
      attempted = record.send("_TC_#{type}_confirmation_attempted")
      current_code = record.send("_TC_#{type}_confirmation_code")
      if !attempted.blank? &&
         attempted > Time.now.utc - 60*5 &&
         current_code.to_s.size == CONFIRMATION_CODE_LENGTH
        current_code
      else
        generate_confirmation_code
      end
    end

    def generate_confirmation_code
      nums = (0..9).to_a
      (0...CONFIRMATION_CODE_LENGTH).collect { nums[Kernel.rand(nums.length)] }.join
    end
  end
end

gem 'twiliolib'
require 'twiliolib'

require File.expand_path(File.join(File.dirname(__FILE__), 'configuration'))
require File.expand_path(File.join(File.dirname(__FILE__), 'gateway'))
require File.expand_path(File.join(File.dirname(__FILE__), 'contactable'))
require File.expand_path(File.join(File.dirname(__FILE__), 'controller'))

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
twilio_contactable-0.8.9 lib/twilio_contactable.rb
twilio_contactable-0.8.8 lib/twilio_contactable.rb