Skip to content

ClickSend/clicksend-ruby

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The official Ruby SDK for ClickSend v3 API

This is the official ClickSend Ruby SDK. Full API documentation can be found here.

Requirements

Installation

Add the gem to your Gemfile:

source 'https://rubygems.org'

gem 'clicksend_client', '~> 1.0.0'

Then install:

bundle install

Install from Git

gem 'clicksend_client', git: 'https://github.com/GIT_USER_ID/GIT_REPO_ID.git'

Getting Started

#!/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)
end

You can find your API key in the ClickSend Dashboard under Account > API Credentials.

Usage

bundle exec ruby send_sms.rb

A 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"
      }
    ]
  }
}

Upgrading the SDK

Update the version in your Gemfile, then run:

bundle update clicksend_client

Available versions are listed on RubyGems.

Documentation

Full SDK and REST API documentation: developers.clicksend.com

Authorization

BasicAuth

  • Type: HTTP basic authentication — pass your ClickSend username and API key as config.username / config.password

Resources

About

ClickSend Ruby SDK

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages