|
| 1 | +module Msg91ruby |
| 2 | + class API |
| 3 | + attr_accessor :auth_key, :senderid |
| 4 | + URL = "http://control.msg91.com" |
| 5 | + def initialize(auth_key, senderid) |
| 6 | + @auth_key = auth_key |
| 7 | + @senderid = senderid |
| 8 | + @url = URL |
| 9 | + end |
| 10 | + |
| 11 | + def send(mobilenos,msg) |
| 12 | + mobile_nos = mobilenos.is_a?(Array) ? mobilenos.join(',') : mobilenos |
| 13 | + params = {:authkey => auth_key, :mobiles => mobile_nos, :message => msg , :sender => senderid ,:route => 1, :response => "json"} |
| 14 | + uri = full_path('/api/sendhttp.php', params) |
| 15 | + response = Net::HTTP.get(uri) |
| 16 | + end |
| 17 | + |
| 18 | + def change_password(passwd, newpasswd) |
| 19 | + params = {:authkey => auth_key, :password => passwd, :newpass => newpasswd, :response => "json"} |
| 20 | + uri = full_path('/api/password.php', params) |
| 21 | + response = Net::HTTP.get(uri) |
| 22 | + end |
| 23 | + |
| 24 | + def balance |
| 25 | + params = {:authkey => auth_key, :type => 1, :response => "json"} |
| 26 | + uri = full_path('/api/balance.php', params) |
| 27 | + response = Net::HTTP.get(uri) |
| 28 | + end |
| 29 | + |
| 30 | + def full_path(path, params) |
| 31 | + encoded_params = URI.encode_www_form(params) |
| 32 | + params_string = [path, encoded_params].join("?") |
| 33 | + URI.parse(@url + params_string) |
| 34 | + end |
| 35 | + end |
| 36 | +end |
0 commit comments