This gem provides a simple and intuitive Ruby API wrapper for interacting with the Semaphore API. With this gem, you can easily send messages, manage accounts, and perform other operations using the Semaphore API.
Note: This gem has been renamed from
ruby-semaphoretosemaphore-sms-ruby, and the client namespace is nowSemaphoreSMS(previouslySemaphore). Update your Gemfile and code accordingly if you were using the previous names.
Add this line to your application's Gemfile:
gem "semaphore-sms-ruby"And then execute:
$ bundleOr install it yourself as:
$ gem install semaphore-sms-ruby- Get your API key from https://semaphore.co/account
For a quick test you can pass your token directly to a new client:
client = SemaphoreSMS::Client.new(api_key: '[API KEY]', sender_name: '[SENDER NAME]')
# Sending a message
client.messages.send(
message: '[YOUR MESSAGE]',
number: '[NUMBER]'
)
# Sending a bulk message
client.messages.bulk_send(
message: '[YOUR MESSAGE]',
numbers: ['NUMBER', 'NUMBER', 'NUMBER', 'NUMBER']
)
# Sending a priority message
client.priority.send(
message: '[YOUR MESSAGE]',
number: '[NUMBER]'
)
# Sending an OTP
client.otp.send(
message: 'Thanks for registering. Your OTP Code is {otp}.',
number: '[NUMBER]',
code: 1234
)
# Retrieving a message
client.messages.retrieve(123)
# Listing messages
client.messages.list(limit: 100, page: 1)
# Account
client.account.retrieve
client.account.transactions(limit: 100, page: 1)
client.account.sender_names
client.account.usersTo enhance your setup, you can configure the gem with your API keys in a more secure manner, such as in a semaphore_sms.rb initializer file. This approach prevents hardcoding secrets directly into your codebase. Instead, consider using a gem like dotenv to safely pass the keys into your environments.
# config/initializers/semaphore_sms.rb
SemaphoreSMS.configure do |config|
config.api_key = ENV.fetch("SEMAPHORE_API_KEY")
config.sender_name = ENV.fetch("SEMAPHORE_SENDERNAME")
endAfter configuring the API key, you can simply create a new client:
client = SemaphoreSMS::Client.new
client.messages.send(
message: '[YOUR MESSAGE]',
number: '[NUMBER]'
)bundle install
bundle exec rake # specs + rubocop
bundle exec rake spec
bundle exec rake rubocopContributions are welcome! Please follow the guidelines outlined in the CONTRIBUTING.md file.
The gem is available as open source under the terms of the MIT License.