Send SMS with Ruby
To send bulk, single, or OTP SMS using the iletimerkezi.com API, you can use the Ruby client prepared for sending SMS and reporting operations.
This library is developed by İrfan Subaş https://github.com/isubas/ileti_merkezi. We thank him for his contribution to İleti Merkezi. Don't forget to star the repo.
For detailed documentation and descriptions of all methods in the library, please refer to https://github.com/isubas/ileti_merkezi.
Kurulum
Add this line to your Gemfile.
gem 'ileti_merkezi'
Then run the following command:
$ bundle
Or you can install it with the following command:
$ gem install ileti_merkezi
Kullanım
Yapılandırma
Create a file named config/initializers/ileti_merkezi_configure.rb
in your Rails application and paste the following code into it.
If you want to authenticate using a username and password, fill in the username and password fields. If you want to use token-based authentication, fill in the public_key and secret_key fields.
If all four fields are filled, the system will perform token-based authentication.
You can create public and secret key information from https://www.iletimerkezi.com/user/preferences.
IletiMerkezi.configure do |config|
# Default: https://api.iletimerkezi.com/v1'
config.endpoint = 'https://api.iletimerkezi.com/v1'
config.sender = 'FOO'
# optional
config.request_overrides = {
use_ssl: true, # default false
verify_mode: OpenSSL::SSL::VERIFY_PEER,
read_timeout: 30, # default 30
open_timeout: 30 # default 30
}
# Authentication: username and password
config.username = 'username'
config.password = 'password'
# Authentication: token-based
config.public_key = 'public_key'
config.secret_key = 'secret_key'
end
Or you can configure it with environment variables. See: .env
IM_ENDPOINT = 'https://api.iletimerkezi.com/v1' # Default: https://api.iletimerkezi.com/v1
# Authentication: username and password
IM_USERNAME = 'username'
IM_PASSWORD = 'password'
# Authentication: token-based
IM_PUBLIC_KEY = 'public_key'
IM_SECRET_KEY = 'secret_key'
IM_SENDER = 'SENDER'
SMS Gönderme - (Tek Mesaj - Çoklu Alıcı)
args = {
send_datetime: '15/01/2017 12:00', # Opsiyonel
sender: 'TEST', # Opsiyonel
phones: ['0555 555 00 01', '0555 555 00 02'],
text: 'Test Mesajı'
}
# return IletiMerkezi::Response
response = IletiMerkezi.send(args)
# veya
sms = IletiMerkezi::Sms.new(args)
response = sms.send
response.code # return 200
response.body # http raw body
response.message # return status message
response.error? # return true or false
response.to_h
# return hash
{
:status => {
:code => "200",
:message => "İşlem başarılı"
},
:order => {
:id => "order_id"
}
}
SMS Gönderme (Çoklu Mesaj - Çoklu Alıcı)
args = {
send_datetime: '15/01/2017 12:00', # Opsiyonel
sender: 'TEST', # Opsiyonel
messages: [
{
text: 'Test Mesajı Bir',
phones: ['0555 555 00 01', '0555 555 00 02'],
},
{
text: 'Test Mesajı İki',
phones: ['0555 555 00 03', '0555 555 00 04'],
}
]
}
# return IletiMerkezi::Response
response = IletiMerkezi.send(args)
# veya
sms = IletiMerkezi::Sms.new(args)
response = sms.send
response.code # return 200
response.body # http raw body
response.message # return status message
response.error? # return true or false
response.to_h
# return hash
{
:status => {
:code => "200",
:message => "İşlem başarılı"
},
:order => {
:id => "order_id"
}
}