Class: SmsClub::AsyncClient

Inherits:
Client
  • Object
show all
Defined in:
lib/sms-club/async.rb

Instance Attribute Summary collapse

Attributes inherited from Client

#from, #password, #transliterate, #user_name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Client

#send_many, #send_one, #status_for, #statuses_for

Constructor Details

#initialize(*args) ⇒ AsyncClient

Returns a new instance of AsyncClient.



12
13
14
15
# File 'lib/sms-club/async.rb', line 12

def initialize(*args)
  @init_args = args
  super
end

Instance Attribute Details

#queueObject

Returns the value of attribute queue.



10
11
12
# File 'lib/sms-club/async.rb', line 10

def queue
  @queue
end

Class Method Details

.perform(init_args, message, msg_options) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/sms-club/async.rb', line 31

def self.perform(init_args, message, msg_options)
  # Ugliness level 99. Needed to pass args to constructor
  # when Resque instantiate AsyncClient
  user_name, password, options = init_args

  # Resque serializes params to json, so symbols are
  # converted to strings, which is not what we want
  puts new(user_name, password, options.symbolize_keys!)
          .send_many(message, msg_options.symbolize_keys!)
end

.queueObject



17
18
19
# File 'lib/sms-club/async.rb', line 17

def self.queue
  'sms_club'
end

Instance Method Details

#send_async(message, options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/sms-club/async.rb', line 21

def send_async(message, options = {})
  begin
    Resque.enqueue(self.class, @init_args, message, options)
  rescue Redis::CannotConnectError => e
    warn e
    warn 'Can not connect to redis server. Falling back to synchronous mode.'
    send_many message, options
  end
end