hatchet-hipchat 0.0.2 → 0.0.3

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,64 @@
1
+ module Hatchet
2
+
3
+ # Public: Class for sending log messages to a HipChat room.
4
+ #
5
+ class HipChatAppender
6
+ include LevelManager
7
+
8
+ # Internal: The class to use to create HipChat clients.
9
+ #
10
+ CLIENT = HipChat::API
11
+
12
+ # Public: The formatter used to format messages before sending them to the
13
+ # HipChat room.
14
+ #
15
+ attr_accessor :formatter
16
+
17
+ # Public: The API token to use to connect to HipChat's API.
18
+ #
19
+ attr_accessor :api_token
20
+
21
+ # Public: The ID of the room to send messages to.
22
+ #
23
+ attr_accessor :room_id
24
+
25
+ # Public: The name to post the messages as (default: Hatchet).
26
+ #
27
+ attr_accessor :name
28
+
29
+ # Public: Creates a new instance.
30
+ #
31
+ # By default the appender is created with a SimpleFormatter.
32
+ #
33
+ # block - Optional block that can be used to customize the appender. The
34
+ # appender itself is passed to the block.
35
+ #
36
+ def initialize
37
+ @name = 'Hatchet'
38
+ @formatter = SimpleFormatter.new
39
+ yield self if block_given?
40
+ end
41
+
42
+ # Internal: Sends a message to HipChat.
43
+ #
44
+ # level - The level of the message.
45
+ # context - The context of the message.
46
+ # message - The unformatted message.
47
+ #
48
+ # Returns nothing.
49
+ #
50
+ def add(level, context, message)
51
+ message = @formatter.format(level, context, message)
52
+ client.rooms_message @room_id, @name, message, 'text'
53
+ end
54
+
55
+ # Internal: Returns the client used to send messages to HipChat.
56
+ #
57
+ def client
58
+ @client ||= CLIENT.new(@api_token)
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+
@@ -0,0 +1,55 @@
1
+ module Hatchet
2
+
3
+ # Public: Formatter that outputs messages with HipChat emoticons in place of
4
+ # the level.
5
+ #
6
+ # Mapping
7
+ #
8
+ # :debug -> (content)
9
+ # :info -> (wat)
10
+ # :warn -> (ohcrap)
11
+ # :error -> (omg)
12
+ # :fatal -> (boom)
13
+ #
14
+ # Emoticon reference: http://hipchat-emoticons.heroku.com/
15
+ #
16
+ class HipChatEmoticonFormatter
17
+
18
+ # Internal: Map for converting levels to emoticons.
19
+ #
20
+ LEVEL_EMOTICON_MAP = {
21
+ debug: '(content)',
22
+ info: '(wat)',
23
+ warn: '(ohcrap)',
24
+ error: '(omg)',
25
+ fatal: '(boom)'
26
+ }
27
+
28
+ # Public: Returns the formatted message with HipChat emoticons in place of
29
+ # the level.
30
+ #
31
+ # level - The severity of the log message.
32
+ # context - The context of the log message.
33
+ # message - The message provided by the log caller.
34
+ #
35
+ # Mapping
36
+ #
37
+ # :debug -> (content)
38
+ # :info -> (wat)
39
+ # :warn -> (ohcrap)
40
+ # :error -> (omg)
41
+ # :fatal -> (boom)
42
+ #
43
+ # Returns messages in the format:
44
+ #
45
+ # LEVEL - CONTEXT - MESSAGE
46
+ #
47
+ def format(level, context, message)
48
+ message = message.to_s.strip
49
+ "#{LEVEL_EMOTICON_MAP[level]} - #{context} - #{message}"
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+
@@ -1,5 +1,5 @@
1
1
  module Hatchet
2
2
  module Hipchat
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
5
5
  end
@@ -1,62 +1,6 @@
1
1
  require 'hatchet-hipchat/version'
2
2
  require 'hatchet'
3
3
  require 'hipchat-api'
4
+ require 'hatchet-hipchat/hipchat_appender'
5
+ require 'hatchet-hipchat/hipchat_emoticon_formatter'
4
6
 
5
- module Hatchet
6
-
7
- # Public: Class for sending log messages to a HipChat room.
8
- #
9
- class HipChatAppender
10
- include LevelManager
11
-
12
- # Interal: The class to use to create HipChat clients.
13
- #
14
- CLIENT = HipChat::API
15
-
16
- # Public: The formatter used to format messages before sending them to the
17
- # HipChat room.
18
- #
19
- attr_accessor :formatter
20
-
21
- # Public: The API token to use to connect to HipChat's API.
22
- #
23
- attr_accessor :api_token
24
-
25
- # Public: The ID of the room to send messages to.
26
- #
27
- attr_accessor :room_id
28
-
29
- # Public: Creates a new instance.
30
- #
31
- # By default the appender is created with a SimpleFormatter.
32
- #
33
- # block - Optional block that can be used to customize the appender. The
34
- # appender itself is passed to the block.
35
- #
36
- def initialize
37
- @formatter = SimpleFormatter.new
38
- yield self if block_given?
39
- end
40
-
41
- # Internal: Sends a message to HipChat.
42
- #
43
- # level - The level of the message.
44
- # context - The context of the message.
45
- # message - The unformatted message.
46
- #
47
- # Returns nothing.
48
- #
49
- def add(level, context, message)
50
- message = @formatter.format(level, context, message)
51
- client.rooms_message @room_id, 'Hatchet', message
52
- end
53
-
54
- # Internal: Returns the client used to send messages to HipChat.
55
- #
56
- def client
57
- @client ||= CLIENT.new(@api_token)
58
- end
59
-
60
- end
61
-
62
- end
@@ -11,8 +11,8 @@ class FakeClient
11
11
  @messages = []
12
12
  end
13
13
 
14
- def rooms_message(room_id, from, message)
15
- @messages << OpenStruct.new(room_id: room_id, from: from, message: message)
14
+ def rooms_message(room_id, from, message, format)
15
+ @messages << OpenStruct.new(room_id: room_id, from: from, message: message, format: format)
16
16
  end
17
17
 
18
18
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require_relative 'spec_helper'
2
2
 
3
3
  describe HipChatAppender do
4
4
  before do
@@ -39,6 +39,21 @@ describe HipChatAppender do
39
39
  formatted_message = subject.formatter.format(:warn, 'Custom::Context', 'Hello, World')
40
40
  assert 'Hatchet' == message.from
41
41
  assert formatted_message == message.message
42
+ assert 'text' == message.format
43
+ end
44
+
45
+ describe 'setting name' do
46
+ before do
47
+ subject.name = 'CustomName'
48
+ end
49
+
50
+ before do
51
+ subject.add :warn, 'Custom::Context', 'Hello, World'
52
+ end
53
+
54
+ it 'sends a message with the configured name' do
55
+ assert 'CustomName' == message.from
56
+ end
42
57
  end
43
58
  end
44
59
  end
@@ -0,0 +1,27 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe HipChatEmoticonFormatter do
4
+ let(:formatter) { HipChatEmoticonFormatter.new }
5
+ let(:context) { 'Context' }
6
+ let(:message) { 'Hello, World' }
7
+
8
+ it 'maps debug to (content)' do
9
+ assert '(content) - Context - Hello, World' == formatter.format(:debug, context, message)
10
+ end
11
+
12
+ it 'maps info to (wat)' do
13
+ assert '(wat) - Context - Hello, World' == formatter.format(:info, context, message)
14
+ end
15
+
16
+ it 'maps warn to (ohcrap)' do
17
+ assert '(ohcrap) - Context - Hello, World' == formatter.format(:warn, context, message)
18
+ end
19
+
20
+ it 'maps debug to (omg)' do
21
+ assert '(omg) - Context - Hello, World' == formatter.format(:error, context, message)
22
+ end
23
+
24
+ it 'maps debug to (boom)' do
25
+ assert '(boom) - Context - Hello, World' == formatter.format(:fatal, context, message)
26
+ end
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hatchet-hipchat
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,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-22 00:00:00.000000000 Z
12
+ date: 2012-07-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hatchet
16
- requirement: &70125504604660 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 0.0.9
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70125504604660
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.0.9
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: hipchat-api
27
- requirement: &70125504604160 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,7 +37,12 @@ dependencies:
32
37
  version: 1.0.4
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70125504604160
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.4
36
46
  description: Hatchet appender that sends messages to HipChat
37
47
  email:
38
48
  - garry@robustsoftware.co.uk
@@ -40,13 +50,16 @@ executables: []
40
50
  extensions: []
41
51
  extra_rdoc_files: []
42
52
  files:
53
+ - lib/hatchet-hipchat/hipchat_appender.rb
54
+ - lib/hatchet-hipchat/hipchat_emoticon_formatter.rb
43
55
  - lib/hatchet-hipchat/version.rb
44
56
  - lib/hatchet-hipchat.rb
45
57
  - spec/helpers/fake_client.rb
46
58
  - spec/hipchat_appender_spec.rb
59
+ - spec/hipchat_emoticon_formatter_spec.rb
47
60
  - spec/spec_helper.rb
48
61
  - LICENSE
49
- homepage: ''
62
+ homepage: https://github.com/gshutler/hatchet-hipchat
50
63
  licenses: []
51
64
  post_install_message:
52
65
  rdoc_options: []
@@ -66,11 +79,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
79
  version: '0'
67
80
  requirements: []
68
81
  rubyforge_project:
69
- rubygems_version: 1.8.17
82
+ rubygems_version: 1.8.24
70
83
  signing_key:
71
84
  specification_version: 3
72
85
  summary: Hatchet appender that sends messages to HipChat
73
86
  test_files:
74
87
  - spec/helpers/fake_client.rb
75
88
  - spec/hipchat_appender_spec.rb
89
+ - spec/hipchat_emoticon_formatter_spec.rb
76
90
  - spec/spec_helper.rb