This is the official ClickSend Ruby SDK. Full API documentation can be found here.
- Ruby >= 2.7 (install via Homebrew:
brew install ruby) - Bundler (
gem install bundler) - A ClickSend account with an API key
Add the gem to your Gemfile:
source 'https://rubygems.org'
gem 'clicksend_client', '~> 1.0.0'Then install:
bundle installgem 'clicksend_client', git: 'https://github.com/GIT_USER_ID/GIT_REPO_ID.git'#!/usr/bin/env ruby
# frozen_string_literal: true
require 'clicksend_client'
# — Credentials ————————————————————————————————————————————————————————————————
USERNAME = 'your_username'
API_KEY = 'your_api_key'
# — Message details ————————————————————————————————————————————————————————————
FROM_NUMBER = '' # E.164 format e.g. "+61400000000", or leave empty for default sender ID
TO_NUMBER = '+61411111111' # Recipient in E.164 format
MESSAGE = 'Hello from ClickSend Ruby SDK!'
# — Configure the client ———————————————————————————————————————————————————————
ClickSendClient.configure do |config|
config.username = USERNAME
config.password = API_KEY
end
# — Build and send the SMS —————————————————————————————————————————————————————
sms_message = ClickSendClient::SmsMessage.new(
to: TO_NUMBER,
from: FROM_NUMBER,
body: MESSAGE,
source: 'ruby'
)
collection = ClickSendClient::SmsMessageCollection.new(messages: [sms_message])
begin
api = ClickSendClient::SMSApi.new
response = api.sms_send_post(collection)
puts "Success: #{response}"
rescue ClickSendClient::ApiError => e
puts "API error: #{e.message}"
puts "Response body: #{e.response_body}" if e.respond_to?(:response_body)
endYou can find your API key in the ClickSend Dashboard under Account > API Credentials.
bundle exec ruby send_sms.rbA successful response looks like:
{
"http_code": 200,
"response_code": "SUCCESS",
"response_msg": "Messages queued for delivery.",
"data": {
"total_price": 0.891,
"total_count": 1,
"queued_count": 1,
"messages": [
{
"status": "SUCCESS",
"to": "+61411111111",
"from": "ClickSend",
"body": "Hello from ClickSend Ruby SDK!",
"message_price": "0.8910",
"carrier": "Telstra",
"country": "AU"
}
]
}
}Update the version in your Gemfile, then run:
bundle update clicksend_clientAvailable versions are listed on RubyGems.
Full SDK and REST API documentation: developers.clicksend.com
- Type: HTTP basic authentication — pass your ClickSend username and API key as
config.username/config.password