GithubHelp home page GithubHelp logo

cellular's Introduction

Cellular

Gem Version Build Status Dependency Status Code Climate Coverage Status

Sending and receiving SMSs with Ruby through pluggable backends.

Supported Ruby versions: 2.0.0 or higher

Licensed under the MIT license, see LICENSE for more information.

Installation

Add this line to your application's Gemfile:

gem 'cellular'

And then execute:

bundle

Or install it yourself as:

gem install cellular

Usage

Configuration

Cellular.configure do |config|
  config.username = 'username'
  config.password = 'password'
  config.backend = Cellular::Backends::Sendega
  config.sender = 'Default custom sender'
  config.country_code = 'NO'
end

Cellular uses Rails' ActiveJob interface to interact with queue backends. Read appropriate documentation to set up queue.

Available Backends

Sending SMSs

The options supported may differ between backends.

sms = Cellular::SMS.new(
  recipient: '+47xxxxxxxx', # Valid international format
  sender: '+370xxxxxxxx',
  message: 'This is an SMS message',
  price: 0,
  country_code: 'NO' # defaults to Cellular.config.country_code
)

sms.deliver

For use with multiple recipients in one request use:

sms = Cellular::SMS.new(
  recipients: ['+47xxxxxxx1','+47xxxxxxx2','+47xxxxxxx3'],
  sender: '+370xxxxxxxx',
  message: 'This is an SMS message',
  price: 0,
  country_code: 'NO' # defaults to Cellular.config.country_code
)

sms.deliver

Delayed SMSs delivery

You can also send texts asynchronously, which is great if you're in a Rails app and are concerned that it might time out or something. To use it, just call deliver_async instead of deliver on the SMS object:

sms = Cellular::SMS.new(
  recipient: '+47xxxxxxxx',
  sender: '+47xxxxxxxx',
  message: 'This is an SMS message'
)

sms.deliver_async

This will create a delayed job for you on the cellular queue, so make sure that your queue processor is running.

To override queue name, use queue option

sms.deliver_async(queue: :urgent)

Using ActiveJob, Cellular allows you to schedule the time when an SMS will be sent. Just call deliver_async(wait_until: timestamp) or deliver_async(wait: time) on the SMS object:

sms = Cellular::SMS.new(
  recipient: '+47xxxxxxxx',
  sender: '+47xxxxxxxx',
  message: 'This is an SMS message'
)

sms.deliver_async(wait_until: Date.tomorrow.noon)

Troubleshooting

If you are using Twilio as a backend, please make sure you add or port a phone number to your account, so that you can use that as a sender option. You won't be able to send messages from any phone number unless you port it to Twilio.

Also, make sure phone numbers are in valid international format: [+47xxxxxxxx, +370xxxxx]

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b feature/my-new-feature)
  3. Write your code and necessary tests
  4. Run your tests (bundle exec rspec)
  5. Commit your changes (git commit -am 'Add some feature')
  6. Push to the branch (git push origin feature/my-new-feature)
  7. Create pull request and be awesome!

Credits

Hyper made this. We're a digital communications agency with a passion for good code, and if you're using this library we probably want to hire you.

cellular's People

Contributors

xmas7 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.