This client allows you to send sms using Codec Fast SMS API.
Add this line to your application's Gemfile:
gem 'codec_fast_sms'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install codec_fast_sms
Client must be configured before use. Configuration fields are as:
Field | Description |
---|---|
api_host | Root url of the API. |
username | Your API username. |
password | Your API password. |
sender | Sms sender title. |
Create a file in the config/initializers
directory and configure client in this file as below:
# config/initializers/codec_fast_sms.rb
CodecFastSms.configure do |config|
config.api_host = 'https://fastsms.api.example.com'
config.username = 'mysuperapiuser'
config.password = 'mYsupeRsecreTqassworld'
config.sender = 'MYSUPERCOMPANY'
end
You can define multiple configurations separated by profile. To do this, you must pass the profile parameter to the configure
definition.
If the profile name is not pass in the configuration, it defaults to use :default
.
In this example, to send sms , profile name specified as settings
.
# config/initializers/codec_otp_settings.rb
CodecFastSms.configure(:otp_user) do |config|
config.api_host = 'https://fastsms.api.example.com'
config.username = 'mysuperapiotpuser'
config.password = 'mYsupeRsecreTqassworldforOtP'
config.sender = 'MYSUPERCOMPANY'
end
Initialize a client object before starting process.
client = CodecFastSms::Client.new
To send sms, call the method deliver
.
phone = '905991112233'
message = 'Dear Hayri Gülümser, your membership has been activated.'
client.deliver(phone, message)
puts client.response
Use attributes to set permission parameters:
attributes = { optionalParameters: '{ DisablePermissionFilter: true }' }
client = CodecFastSms::Client.new(attributes: attributes)
Use attributes to set IYS parameters:
iys_message_type
: must take the value TICARI
or BILGILENDIRME
. In case the value is not given, it takes BILGILENDIRME
value by default.
iys_brand_code
: If iys_message_type
is set as TICARI
, it must be filled.
iys_recipient_type
: If iys_message_type
is set as TICARI
, it must be filled.
attributes = {
optionalParameters: '{ DisablePermissionFilter: true }',
iys_message_type: 'TICARI'
iys_brand_code: 'BC1'
iys_recipient_type: 'RT1'
}
client = CodecFastSms::Client.new(attributes: attributes)
We can pass the profile argument on client initialization to use different configuration.
client = CodecFastSms::Client.new(profile: :dynamic_settings)
client.deliver(phone, message)
Bug reports and pull requests are welcome on GitHub at https://github.com/sertangulveren/codec_fast_sms.