Coder Social home page Coder Social logo

kavenegar / kavenegar-ruby Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mm580486/kave_rest_api

2.0 3.0 1.0 377 KB

Kavenegar API Client Writen In Ruby

Home Page: https://kavenegar.com/rest.html

License: MIT License

Ruby 99.68% Shell 0.32%
kavenegar-ruby kavenegar-sdk sdk rest api sms

kavenegar-ruby's Introduction

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.

kavenegar-ruby's People

Contributors

mm580486 avatar bgsrb avatar

Stargazers

$enaxor avatar Muhammadreza Haghiri avatar

Watchers

James Cloos avatar Ardavan avatar  avatar

Forkers

jmimi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.