Skip to content
Rails Initializer for the Nexmo Ruby Gem
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
lib Delegate API methods to client. Apr 25, 2019
spec
.gitignore pushing up Feb 15, 2019
.rspec removed dummy folder and added test for creation of initializer Feb 18, 2019
CHANGES.md added changelog Feb 19, 2019
Gemfile pushing up Feb 15, 2019
LICENSE
README.md Add Version Badge to README Apr 30, 2019
Rakefile pushing up Feb 15, 2019
nexmo_rails.gemspec added dotenv-rails as a dependency Apr 10, 2019

README.md

Nexmo Rails Gem

Gem Version

This is the Nexmo Rails Gem for Nexmo's API. To use it you'll need a Nexmo account. Sign up for free at nexmo.com.

Requirements

Nexmo Rails requires:

Installation

To install the Nexmo Rails gem, add it, along with dotenv-rails, to your project's Gemfile:

gem 'nexmo_rails'
gem 'dotenv-rails'

The dotenv-rails gem assists with environment variable management and utilization.

Then, run bundle install from the command line.

Usage

The Nexmo Rails gem will initialize a new instance of the Nexmo client inside your Rails application and make it globally accessible. To make this happen, first add the desired Nexmo credentials to your .env file. For example, if you are using only the API_KEY and API_SECRET, then add the following:


NEXMO_API_KEY = your_api_key
NEXMO_API_SECRET = your_api_secret

If you are also using a SIGNATURE, APPLICATION_ID and/or a PRIVATE_KEY, then add them as appropriate to your .env file:


NEXMO_API_SIGNATURE = your_signature
NEXMO_PRIVATE_KEY = your_private_key_file_path
NEXMO_APPLICATION_ID = your_application_id

To initialize your global Nexmo client in your application, run the following from your terminal:

rails generate nexmo_initializer

This will create a ./config/initializers/nexmo.rb file in your application that will make the variable Nexmo available across your application, which contains your fully credentialed Nexmo client.

At this point, you can access any of the Nexmo APIs by simply referring to Nexmo in your code. For example, instead of first initializing a Nexmo client with your credentials to send an SMS, all you need to do is add the following to your application:

Nexmo.sms.send(from: 'YOUR_NUMBER', to: 'NUMBER', text: 'Hello world')

More information on the Nexmo Ruby client library and how to use it with the Nexmo APIs can be found here.

License

This project is under the MIT License.

You can’t perform that action at this time.