0.0
No commit activity in last 3 years
No release in over 3 years
An sms_carrier delivery method layer that decides the delivery method dynamically by your rules.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.0
>= 0

Runtime

>= 0.1.1
 Project Readme

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