0.0
No commit activity in last 3 years
No release in over 3 years
Ruby gem to send and receive SMS via kavenegar API(rest) kavenegar is great services for send and receive sms this service has a some feature like verification sms or voice service , etc
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.14
~> 10.0
~> 3.0

Runtime

 Project Readme

KaveRestApi

Installation

Add this line to your application's Gemfile:

gem 'kavenegar-ruby'

And then execute:

$ bundle

Or install it yourself as:

$ gem install kavenegar-ruby

How do I configure my app for Kave negar service ?

Using the generator

Run the generator : rails generate kavenegar-ruby install

This will create a initializer at config/initializer/kavenegar-ruby_initializer.rb. You can set api key , default sender , strip emoji , debugmode or format

KaveRestApi.configure do |config|
    
  # To completely ignore debug mode events(No Errors) uncomment this line *optional
  # config.debugmode = false #by default it's true
  
  # It is recommended that you pull your API keys from environment settings. *required
  config.api_key = 'XXXX-XXXX-XXXX-XXXX'
  
  # Default response format is json (you can use xml too). *optional
  config.format  = 'json'
  
  #If you don't set your sender number in your request, this is the default number used instead *required
  config.default_sender  = 'XXXXXXXXXXXX'
  
  # You can remove problematic emojis (like android emojis) and replace with standard emojis listed here:(https://www.webpagefx.com/tools/emoji-cheat-sheet/)
  # config.strip_emoji = 'false' # can include false , true and matcher
  
end

Send Simple SMS

sample (click me)
client=KaveRestApi::SendSimple.new({
        receptor: '09127105568', # can be array ['09127105568','09123456789'] < = 3000 
        message: 'hello my freinds'
        #optional arguments
        # ,sender: 'XXXXXXXXX'
        # ,date: (Date.today + 90)
        # ,type: 0 read this table http://kavenegar.com/rest.html#result-msgmode
        # ,localid: SomeModel.id
})

if client.valid?
    response = client.call
else
    flash[:error]=client.errors.full_messages # is array
    .
    .
end

if response.valid?
    # anything ....
else
    response.full_message_errors # is string 
end

notice: you can use persian and arabic number in receptor.

Receive SMS

sample (click me)
client= KaveRestApi::Receive.new({
    #optional arguments
    linenumber: 'XXXX-XXXX-XXXX-XXXX',
    isread: 0 # unread sms = 0 and read sms = 1
})

if client.valid?
    response = client.call
else
    flash[:error]=client.errors.full_messages # is array
    .
    .
end

if response.valid?
    inbox=response.entries
else
    response.full_message_errors # is string 
end

inbox = > [
        {
            "messageid" : 35850015 , 
            "message" : "خدمات پیام کوتاه کاوه نگار" , 
            "sender" : "09360462960" ,
            "receptor" : "3000202030" ,
            "date" : 1357206241 
        },
        {
            "messageid" : 35850016 , 
            "message" : "خدمات پیام کوتاه کاوه نگار" , 
            "sender" : "09123832441" ,
            "receptor" : "3000202030" ,
            "date" : 1357103281 
        }
    ]

Lookup

sample (click me)
client=KaveRestApi::Lookup.new({
    receptor: 'XXXXXXXXX',
    token: '4334', # only standard digit and english chars
    template: 'auth',
    #optional arguments
    type: 'sms' # or call
    token2: 'blah blah',
    token3: 'blah blah'
})


if client.valid?
    response = client.call
else
    flash[:error]=client.errors.full_messages # is array
    .
    .
end

if response.valid?
    # succecful
else
    #error 
end

License

The gem is available as open source under the terms of the MIT License.