Prerequisites
Before you begin, make sure you have:
- A SpringEdge account with an API key
- 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 + Bearer Auth
Secure API key authentication over TLS
require 'net/http'
require 'json'
require 'uri'
api_key = "YOUR_API_KEY"
uri = URI("https://api.springedge.com/v1/sms/send")
payload = {
to: "+919876543210",
sender_id: "SPREDG",
message: "Your OTP is 482910",
type: "transactional"
}
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri)
request["Content-Type"] = "application/json"
request["Authorization"] = "Bearer #{api_key}"
request.body = payload.to_json
response = http.request(request)
puts "Status: #{response.code}"
puts "Response: #{response.body}"
# Response:
# {
# "status": "success",
# "message_id": "msg_a1b2c3d4",
# "credits_used": 1
# }
STANDARD RUBY
Using net/http
This example uses Ruby's built-in net/http library to send an SMS through the SpringEdge API. No external gems are required — this works in any Ruby environment out of the box.
The API returns a JSON response with the message ID which you can use to track delivery status via webhooks or the status API.
Steps:
- Replace
YOUR_API_KEYwith your SpringEdge API key - Set the recipient number, sender ID, and message
- 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("+919876543210", "482910")
# app/services/sms_service.rb
class SmsService
API_URL = "https://api.springedge.com"
"/v1/sms/send"
API_KEY = ENV["SPRINGEDGE_API_KEY"]
def self.send_otp(phone, otp)
payload = {
to: phone,
sender_id: "SPREDG",
message: "Your OTP is #{otp}",
type: "transactional"
}
uri = URI(API_URL)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
req = Net::HTTP::Post.new(uri)
req["Content-Type"] = "application/json"
req["Authorization"] = "Bearer #{API_KEY}"
req.body = payload.to_json
response = http.request(req)
JSON.parse(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
Build a Rails endpoint to receive delivery reports and update message status in your database in real time.
