Class: Lleidasms::Client

Inherits:
Gateway show all
Defined in:
lib/lleidasms/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Gateway

#close, #close!, #cmd_acuseack, #cmd_acuseoff, #cmd_acuseon, #cmd_allowanswer, #cmd_bsubmit, #cmd_dst, #cmd_envia, #cmd_fbsubmit, #cmd_filemsg, #cmd_fsubmit, #cmd_fusubmit, #cmd_incomingmoack, #cmd_infonum, #cmd_login, #cmd_mmsmsg, #cmd_msg, #cmd_ping, #cmd_pong, #cmd_quit, #cmd_raw, #cmd_saldo, #cmd_submit, #cmd_tarifa, #cmd_trans, #cmd_usubmit, #cmd_waplink, #conected?, debug, event, #initialize, #last_label, #listener, #new_label, #parser

Constructor Details

This class inherits a constructor from Lleidasms::Gateway

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



12
13
14
# File 'lib/lleidasms/client.rb', line 12

def debug
  @debug
end

#timeoutObject

Returns the value of attribute timeout.



12
13
14
# File 'lib/lleidasms/client.rb', line 12

def timeout
  @timeout
end

Instance Method Details

#acuseObject

Return hash or false

- :id
- :destino
- :timestamp_acuse
- :estado
    * :acked     Entregado a la operadora correctamente
    * :buffred   Telefono apagado o fuera de cobertura
    * :failed    El mensaje no se puede entregar en destino
    * :delivrd   El mesaje ha sido entregado en destino
- :timestamp_envio
- :texto


250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/lleidasms/client.rb', line 250

def acuse
  return false unless acuse?
  row = @acuse.shift
  return {
      id: row[0],
      destino: row[1],
      timestamp_acuse: row[2],
      estado: row[3].to_sym,
      timestamp_envio: row[4],
      texto: row[5] || ''
    }
end

#acuse?Boolean

Returns:

  • (Boolean)


227
228
229
# File 'lib/lleidasms/client.rb', line 227

def acuse?
  @acuse.count > 0
end

#acuseoff(wait = true) ⇒ Object



221
222
223
224
225
# File 'lib/lleidasms/client.rb', line 221

def acuseoff wait = true
  cmd_acuseoff
  return false unless wait_for(last_label) if wait
  true
end

#acuseon(opts = {}) ⇒ Object

opts

- nowait: (default false) no wait for response
- cert: true/false (default false) use certificated confirmations
- lang
    * :es Spanish (default)
    * :ca Catalan
    * :en English
    * :fr French
    * :de German
    * :it Italian
    * :nl Dutch
    * :pt Portuguese
    * :pl Polish
    * :se Swedish


209
210
211
212
213
214
215
216
217
218
219
# File 'lib/lleidasms/client.rb', line 209

def acuseon opts={}
  wait      =!(opts[:nowait]  || false)
  lang      =  opts[:lang]    || false
  cert      =  opts[:cert]    || false
  email     =  opts[:email]   || 'INTERNAL'

  cmd_acuseon lang, cert ? 'D' : false, email

  return false unless wait_for(last_label) if wait
  true
end

#add_addressee(addressees, wait = true) ⇒ Object

Add telephone numbers into the massive send list. It is recommended not to send more than 50 in each call

Return TRUE if ok

- see accepted in *last_addressees_accepted*
- see rejected in *last_addressees_rejected*


116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/lleidasms/client.rb', line 116

def add_addressee addressees, wait = true
  @addressees_accepted = false
  @addressees_rejected = false
  if addressees.kind_of?(Array)
    addressees = addressees.join ' '
  end

  cmd_dst addressees

  while wait && !@addressees_accepted
    wait_for last_label
    return false if !add_addressee_results
  end
end

#allowanswer(on = true, wait = true) ⇒ Object



298
299
300
301
# File 'lib/lleidasms/client.rb', line 298

def allowanswer on = true, wait = true
  cmd_allowanswer on
  wait_for last_label if wait
end

#connect(user, password, timeout = 2.4) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/lleidasms/client.rb', line 14

def connect user, password, timeout = 2.4
  super()
  listener
   user, password
  self.timeout= timeout
  @acuse = []
  @incomingmo = []
  @unknow = []
  @debug = false
end

#debugger(line) ⇒ Object



25
26
27
# File 'lib/lleidasms/client.rb', line 25

def debugger line
  puts line
end

#filemsg(type, data, wait = true) ⇒ Object

Set file content (base64 encded) as message for the massive send list

data file contenten base64 encoded

Available types:

* :jpeg        image JPEG
* :gif         image GIF
* :midi        polyfonic melody MIDI
* :sp_midi     polyfonic melody SP-MIDI
* :amr         sound AMR
* :mp3         sound MP3
* :gpp         video 3GP
* :java        application JAVA
* :symbian     application Symbian


158
159
160
161
162
# File 'lib/lleidasms/client.rb', line 158

def filemsg type, data, wait = true
  cmd_filemsg type, data
  return false unless wait_for(last_label) if wait
  return @response_args
end

#incomingmoObject

Return hash or false

- :id
- :timestamp
- :remitente
- :destino
- :texto


309
310
311
312
313
314
315
316
317
318
319
# File 'lib/lleidasms/client.rb', line 309

def incomingmo
  return false unless incomingmo?
  row = @incomingmo.shift
  return {
      id: row.shift,
      timestamp: row.shift,
      remitente: row.shift,
      destino: row.shift,
      texto: row.join(' ')
    }
end

#incomingmo?Boolean

Returns:

  • (Boolean)


231
232
233
# File 'lib/lleidasms/client.rb', line 231

def incomingmo?
  @incomingmo.count > 0
end

#last_addressees_acceptedObject



131
132
133
# File 'lib/lleidasms/client.rb', line 131

def last_addressees_accepted
  return @addressees_accepted
end

#last_addressees_rejectedObject



135
136
137
# File 'lib/lleidasms/client.rb', line 135

def last_addressees_rejected
  return @addressees_rejected
end

#mmsmsg(type, data, title, message, wait = true) ⇒ Object

Set file content (base64 encded) as message for the massive send list

*data* file contenten base64 encoded
*title* Information title before downloading content
*message* Information text before downloading content

Available types:

* :jpeg        image JPEG
* :gif         image GIF
* :midi        polyfonic melody MIDI
* :sp_midi     polyfonic melody SP-MIDI
* :amr         sound AMR
* :mp3         sound MP3
* :gpp         video 3GP
* :java        application JAVA
* :symbian     application Symbian


178
179
180
181
182
# File 'lib/lleidasms/client.rb', line 178

def mmsmsg type, data, title, message, wait = true
  cmd_mmsmsg type, data, title, message
  return false unless wait_for(last_label) if wait
  return @response_args
end

#msg(message, wait = true) ⇒ Object

Set the message for the massive send list



140
141
142
143
144
# File 'lib/lleidasms/client.rb', line 140

def msg message, wait = true
  cmd_msg message
  return false unless wait_for(last_label) if wait
  return @response_args
end

#saldoObject



29
30
31
32
33
# File 'lib/lleidasms/client.rb', line 29

def saldo
  cmd_saldo
  return false unless wait_for last_label
  return @response_args[0]
end

#send_all(wait = true) ⇒ Object

Send message/file to the massive send list



185
186
187
188
189
190
191
192
193
# File 'lib/lleidasms/client.rb', line 185

def send_all wait = true
  cmd_envia

  if wait
    wait_for last_label
    return false if @response_cmd.eql? 'NOOK'
    return "#{@response_args[0]}.#{@response_args[1]}".to_f
  end
end

#send_sms(number, message, opts = {}) ⇒ Object

number

The telephone number

message

The string to send

opts

- nowait: (default false) no wait for response
- sender: The sender telephone number
- date: Date and time to send message in format YYYYMMDDhhmm[+-]ZZzz
- encode
    * :ascii (default)
    * :binary message is in base64 encoded
    * :base64 message is in base64 encoded
    * :unicode message is in unicode and base64 encoded


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/lleidasms/client.rb', line 56

def send_sms number, message, opts={}
  wait       =!(opts[:nowait] || false)
  encode    =  opts[:encode] || :ascii
  sender    =  opts[:sender] || false
  datetime  =  opts[:date]   || false

  case encode
    when :binary || :base64
      encode = 'B'
    when :unicode
      encode = 'U'
    else # :ascii
      encode = ''
  end

  if sender
    sender = "#{sender} "
    custom = 'F'
  else
    custom = ''
  end

  if datetime
    datetime = "#{datetime} "
    date = 'D'
  else
    date = ''
  end

  cmd_raw "#{date}#{custom}#{encode}SUBMIT", "#{datetime}#{sender}#{number} #{message}"

  if wait
    wait_for last_label
    return false if @response_cmd.eql? 'NOOK'
    return "#{@response_args[0]}.#{@response_args[1]}".to_f
  end
end

number

The telephone number

url

The URL to content. Usually a image, tone or application

message

Information text before downloading content


100
101
102
103
104
105
106
107
108
# File 'lib/lleidasms/client.rb', line 100

def send_waplink number, url, message
  cmd_waplink number, url, message

  if wait
    wait_for last_label
    return false if @response_cmd.eql? 'NOOK'
    return "#{@response_args[0]}.#{@response_args[1]}".to_f
  end
end

#tarifa(number) ⇒ Object

number

The telephone number


37
38
39
40
41
# File 'lib/lleidasms/client.rb', line 37

def tarifa number
  cmd_tarifa number
  return false unless wait_for last_label
  return @response_args
end

#trans(action, wait = true) ⇒ Object

  • wait: (default false) no wait for response

  • action

    * :begin
    * :end
    * :abort
    


274
275
276
277
278
279
280
281
282
283
284
# File 'lib/lleidasms/client.rb', line 274

def trans action, wait = true
  return false unless cmd_trans action
  if wait
    wait_for last_label
    return false if @response_cmd.eql? 'NOOK'
    return false if @response_args[1].eql? 'NOOK'
    return true if @response_args[0].eql? 'INICIAR'
    return true if @response_args[0].eql? 'ABORTAR'
    return "#{@response_args[2]}.#{@response_args[3]}".to_f
  end
end

#trans_abort(wait = true) ⇒ Object



294
295
296
# File 'lib/lleidasms/client.rb', line 294

def trans_abort wait = true
  trans :abort, wait
end

#trans_begin(wait = true) ⇒ Object



286
287
288
# File 'lib/lleidasms/client.rb', line 286

def trans_begin wait = true
  trans :begin, wait
end

#trans_end(wait = true) ⇒ Object



290
291
292
# File 'lib/lleidasms/client.rb', line 290

def trans_end wait = true
  trans :end, wait
end

#unknowObject

Return array or false



264
265
266
267
# File 'lib/lleidasms/client.rb', line 264

def unknow
  return false unless unknow?
  @unknow.shift
end

#unknow?Boolean

Returns:

  • (Boolean)


235
236
237
# File 'lib/lleidasms/client.rb', line 235

def unknow?
  @unknow.count > 0
end