Class: Fluent::TwilioOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::TwilioOutput
- Defined in:
- lib/fluent/plugin/out_twilio.rb
Constant Summary collapse
- VOICE_MAP =
['man', 'woman']
Instance Method Summary collapse
- #call(number, message) ⇒ Object
- #configure(conf) ⇒ Object
- #emit(tag, es, chain) ⇒ Object
-
#initialize ⇒ TwilioOutput
constructor
A new instance of TwilioOutput.
Constructor Details
#initialize ⇒ TwilioOutput
Returns a new instance of TwilioOutput.
18 19 20 21 22 |
# File 'lib/fluent/plugin/out_twilio.rb', line 18 def initialize super require 'uri' require 'twilio-ruby' end |
Instance Method Details
#call(number, message) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fluent/plugin/out_twilio.rb', line 39 def call(number, ) response = Twilio::TwiML::Response.new do |r| r.Say , :voice => @voice, :language => @language end xml = response.text.sub(/<[^>]+?>/, '') url = "http://twimlets.com/echo?Twiml=#{URI.escape(xml)}" log.info "twilio: generateing twiml: #{xml}" client = Twilio::REST::Client.new(@account_sid, @auth_token) account = client.account number.gsub(' ', '').split(',').each do |to_number| begin call = account.calls.create({:from => @from_number, :to => to_number, :url => url}) rescue => e log.error "twilio: Error: #{e.message}" end end end |
#configure(conf) ⇒ Object
24 25 26 27 |
# File 'lib/fluent/plugin/out_twilio.rb', line 24 def configure(conf) super end |
#emit(tag, es, chain) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/fluent/plugin/out_twilio.rb', line 29 def emit(tag, es, chain) es.each do |time,record| number = record['number'].nil? ? @default_number : record['number'] @voice = VOICE_MAP.include?(record['voice']) ? record['voice'] : @default_voice call(number, record['message']) end chain.next end |