Module: TwilioContactable

Defined in:
lib/gateway.rb,
lib/controller.rb,
lib/contactable.rb,
lib/configuration.rb,
lib/twilio_contactable.rb

Defined Under Namespace

Modules: Contactable, Controller, Gateway Classes: Configuration

Constant Summary collapse

CONFIRMATION_CODE_LENGTH =
4

Class Method Summary collapse

Class Method Details

.configurationObject



16
17
18
# File 'lib/configuration.rb', line 16

def configuration
  @configuration ||= Configuration.new
end

.configure(&block) ⇒ Object



20
21
22
# File 'lib/configuration.rb', line 20

def configure(&block)
  @configuration = Configuration.new(&block)
end

.configured?Boolean

Returns:

  • (Boolean)


11
12
13
14
# File 'lib/configuration.rb', line 11

def configured?
  return false unless configuration
  configuration.client_id && configuration.client_key
end

.confirmation_code(record, type) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/twilio_contactable.rb', line 24

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

.confirmation_message(confirmation_code) ⇒ Object



20
21
22
# File 'lib/twilio_contactable.rb', line 20

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

.generate_confirmation_codeObject



36
37
38
39
# File 'lib/twilio_contactable.rb', line 36

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

.internationalize(given_number) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/twilio_contactable.rb', line 8

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

.modeObject



3
4
5
# File 'lib/configuration.rb', line 3

def mode
  @@mode ||= :test
end

.mode=(new_mode) ⇒ Object



7
8
9
# File 'lib/configuration.rb', line 7

def mode=(new_mode)
  @@mode = new_mode
end

.numerize(numberish) ⇒ Object



4
5
6
# File 'lib/twilio_contactable.rb', line 4

def numerize(numberish)
  numberish.to_s.scan(/\d+/).join
end