Class: Flapjack::Gateways::SmsTwilio

Inherits:
Object
  • Object
show all
Includes:
Utility
Defined in:
lib/flapjack/gateways/sms_twilio.rb

Constant Summary collapse

TWILIO_DEFAULT_HOST =

curl -X POST ‘api.twilio.com/2010-04-01/Accounts/[AccountSid]/Messages.json’ \ –data-urlencode ‘To=+61414123456’ \ –data-urlencode ‘From=+61414123456’ \ –data-urlencode ‘Body=Sausage’ \ -u [AccountSid]:

'api.twilio.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utility

#hashify, #load_template, #local_timezone, #relative_time_ago, #remove_utc_offset, #stringify, #symbolize, #time_period_in_words, #truncate

Constructor Details

#initialize(opts = {}) ⇒ SmsTwilio

Returns a new instance of SmsTwilio.



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/flapjack/gateways/sms_twilio.rb', line 33

def initialize(opts = {})
  @lock = opts[:lock]

  @config = opts[:config]

  # TODO support for config reloading
  @queue = Flapjack::RecordQueue.new(@config['queue'] || 'sms_twilio_notifications',
             Flapjack::Data::Alert)

  @sent = 0

  Flapjack.logger.debug("new sms_twilio gateway pikelet with the following options: #{@config.inspect}")
end

Instance Attribute Details

#sentObject

Returns the value of attribute sent.



29
30
31
# File 'lib/flapjack/gateways/sms_twilio.rb', line 29

def sent
  @sent
end

Instance Method Details

#startObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/flapjack/gateways/sms_twilio.rb', line 47

def start
  begin
    Zermelo.redis = Flapjack.redis

    loop do
      @lock.synchronize do
        @queue.foreach {|alert| handle_alert(alert) }
      end

      @queue.wait
    end
  ensure
    Flapjack.redis.quit
  end
end

#stop_typeObject



63
64
65
# File 'lib/flapjack/gateways/sms_twilio.rb', line 63

def stop_type
  :exception
end