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?, #do_event, event, #initialize, #last_label, #listener, #new_label, #parser, #run_event, #run_event_for

Constructor Details

This class inherits a constructor from Lleidasms::Gateway

Instance Attribute Details

#timeoutObject

Returns the value of attribute timeout.



10
11
12
# File 'lib/lleidasms/client.rb', line 10

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


238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/lleidasms/client.rb', line 238

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)


219
220
221
# File 'lib/lleidasms/client.rb', line 219

def acuse?
  @acuse.count > 0
end

#acuseoff(wait = true) ⇒ Object



213
214
215
216
217
# File 'lib/lleidasms/client.rb', line 213

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


201
202
203
204
205
206
207
208
209
210
211
# File 'lib/lleidasms/client.rb', line 201

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*


108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/lleidasms/client.rb', line 108

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



280
281
282
283
# File 'lib/lleidasms/client.rb', line 280

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

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



12
13
14
15
16
17
18
19
# File 'lib/lleidasms/client.rb', line 12

def connect user, password, timeout = 2.4
  super()
  listener
   user, password
  self.timeout= timeout
  @acuse = []
  @incomingmo = []
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


150
151
152
153
154
# File 'lib/lleidasms/client.rb', line 150

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


291
292
293
294
295
296
297
298
299
300
301
# File 'lib/lleidasms/client.rb', line 291

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)


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

def incomingmo?
  @incomingmo.count > 0
end

#last_addressees_acceptedObject



123
124
125
# File 'lib/lleidasms/client.rb', line 123

def last_addressees_accepted
  return @addressees_accepted
end

#last_addressees_rejectedObject



127
128
129
# File 'lib/lleidasms/client.rb', line 127

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


170
171
172
173
174
# File 'lib/lleidasms/client.rb', line 170

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



132
133
134
135
136
# File 'lib/lleidasms/client.rb', line 132

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

#saldoObject



21
22
23
24
25
# File 'lib/lleidasms/client.rb', line 21

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



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

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


48
49
50
51
52
53
54
55
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
# File 'lib/lleidasms/client.rb', line 48

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


92
93
94
95
96
97
98
99
100
# File 'lib/lleidasms/client.rb', line 92

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


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

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
    


256
257
258
259
260
261
262
263
264
265
266
# File 'lib/lleidasms/client.rb', line 256

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



276
277
278
# File 'lib/lleidasms/client.rb', line 276

def trans_abort wait = true
  trans :abort, wait
end

#trans_begin(wait = true) ⇒ Object



268
269
270
# File 'lib/lleidasms/client.rb', line 268

def trans_begin wait = true
  trans :begin, wait
end

#trans_end(wait = true) ⇒ Object



272
273
274
# File 'lib/lleidasms/client.rb', line 272

def trans_end wait = true
  trans :end, wait
end