Class: Smsc
Instance Method Summary collapse
-
#active? ⇒ Boolean
Check the server status, return true if it’s active, false in other case.
-
#balance ⇒ Object
Check the balanca on Smsc return the value balance or false in case of error.
-
#cancel_queue ⇒ Object
Cancel all messages enqueued.
-
#enqueued(priority = 0) ⇒ Object
Chek the messages enqueued to send later by default the parameter is 0 param priority 0:all 1:low 2:middle 3:high return an array with all messages enqueued with te priority specified.
- #errors? ⇒ Boolean
-
#initialize(account, apiKey) ⇒ Smsc
constructor
A new instance of Smsc.
-
#received(lastId = nil) ⇒ Object
############################################### ######## Methods for making queries ######## ###############################################.
-
#send(num, msj, time = nil) ⇒ Object
########################################### ######## Method to send a SMS ######### ###########################################.
-
#sent(lastId = nil) ⇒ Object
Return the lastest 30 smsc messages sent.
-
#status ⇒ Object
Check the server status Return hash with the keys :code, :message code: is the status of the server response, 200 its oky! message: is the message if the query to the serve has problems.
-
#valid_phone?(number) ⇒ Boolean
Valid the phone number Return true if is a valid phone number.
Constructor Details
#initialize(account, apiKey) ⇒ Smsc
Returns a new instance of Smsc.
6 7 8 9 |
# File 'lib/smsc.rb', line 6 def initialize(account, apiKey) @alias = account @apiKey = apiKey end |
Instance Method Details
#active? ⇒ Boolean
Check the server status, return true if it’s active, false in other case
28 29 30 31 32 33 34 35 36 |
# File 'lib/smsc.rb', line 28 def active? response = run('estado') success = response["code"] == 200 raise 'NoSuccessCode' if !success success rescue => e error(response["code"]) false end |
#balance ⇒ Object
Check the balanca on Smsc return the value balance or false in case of error
56 57 58 59 60 61 62 |
# File 'lib/smsc.rb', line 56 def balance response = run('saldo') response["data"]["mensajes"] rescue => e error(response["code"]) false end |
#cancel_queue ⇒ Object
Cancel all messages enqueued
67 68 69 70 71 72 73 74 75 |
# File 'lib/smsc.rb', line 67 def cancel_queue response = run('cancelqueue') success = response["code"] == 200 raise 'NoSuccessCode' if !success success rescue => e error(response["code"]) false end |
#enqueued(priority = 0) ⇒ Object
Chek the messages enqueued to send later by default the parameter is 0 param priority 0:all 1:low 2:middle 3:high return an array with all messages enqueued with te priority specified
83 84 85 86 87 88 89 |
# File 'lib/smsc.rb', line 83 def enqueued(priority=0) response = run('encolados', nil, nil, nil, nil, priority) response["data"]["mensajes"] rescue => e error(response["code"]) false end |
#errors? ⇒ Boolean
176 177 178 |
# File 'lib/smsc.rb', line 176 def errors? errors.any? end |
#received(lastId = nil) ⇒ Object
############################################### ######## Methods for making queries ######## ###############################################
Return the lastest 30 messages received
You can specified an URL on www.smsc.com.ar/usuario/api/ then the App will make a get to the url specified, that means you receive a new message
you can add a paramater ‘lastId’ by default none, and you can check all messages recevided from the id specified.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/smsc.rb', line 133 def received(lastId=nil) response = run('recibidos', lastId) response["data"].map do || { id: ["id"], date: ["fechahora"], message: ["mensaje"], from: ["de"], phone: ["linea"] } end rescue => e error(response["code"]) false end |
#send(num, msj, time = nil) ⇒ Object
########################################### ######## Method to send a SMS ######### ###########################################
take 3 params, num, msj time num: is the phone number with code area included by the fault the api of Sms
require the phone number on format xxxx-xxxxxxxxx, but, if you have other
format, you can check it with the method valid_phone?(phone_number)
msj: is a string with the message to send, a message has “180(CHECK)”
characters, if you include more characters, so you're sending two messages
time: this by default is nil, in case you specified this parameter
the message will be enqueue at the datetime specified
with the format "YYYY-MM-DD HH:MM:SS"
Return true if the message was sended, false in other case
108 109 110 111 112 113 114 115 116 |
# File 'lib/smsc.rb', line 108 def send(num, msj, time=nil) response = run('enviar', nil, num, msj, time) success = response["code"] == 200 raise 'NoSuccessCode' if !success success rescue => e error(response["code"]) false end |
#sent(lastId = nil) ⇒ Object
Return the lastest 30 smsc messages sent
you can add a paramater ‘lastId’ by default none, and you can check all messages sent from the id specified.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/smsc.rb', line 155 def sent(lastId=nil) response = run('enviados', lastId) response["data"].map do || { id: ["id"], date: ["fechahora"], message: ["mensaje"], recipients: ["destinatarios"].map do |recipient| { code_area: recipient["prefijo"], phone: recipient["fijo"], status: recipient["enviado"]["estado_desc"] } end } end rescue => e error(response["code"]) false end |
#status ⇒ Object
Check the server status Return hash with the keys :code, :message code: is the status of the server response, 200 its oky! message: is the message if the query to the serve has problems
44 45 46 47 48 49 50 |
# File 'lib/smsc.rb', line 44 def status response = run('estado') { code: response["code"], message: response["message"] } rescue => e error(response["code"]) false end |
#valid_phone?(number) ⇒ Boolean
Valid the phone number Return true if is a valid phone number
15 16 17 18 19 20 21 22 23 |
# File 'lib/smsc.rb', line 15 def valid_phone?(number) response = run('evalnumero', nil, number) begin response["data"]["estado"] rescue => e error(response["code"]) false end end |