fluent-plugin-twilio 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-twilio.gemspec
4
+ gemspec
@@ -0,0 +1,14 @@
1
+ Copyright (c) 2013- Kentaro Yoshida
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
@@ -0,0 +1,67 @@
1
+ fluent-plugin-twilio
2
+ =====================
3
+
4
+ ## Overview
5
+ Fluentd Output plugin to make a call with twilio.
6
+
7
+ ## Installation
8
+
9
+ ### native gem
10
+ `````
11
+ gem install fluent-plugin-twilio
12
+ `````
13
+
14
+ ### td-agent gem
15
+ `````
16
+ /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-twilio
17
+ `````
18
+
19
+ ## Configuration
20
+
21
+ ### Message Format
22
+ `````
23
+ fluent_logger.post('notify.call', {
24
+ :message => 'Hello World!', # Required
25
+ :number => '+8109012345678' # Required
26
+ })
27
+ `````
28
+
29
+ ### Sample
30
+ `````
31
+ <source>
32
+ type http
33
+ port 8888
34
+ </source>
35
+
36
+ <match notify.call>
37
+ type twilio
38
+ account_sid TWILIO_ACCOUNT_SID # Required
39
+ auth_token TWILIO_AUTH_TOKEN # Required
40
+ from_number +81312345678 # Required with country code
41
+ default_number 090-1234-5678 # Optional
42
+ </match>
43
+ `````
44
+
45
+ ### Quick Test
46
+ `````
47
+ # test call to +819012345678 and say "Help! System ABC has down." with woman voice.
48
+ $ curl http://localhost:8888/notify.call -F 'json={"number":"+819012345678","voice":"woman","message":"Help! System ABC has down."}'
49
+
50
+ # check twilio activity log
51
+ $ tail -f /var/log/td-agent/td-agent.log
52
+ `````
53
+
54
+ ## Backend Service
55
+
56
+ * Twilio https://www.twilio.com/
57
+ * Twilio Japan http://twilio.kddi-web.com/
58
+
59
+ ## TODO
60
+ Pull requests are very welcome!!
61
+
62
+ ## Copyright
63
+ Copyright © 2013- Kentaro Yoshida ([@yoshi_ken](https://twitter.com/yoshi_ken))
64
+
65
+ ## License
66
+ Apache License, Version 2.0
67
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ Rake::TestTask.new(:test) do |test|
4
+ test.libs << 'lib' << 'test'
5
+ test.pattern = 'test/**/test_*.rb'
6
+ test.verbose = true
7
+ end
8
+
9
+ task :default => :test
10
+
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "fluent-plugin-twilio"
6
+ s.version = "0.0.1"
7
+ s.authors = ["Kentaro Yoshida"]
8
+ s.email = ["y.ken.studio@gmail.com"]
9
+ s.homepage = "https://github.com/y-ken/fluent-plugin-twilio"
10
+ s.summary = %q{Fluentd Output plugin to make a call with twilio.}
11
+
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ s.require_paths = ["lib"]
16
+
17
+ # specify any dependencies here; for example:
18
+ s.add_development_dependency "rake"
19
+ s.add_runtime_dependency "fluentd"
20
+ s.add_runtime_dependency "twilio-ruby"
21
+ end
@@ -0,0 +1,51 @@
1
+ class Fluent::TwilioOutput < Fluent::Output
2
+ Fluent::Plugin.register_output('twilio', self)
3
+
4
+ config_param :account_sid, :string
5
+ config_param :auth_token, :string
6
+ config_param :from_number, :string, :default => ''
7
+ config_param :default_number, :string, :default => ''
8
+ config_param :default_voice, :string, :default => 'woman'
9
+ config_param :language, :string, :default => 'ja-jp'
10
+
11
+ VOICE_MAP = ['woman']
12
+
13
+ def initialize
14
+ super
15
+ require 'uri'
16
+ require 'twilio-ruby'
17
+ end
18
+
19
+ def configure(conf)
20
+ super
21
+
22
+ end
23
+
24
+ def emit(tag, es, chain)
25
+ es.each do |time,record|
26
+ number = record['number'].nil? ? @default_number : record['number']
27
+ @voice = VOICE_MAP.include?(record['voice']) ? record['voice'] : @default_voice
28
+ call(number, record['message'])
29
+ end
30
+
31
+ chain.next
32
+ end
33
+
34
+ def call(number, message)
35
+ response = Twilio::TwiML::Response.new do |r|
36
+ r.Say message, :voice => @voice, :language => @language
37
+ end
38
+ xml = response.text.sub(/<[^>]+?>/, '')
39
+ url = "http://twimlets.com/echo?Twiml=#{URI.escape(xml)}"
40
+ $log.info "twilio: generateing twiml: #{xml}"
41
+
42
+ client = Twilio::REST::Client.new(@account_sid, @auth_token)
43
+ account = client.account
44
+ begin
45
+ call = account.calls.create({:from => @from_number, :to => number, :url => url})
46
+ rescue => e
47
+ $log.error "twilio: Error: #{e.message}"
48
+ end
49
+ end
50
+ end
51
+
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ require 'fluent/test'
15
+ unless ENV.has_key?('VERBOSE')
16
+ nulllogger = Object.new
17
+ nulllogger.instance_eval {|obj|
18
+ def method_missing(method, *args)
19
+ # pass
20
+ end
21
+ }
22
+ $log = nulllogger
23
+ end
24
+
25
+ require 'fluent/plugin/out_twilio'
26
+
27
+ class Test::Unit::TestCase
28
+ end
@@ -0,0 +1,42 @@
1
+ require 'helper'
2
+
3
+ class TwilioOutputTest < Test::Unit::TestCase
4
+ def setup
5
+ Fluent::Test.setup
6
+ end
7
+
8
+ CONFIG = %[
9
+ account_sid TWILIO_ACCOUNT_SID
10
+ auth_token TWILIO_AUTH_TOKEN
11
+ from_number +8112345678
12
+ ]
13
+
14
+ def create_driver(conf=CONFIG,tag='test')
15
+ Fluent::Test::OutputTestDriver.new(Fluent::TwilioOutput, tag).configure(conf)
16
+ end
17
+
18
+ def test_configure
19
+ assert_raise(Fluent::ConfigError) {
20
+ d = create_driver('')
21
+ }
22
+ d = create_driver %[
23
+ account_sid TWILIO_ACCOUNT_SID
24
+ auth_token TWILIO_AUTH_TOKEN
25
+ from_number +8112345678
26
+ ]
27
+ d.instance.inspect
28
+ assert_equal 'TWILIO_ACCOUNT_SID', d.instance.account_sid
29
+ assert_equal 'TWILIO_AUTH_TOKEN', d.instance.auth_token
30
+ assert_equal '+8112345678', d.instance.from_number
31
+ end
32
+
33
+ def test_emit
34
+ d1 = create_driver(CONFIG, 'notify.call')
35
+ d1.run do
36
+ d1.emit({'message' => 'hello world.'})
37
+ end
38
+ emits = d1.emits
39
+ assert_equal 0, emits.length
40
+ end
41
+ end
42
+
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-twilio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kentaro Yoshida
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: fluentd
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: twilio-ruby
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description:
63
+ email:
64
+ - y.ken.studio@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - fluent-plugin-twilio.gemspec
75
+ - lib/fluent/plugin/out_twilio.rb
76
+ - test/helper.rb
77
+ - test/plugin/test_out_twilio.rb
78
+ homepage: https://github.com/y-ken/fluent-plugin-twilio
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 1.8.23
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Fluentd Output plugin to make a call with twilio.
102
+ test_files:
103
+ - test/helper.rb
104
+ - test/plugin/test_out_twilio.rb