Project

send_sonar

0.01
No commit activity in last 3 years
No release in over 3 years
Provides a clean and simple gem to connect to Sonar
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.15.4, ~> 1.15
~> 2.1
~> 12.1
~> 3.6
>= 3.0.3, ~> 3.0
>= 3.0.1, ~> 3.0

Runtime

>= 2.0.2, ~> 2.0
 Project Readme

Build Status

SendSonar

Sonar is an SMS customer engagement platform that allows companies to have 2-way conversations with their customers over SMS - whether it's for sales, customer service, funnel abandonment, or transactional messages.

Installation

Add this line to your application's Gemfile:

gem 'send_sonar'

And then execute:

$ bundle

Compatibility

Works with Ruby 2.0.0 or greater

Changes

See RELEASE.md

  • Ruby 2.0.0 or greater is now required
  • Included publishable_key in configuration
  • Added support for 5 new API endpoints
  • add_customer has been aliased to add_update_customer

Setup

Initialize the gem by creating an initializer.

  • Your production token can be found if you log into https://sendsonar.com, click the left menu and select Settings, then Company Settings
  • Your sandbox token can be found if you log into or sign up at https://sandbox.sendsonar.com/, click on the left menu and select Settings, then Company Settings
# config/initializers/send_sonar.rb

SendSonar.configure do |config|
  if Rails.env.production?
    config.env = :live
    config.token = ENV['SONAR_PRODUCTION_TOKEN'] || 'YOUR_PRODUCTION_TOKEN'
    config.publishable_key = ENV['SONAR_PRODUCTION_PUBLISHABLE_KEY'] || 'YOUR_PRODUCTION_PUBLISHABLE_KEY'

  elsif Rails.env.staging?
    config.env = :sandbox
    config.token = ENV['SONAR_SANDBOX_TOKEN'] || 'YOUR_SANDBOX_TOKEN'
    config.publishable_key = ENV['SONAR_SANDBOX_PUBLISHABLE_KEY'] || 'YOUR_SANDBOX_PUBLISHABLE_KEY'
  end
end

Usage

The gem offers connections to the following API endpoints:

  • Send Message
  • Add / Update Customer
  • Send Campaign
  • Delete Customer Property
  • Close Customer
  • Get Customer
  • Available Phone Number

Note: Please include a country code for phone numbers (such as +1 for US) in all API calls to us.


Visit Documentation

SendSonar.message_customer(
  text: 'message text',
  to: '+12234567890',
  tag_names: ["attribution"],
  media_url: "http://where_the_pics_live.com/the_bermanator.png"
)

The response is a SendSonar::Message object with accessors for the parameters listed in the documentation.

Important Notes:

  1. If you send a message to a new phone number the API will automatically create a new user.
  2. We prevent companies from sending the exact same message to customers within 7 seconds to prevent spamming and to preserve the great SMS experience.
  3. In the response, "status" will either be "queued" or "unsubscribed". A "queued" status is a successful response, and means that the message should be sent within seconds. An "unsubscribed" status means that the message will not be sent, as the customer has previously unsubscribed from messages from your business.

Visit Documentation

SendSonar.add_update_customer(
  phone_number: "5555555555",
  email: "user@example.com",
  first_name: "john",
  last_name: "doe",
  picture_url: "http://where_the_pics_live.com/the_bermanator.png",
  properties: { great_customer: "true" }
)

Important Notes:

  1. You can send an unlimited number of properties with arbitrary keys and values.
  2. If a customer already exists with the given phone number, that customer will be updated.
  3. The old add_customer method continues to work but was aliased to add_update_customer for clarity.

The response is a SendSonar::Customer object with accessors for the parameters listed in the documentation.


Visit Documentation

SendSonar.send_campaign(
  to: "+15555555555",
  campaign_id: "XXXXXXXX_XXXX_XXXX"
)

The response is a SendSonar::Response object with accessors for the parameters listed in the documentation.


Visit Documentation

SendSonar.delete_customer_property(
  phone_number: "+15555555555",
  property_name: "delete_me"
)

The customer's email can be used instead of phone_number, so the following is also valid:

SendSonar.delete_customer_property(
  email: "user@example.com",
  property_name: "delete_me"
)

The response is a SendSonar::Response object with accessors for the parameters listed in the documentation


Visit Documentation

SendSonar.close_customer(
  phone_number: "+15555555555"
)

The response is a SendSonar::Response object with accessors for the parameters listed in the documentation


Visit Documentation

SendSonar.get_customer(
  phone_number: "+15555555555"
)

The response is a SendSonar::Customer object with accessors for the parameters listed in the documentation


Visit Documentation

SendSonar.available_phone_number

The response is a SendSonar::Response object with accessors for the parameters listed in the documentation

Errors

There are many reasons why requests can fail. There are custom error classes to help you figure out what went wrong.

Note, all request errors inherit from SendSonar::RequestException. Therefore you can rescue all request errors with rescue SendSonar::RequestException. The current supported error classes are:

  • SendSonar::BadToken
  • SendSonar::TokenOrPublishableKeyNotFound
  • SendSonar::NoActiveSubscription
  • SendSonar::ApiDisabledForCompany
  • SendSonar::RequestTimeout
  • SendSonar::ConnectionRefused
  • SendSonar::UnknownRequestError (the server return an error response that your version of the gem does not recognize.)

Support

Email api-help@sendsonar.com if you are having issues with the gem or service.

Contributing

Please file an issue on Github and have a conversation with us before creating a pull request

  1. Fork it ( https://github.com/[my-github-username]/send_sonar/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request