fluent-plugin-out_chatwork 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,6 +4,7 @@ fluentd output plugin for post to [ChatWork](http://www.chatwork.com/)
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/fluent-plugin-out_chatwork.svg)](http://badge.fury.io/rb/fluent-plugin-out_chatwork)
6
6
  [![Build Status](https://travis-ci.org/sue445/fluent-plugin-out_chatwork.svg)](https://travis-ci.org/sue445/fluent-plugin-out_chatwork)
7
+ [![Dependency Status](https://gemnasium.com/sue445/fluent-plugin-out_chatwork.svg)](https://gemnasium.com/sue445/fluent-plugin-out_chatwork)
7
8
 
8
9
  ## Installation
9
10
 
@@ -26,7 +27,7 @@ Or install it yourself as:
26
27
  type chatwork
27
28
  api_token YOUR_SECRET_TOKEN
28
29
  room_id 0000000000
29
- message Hello ChatWork! <%= record["value"] %>
30
+ message Hello ChatWork!\n<%= record["value"] %>
30
31
  </match>
31
32
  ```
32
33
 
@@ -37,12 +38,18 @@ Or install it yourself as:
37
38
  * message
38
39
  * message content
39
40
  * support erb format
41
+ * support newline character (\n)
40
42
 
41
43
  ## Changelog
44
+ ### master
45
+ [full changelog](http://github.com/sue445/fluent-plugin-out_chatwork/compare/v0.0.2...master)
46
+
47
+ * Support newline character in message
48
+
42
49
  ### 0.0.2
43
50
  [full changelog](http://github.com/sue445/fluent-plugin-out_chatwork/compare/v0.0.1...v0.0.2)
44
51
 
45
- * Support erb at message
52
+ * Support erb in message
46
53
 
47
54
  ### 0.0.1
48
55
  * Initial commit
@@ -4,12 +4,12 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fluent-plugin-out_chatwork"
7
- spec.version = "0.0.2"
7
+ spec.version = "0.0.3"
8
8
  spec.authors = ["sue445"]
9
9
  spec.email = ["sue445@sue445.net"]
10
10
  spec.summary = %q{fluentd output plugin for post to chatwork}
11
11
  spec.description = %q{fluentd output plugin for post to chatwork}
12
- spec.homepage = "https://github.com/sue445/fluent-plugin-out_chatwor"
12
+ spec.homepage = "https://github.com/sue445/fluent-plugin-out_chatwork"
13
13
  spec.license = "MIT"
14
14
 
15
15
  spec.files = `git ls-files -z`.split("\x0")
@@ -1,3 +1,4 @@
1
+ # -*- encoding: utf-8 -*-
1
2
  require "chatwork"
2
3
 
3
4
  module Fluent
@@ -37,16 +38,18 @@ module Fluent
37
38
  }
38
39
  end
39
40
 
40
- private
41
41
  def post_message(args={})
42
+ body = generate_message(args)
43
+ ChatWork.api_key = @api_token
44
+ ChatWork::Message.create(room_id: @room_id, body: body)
45
+ end
46
+
47
+ def generate_message(args={})
42
48
  time = args[:time]
43
49
  record = args[:record]
44
50
  tag = args[:tag]
45
51
 
46
- erb = ERB.new(@message)
47
- body = erb.result(binding)
48
- ChatWork.api_key = @api_token
49
- ChatWork::Message.create(room_id: @room_id, body: body)
52
+ ERB.new(@message).result(binding).gsub("\\n", "\n")
50
53
  end
51
54
  end
52
55
  end
@@ -1,3 +1,5 @@
1
+ # -*- encoding: utf-8 -*-
2
+
1
3
  describe Fluent::ChatworkOutput do
2
4
  let(:driver) { Fluent::Test::OutputTestDriver.new(Fluent::ChatworkOutput, 'test.metrics').configure(config) }
3
5
  let(:instance) { driver.instance }
@@ -22,10 +24,6 @@ describe Fluent::ChatworkOutput do
22
24
  it "should get message" do
23
25
  expect( instance.message ).to eq "some message"
24
26
  end
25
-
26
- context "When contain erb" do
27
-
28
- end
29
27
  end
30
28
 
31
29
  describe "#emit" do
@@ -40,4 +38,42 @@ describe Fluent::ChatworkOutput do
40
38
  expect(driver.run).not_to be_nil
41
39
  end
42
40
  end
41
+
42
+ describe "#generate_message" do
43
+ subject{ instance.generate_message(record: record, time: time, tag: tag) }
44
+
45
+ let(:record){ {} }
46
+ let(:time) { Time.now }
47
+ let(:tag) { "debug.foo" }
48
+
49
+ context "When contain erb format" do
50
+ let(:config) do
51
+ %[
52
+ api_token xxxxxxxxxxxxxxxxxxxx
53
+ room_id 1234567890
54
+ message <%= record["greeting"] %> ChatWork!
55
+ ]
56
+ end
57
+
58
+ let(:record) do
59
+ {
60
+ "greeting" => "Hello"
61
+ }
62
+ end
63
+
64
+ it{ should eq "Hello ChatWork!" }
65
+ end
66
+
67
+ context "When contain newline character" do
68
+ let(:config) do
69
+ %[
70
+ api_token xxxxxxxxxxxxxxxxxxxx
71
+ room_id 1234567890
72
+ message 1st line\\n2nd line
73
+ ]
74
+ end
75
+
76
+ it{ should eq "1st line\n2nd line" }
77
+ end
78
+ end
43
79
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # -*- encoding: utf-8 -*-
2
+
1
3
  # This file was generated by the `rspec --init` command. Conventionally, all
2
4
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
5
  # The generated `.rspec` file contains `--require spec_helper` which will cause this
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-out_chatwork
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-25 00:00:00.000000000 Z
12
+ date: 2014-06-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd
@@ -109,7 +109,7 @@ files:
109
109
  - lib/fluent/plugin/out_chatwork.rb
110
110
  - spec/lib/fluent/plugin/out_chatwork_spec.rb
111
111
  - spec/spec_helper.rb
112
- homepage: https://github.com/sue445/fluent-plugin-out_chatwor
112
+ homepage: https://github.com/sue445/fluent-plugin-out_chatwork
113
113
  licenses:
114
114
  - MIT
115
115
  post_install_message:
@@ -124,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
124
  version: '0'
125
125
  segments:
126
126
  - 0
127
- hash: 872810270354693595
127
+ hash: 2466610615714716893
128
128
  required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  none: false
130
130
  requirements:
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  segments:
135
135
  - 0
136
- hash: 872810270354693595
136
+ hash: 2466610615714716893
137
137
  requirements: []
138
138
  rubyforge_project:
139
139
  rubygems_version: 1.8.23