Skip to content

An sms_carrier delivery method layer that decides the delivery method dynamically by your rules.

License

Notifications You must be signed in to change notification settings

emn178/dynamic-carrier

Repository files navigation

dynamic-carrier

Build Status Coverage Status

An sms_carrier delivery method layer that decides the delivery method dynamically by your rules.

Installation

Add this line to your application's Gemfile:

gem 'dynamic-carrier'

And then execute:

bundle

Or install it yourself as:

gem install dynamic-carrier

Usage

Setup

Set up delivery method and Twilio settings in you rails config, eg. config/environments/production.rb

config.sms_carrier.delivery_method = :dynamic
config.sms_carrier.dynamic_settings = {
  # default delivery_method if not matched, default is :test
  :default_delivery_method => :twilio
}

Rules

Add your rules by DynamicCarrier.add_rule.

# add a rule with Proc, it will use yunpian delivery_method if matched.
DynamicCarrier.add_rule(:yunpian, Proc.new { |to, sms| to.start_with?('+86') })

# This will send by yunpian
SmsCarrier::Base.sms(:to => '+8615123456789', :body => '...')

# This will send by your default_delivery_method, eg. twilio
SmsCarrier::Base.sms(:to => '+886912345678', :body => '...')

Or you can define a class.

class ChinaRule
  def match(to, sms)
    to.start_with?('+86')
  end
end

DynamicCarrier.add_rule(:yunpian, ChinaRule)

License

The gem is available as open source under the terms of the MIT License.

Contact

The project's website is located at https://github.com/emn178/dynamic-carrier
Author: emn178@gmail.com

About

An sms_carrier delivery method layer that decides the delivery method dynamically by your rules.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages