module AnySMS

Constants

VERSION

Public Class Methods

config() click to toggle source

@return [AnySMS::Configuration] object with configuration options

# File lib/any_sms/configuration.rb, line 4
def self.config
  @@config ||= Configuration.new
end
configure() { |config| ... } click to toggle source

Allows to configure AnySMS options and register backends

# File lib/any_sms/configuration.rb, line 9
def self.configure
  yield(config)
end
reset!() click to toggle source

resets AnySMS configuration to default

# File lib/any_sms/configuration.rb, line 14
def self.reset!
  @@config = nil
end
send_sms(phone, text, args = {}) click to toggle source

Core of the gem, method responsible for sending sms

@param phone [String] Phone number for sms @param text [String] Text for sms @param backend [Symbol] Keyword argument to specify non-default backend @param args [Hash] Additional options for delivery bypassed to final backend

# File lib/any_sms/sending.rb, line 10
def send_sms(phone, text, args = {})
  backend_name = args.delete(:backend)
  backend_class(backend_name).new(backend_params(backend_name))
                             .send_sms(phone, text, args)
end

Private Class Methods

backend_class(name) click to toggle source
# File lib/any_sms/sending.rb, line 18
def backend_class(name)
  return default_backend_class if name.nil?

  if AnySMS.config.backends[name].nil?
    raise ArgumentError, "#{name} backend is not registered"
  end

  AnySMS.config.backends[name][:class]
end
backend_params(name) click to toggle source
# File lib/any_sms/sending.rb, line 32
def backend_params(name)
  return default_backend_params if name.nil?
  AnySMS.config.backends[name][:params]
end
default_backend_class() click to toggle source
# File lib/any_sms/sending.rb, line 28
def default_backend_class
  AnySMS.config.backends[AnySMS.config.default_backend][:class]
end
default_backend_params() click to toggle source
# File lib/any_sms/sending.rb, line 37
def default_backend_params
  AnySMS.config.backends[AnySMS.config.default_backend][:params]
end