Class: BabySMS::Adapters::TestAdapter

Inherits:
BabySMS::Adapter show all
Defined in:
lib/babysms/adapters/test_adapter.rb

Defined Under Namespace

Classes: WebHook

Instance Attribute Summary collapse

Attributes inherited from BabySMS::Adapter

#client, #from

Instance Method Summary collapse

Methods inherited from BabySMS::Adapter

#adapter_id, adapter_name, #adapter_name, for_adapter_id, for_number, #web_hook, #web_hook?, #web_hook_class

Constructor Details

#initialize(verbose: false, fails: false, from: '+1555-555-5555') ⇒ TestAdapter

Returns a new instance of TestAdapter.



15
16
17
18
19
20
21
# File 'lib/babysms/adapters/test_adapter.rb', line 15

def initialize(verbose: false, fails: false, from: '+1555-555-5555')
  super(from: from)

  self.verbose = verbose
  self.fails = fails
  self.outbox = []
end

Instance Attribute Details

#failsObject

Returns the value of attribute fails.



12
13
14
# File 'lib/babysms/adapters/test_adapter.rb', line 12

def fails
  @fails
end

#outboxObject

Returns the value of attribute outbox.



13
14
15
# File 'lib/babysms/adapters/test_adapter.rb', line 13

def outbox
  @outbox
end

#verboseObject

Returns the value of attribute verbose.



11
12
13
# File 'lib/babysms/adapters/test_adapter.rb', line 11

def verbose
  @verbose
end

Instance Method Details

#deliver(message) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/babysms/adapters/test_adapter.rb', line 23

def deliver(message)
  if fails
    raise BabySMS::FailedDelivery.new('intentional failure', adapter: self)
  end

  outbox.push(message)
  if verbose
    terminal_output = <<~"MSG"
      #{"SMS:".bright.yellow} -> #{message.to.bright.yellow}:
        >> #{message.contents.white}
    MSG
    $stderr.puts terminal_output
  end

  next_message_uuid
end