Skip to content

Repository files navigation

ClickSend Ruby SDK

Ruby License: MIT API: v3

Official Ruby gem for the ClickSend API — send SMS, MMS, voice and email messages, run SMS and MMS campaigns, manage numbers, contacts and subaccounts, and pull delivery receipts and reporting through a single authenticated HTTPS client.

This library is generated from ClickSend's official OpenAPI v3 specification and is maintained by ClickSend. It covers every endpoint of the ClickSend REST API.

Features

  • Messaging — SMS, MMS, voice / text-to-speech, transactional email, email-to-SMS
  • Campaigns — SMS and MMS campaigns
  • Numbers & sender IDs — dedicated numbers, own numbers, alpha tags, default senders
  • Contacts — contact lists, contacts and the address book
  • Account & billing — account details, transactions, subaccounts, referrals, reseller accounts
  • Delivery & reporting — delivery receipts, inbound messages, statistics
  • Extras — URL shortening, file uploads, number verification, international messaging
  • Typed models for every request and response
  • HTTP Basic auth with your ClickSend username and API key
  • Identifiable traffic — requests are sent with a ClickSend-SDK/<version>/ruby User-Agent by default
  • MIT licensed

Requirements

  • Ruby 2.7 or newer

Installation

Add this to your Gemfile:

gem 'clicksend_client', :git => 'https://github.com/ClickSend/clicksend-ruby-v2.git'

Then run:

bundle install

Authentication

Every API class authenticates with HTTP Basic auth using your ClickSend username and API key, both available from the ClickSend Dashboard. Supply them through environment variables rather than hard-coding them:

export CLICKSEND_USERNAME="your-username"
export CLICKSEND_API_KEY="your-api-key"

Quickstart

require 'clicksend_client'

ClickSend.configure do |config|
  config.username = ENV['CLICKSEND_USERNAME']
  config.password = ENV['CLICKSEND_API_KEY']
end

api_instance = ClickSend::SmsApi.new
send_sms_request = ClickSend::SendSmsRequest.new(
  messages: [
    { source: 'sdk', body: 'Hello from ClickSend!', to: '+61411111111' }
  ]
)

begin
  result = api_instance.send_sms(send_sms_request: send_sms_request)
  p result
rescue ClickSend::ApiError => e
  puts "Exception when calling SmsApi->send_sms: #{e}"
end

More Examples

View account details

api_instance = ClickSend::ManagementApi.new

begin
  result = api_instance.view_account_details
  p result
rescue ClickSend::ApiError => e
  puts "Exception when calling ManagementApi->view_account_details: #{e}"
end

Send an MMS

api_instance = ClickSend::MmsApi.new
send_mms_request = ClickSend::SendMmsRequest.new(
  media_file: 'https://clicksend.com/logo.png',
  messages: [
    { source: 'sdk', to: '+61411111111', from: 'sdk', subject: 'Hello', body: 'Hello from ClickSend!' }
  ]
)

begin
  result = api_instance.send_mms(send_mms_request: send_mms_request)
  p result
rescue ClickSend::ApiError => e
  puts "Exception when calling MmsApi->send_mms: #{e}"
end

Configuration

ClickSend.configure do |config|
  config.username = ENV['CLICKSEND_USERNAME']
  config.password = ENV['CLICKSEND_API_KEY']
  # Override the API base URL (default: https://rest.clicksend.com).
  config.host = 'rest.clicksend.com'
  config.scheme = 'https'
  config.timeout = 30
end

Error Handling

Non-2xx responses raise ClickSend::ApiError:

begin
  result = api_instance.send_sms(send_sms_request: send_sms_request)
rescue ClickSend::ApiError => e
  e.code           # HTTP status code
  e.response_body  # raw error payload from the API
  e.response_headers
end

Documentation

Versioning

This gem follows semantic versioning. Breaking changes are released as major versions.

Support

License

Released under the MIT License.


Keywords: clicksend, sms, sms api, send sms, bulk sms, text message, texting, mms, mms api, voice, voice call, text to speech, tts, ivr, email to sms, sms campaign, mms campaign, url shortening, number verification, messaging, notifications, otp, 2fa, two factor authentication, transactional sms, marketing sms, appointment reminders, alerts, ruby, rails, gem, rest api, clicksend sdk

About

Repo for a new and improved ruby SDKs

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages