Skip to main content

Prerequisites

Before you begin, make sure you have:

  • A SpringEdge account with an API key and your SMS service URL (<SMS_SERVICE_URL>, shared after sign-up)
  • Ruby 2.7 or higher (Rails 6+ for the Rails example)
  • No external gems required — uses Ruby's built-in net/http
  • A DLT-registered sender ID and approved template (for India)

Zero Dependencies

Uses Ruby's built-in net/http — no gems needed

Rails Ready

Drop-in service class for any Rails application

HTTPS + API Key

API key sent as a request parameter over HTTPS; restrict it to whitelisted IPs

require 'net/http'
require 'json'
require 'uri'

api_key = "YOUR_API_KEY"
uri = URI("<SMS_SERVICE_URL>/api/web/send/")

params = {
  apikey:  api_key,
  sender:  "SEDEMO",
  to:      "9900XXXXXX",
  message: "Your OTP is 482910",
  format:  "json"
}

# Sends an application/x-www-form-urlencoded POST
response = Net::HTTP.post_form(uri, params)

puts "Status: #{response.code}"
puts "Response: #{response.body}"

# Success response (format=json):
# {"groupID": 61, "MessageIDs": "61-1", "status": "AWAITED-DLR"}
#
# Errors are plain text, e.g. "Invalid Sender ID"
# or "Insufficient Credits"

STANDARD RUBY

Using net/http

This example uses Ruby's built-in net/http library to send a form-encoded POST to the SpringEdge send endpoint. The API key is passed as the apikey parameter; no external gems are required. Replace <SMS_SERVICE_URL> with your SMS service URL, shared after sign-up.

With format=json the API returns a groupID and MessageIDs, which you can use to check delivery status via the status API or receive it on a callback URL. Errors come back as plain-text messages — see the error list.

Steps:

  1. Replace YOUR_API_KEY with your SpringEdge API key
  2. Set the recipient number, your DLT-approved sender ID, and a message that matches an approved template
  3. Run: ruby send_sms.rb

RAILS INTEGRATION

Rails Service Class

For Rails applications, create a service class in app/services/ that encapsulates the SMS sending logic. Call it from any controller, model callback, or background job.

Use it in a controller: SmsService.send_otp("9900XXXXXX", "482910")

# app/services/sms_service.rb
require "net/http"
require "json"

class SmsService
  API_URL = "#{ENV["SPRINGEDGE_SMS_SERVICE_URL"]}/api/web/send/"
  API_KEY = ENV["SPRINGEDGE_API_KEY"]

  def self.send_otp(phone, otp)
    params = {
      apikey:  API_KEY,
      sender:  "SEDEMO",
      to:      phone,
      message: "Your OTP is #{otp}",
      format:  "json"
    }

    response = Net::HTTP.post_form(URI(API_URL), params)
    JSON.parse(response.body)
  rescue JSON::ParserError
    # Errors are returned as plain text
    { "error" => response.body }
  end
end

What You Can Build

Devise OTP

Add SMS-based two-factor authentication to your Rails application's Devise login flow.

Sidekiq Jobs

Send SMS from background jobs using Sidekiq or Active Job for non-blocking message delivery.

Order Notifications

Trigger order confirmation and shipping update SMS from Rails model callbacks or controller actions.

API Webhooks

Pass a callbackurl and label when sending, then build a Rails endpoint that reads label, recipient and status to update message status in your database.