chatterbox 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ### 0.8.2
4
+ - Fix Github Issue #2: In email service, change incoming default configuration to HashWithIndifferentAccess: fixes a bug that would result in default configuration always winning over per-message configuration.
5
+
3
6
  ### 0.8.1
4
7
  - Make sure Arrays format nicely for ExceptionNotification, so backtraces are easy to read
5
8
 
@@ -94,15 +94,19 @@ And you are done! Exceptions thrown in controllers will automatically be proces
94
94
 
95
95
  Bugs & Patches
96
96
  --------------
97
- Please submit to [Github Issues](http://github.com/rsanheim/chatterbox/TODO).
97
+ Please submit to [Github Issues](http://github.com/rsanheim/chatterbox/issues).
98
98
 
99
- All patches must have spec coverage and a passing build, or they will be pushed back.
99
+ All patches must have spec coverage and a passing build.
100
100
 
101
101
  You can easily verify your build by pushing the project to [RunCodeRun](http://runcoderun.com). View the [master build](http://runcoderun.com/rsanheim/chatterbox) to confirm that HEAD is stable and passing.
102
102
 
103
103
  Links
104
104
  -------------
105
105
 
106
+ Bugs/Issues: http://github.com/rsanheim/chatterbox/issues
107
+ CI: http://runcoderun.com/rsanheim/chatterbox
108
+ Docs: http://rdoc.info/projects/rsanheim/chatterbox
109
+
106
110
  Contributors
107
111
  ------------
108
112
  * Rob Sanheim (creator)
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 8
4
- :patch: 1
4
+ :patch: 2
5
5
  :build:
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{chatterbox}
8
- s.version = "0.8.1"
8
+ s.version = "0.8.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Rob Sanheim"]
12
- s.date = %q{2009-11-26}
12
+ s.date = %q{2009-12-02}
13
13
  s.description = %q{Send notifications and messages. However you want.}
14
14
  s.email = %q{rsanheim@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -19,14 +19,14 @@ describe Chatterbox::Services::Email do
19
19
  result.should be_instance_of(TMail::Mail)
20
20
  end
21
21
 
22
- it "should preserve HashWithIndifferentAccess with explicit options" do
22
+ it "preserves HashWithIndifferentAccess with explicit options" do
23
23
  options = { :summary => "foo", :config => { :to => "a", :from => "a" } }.with_indifferent_access
24
24
  service = Chatterbox::Services::Email.new(options)
25
25
  service.options.should be_instance_of(HashWithIndifferentAccess)
26
26
  service.options[:config].should be_instance_of(HashWithIndifferentAccess)
27
27
  end
28
28
 
29
- it "should preserve HashWithIndifferentAccess with default configuration" do
29
+ it "preserves HashWithIndifferentAccess with default configuration" do
30
30
  options = { :summary => "foo" }.with_indifferent_access
31
31
  Chatterbox::Services::Email.configure :to => "default-to@example.com", :from => "default-from@example.com"
32
32
  service = Chatterbox::Services::Email.new(options)
@@ -65,14 +65,14 @@ describe Chatterbox::Services::Email do
65
65
  end
66
66
  end
67
67
 
68
- describe "default_configuration=" do
68
+ describe "default configuration" do
69
69
  it "defaults to empty hash" do
70
70
  Chatterbox::Services::Email.default_configuration.should == {}
71
71
  end
72
72
 
73
73
  it "sets default configuration into :config" do
74
- Chatterbox::Services::Email.configure :to => "to@example.com", :from => "from@example.com"
75
- Chatterbox::Services::Email.default_configuration.should == { :to => "to@example.com", :from => "from@example.com"}
74
+ Chatterbox::Services::Email.configure "to" => "to@example.com", "from" => "from@example.com"
75
+ Chatterbox::Services::Email.default_configuration.should == { "to" => "to@example.com", "from" => "from@example.com"}
76
76
  end
77
77
 
78
78
  it "uses default configuration if no per-message configuration provided" do
@@ -83,11 +83,19 @@ describe Chatterbox::Services::Email do
83
83
  end
84
84
 
85
85
  it "allows per message configuration (if provided) to override default configuration" do
86
- Chatterbox::Services::Email.configure :to => "default-to@example.com", :from => "default-from@example.com"
86
+ Chatterbox::Services::Email.configure "to" => "default-to@example.com", :from => "default-from@example.com"
87
87
  mail = Chatterbox::Services::Email.deliver(:summary => "summary",
88
88
  :config => { :to => "joe@example.com", :from => "harry@example.com"} )
89
89
  mail.to.should == ["joe@example.com"]
90
90
  mail.from.should == ["harry@example.com"]
91
91
  end
92
+
93
+ it "allows per message configuration with string keys to override default configuration" do
94
+ Chatterbox::Services::Email.configure "to" => "default-to@example.com", :from => "default-from@example.com"
95
+ mail = Chatterbox::Services::Email.deliver(:summary => "summary",
96
+ :config => { "to" => "joe@example.com" })
97
+ mail.to.should == ["joe@example.com"]
98
+ mail.from.should == ["default-from@example.com"]
99
+ end
92
100
  end
93
101
  end
@@ -22,6 +22,7 @@ Feature: Sending email
22
22
  Then the exit code should be 0
23
23
  And the stdout should match "To: joe@example.com"
24
24
 
25
+ @wip
25
26
  Scenario: Sending with default configuration
26
27
  Given a file named "default_configuration_email_send.rb" with:
27
28
  """
@@ -35,12 +36,13 @@ Feature: Sending email
35
36
  Chatterbox::Services::Email.configure({
36
37
  :to => "to@example.com", :from => "from@example.com", :summary_prefix => "[CUKE] "
37
38
  })
38
- Chatterbox.notify :message => { :summary => "subject goes here!", :body => "body" }
39
+ Chatterbox.notify :summary => "subject goes here!", :body => "body",
40
+ :config => { :to => "override@example.com" }
39
41
  puts ActionMailer::Base.deliveries.last.encoded
40
42
  """
41
43
  When I run "default_configuration_email_send.rb"
42
44
  Then the exit code should be 0
43
- And the stdout should match "To: to@example.com"
45
+ And the stdout should match "To: override@example.com"
44
46
  And the stdout should match "From: from@example.com"
45
47
  And the stdout should match "Subject: [CUKE] subject goes here!"
46
48
 
@@ -1,6 +1,17 @@
1
1
  require 'active_support'
2
2
 
3
3
  module Chatterbox
4
+ # Send a notification with Chatterbox
5
+ # Returns the message itself
6
+ #
7
+ # <tt>message</tt> is an options hash that allows the following options:
8
+ #
9
+ # :summary - The summary of the message - required. If your service only supports
10
+ # 'short' notifications, like Twitter, this is generally what you should send.
11
+ # :body - The body of the message - this may not be used if the service you are using
12
+ # doesn't support 'bodies' -- for example, Twitter.
13
+ # :config - The configuration settings for the different services the notification should use.
14
+ # See the individual services you are using for what configuration options should be used.
4
15
  def notify(message)
5
16
  publish_notice(message)
6
17
  message
@@ -10,6 +21,7 @@ module Chatterbox
10
21
  Publishers.publishers.each { |p| p.call(message.with_indifferent_access) }
11
22
  end
12
23
 
24
+ # Deprecated version of #notify
13
25
  def handle_notice(message)
14
26
  warning = "Chatterbox#handle_notice is deprecated and will be removed from Chatterbox 1.0. Call Chatterbox#notify instead."
15
27
  deprecate(warning, caller)
@@ -30,6 +42,13 @@ module Chatterbox
30
42
  @logger = logger
31
43
  end
32
44
 
45
+ # Register a service for sending notifications
46
+ #
47
+ # ===== Example:
48
+ #
49
+ # Chatterbox::Publishers.register do |notice|
50
+ # Chatterbox::Services::Email.deliver(notice)
51
+ # end
33
52
  def register(&blk)
34
53
  Publishers.register(&blk)
35
54
  end
@@ -5,10 +5,10 @@ module Chatterbox
5
5
 
6
6
  # Handle the exception
7
7
  # Accepts either an exception, a hash, or an object that responds to to_s
8
- # Exceptions are passed through like normal
9
- # Hashes can have an :exception => exception in them, which will result in
8
+ # * Exceptions are passed through like normal
9
+ # * Hashes can have an :exception => exception in them, which will result in
10
10
  # the same treatment as a literal exception passed
11
- # Objects are simply treated as a 'summary' message were an exception may not be necessary
11
+ # * Objects are simply treated as a 'summary' message were an exception may not be necessary
12
12
  def handle(args)
13
13
  hsh = normalize_to_hash(args)
14
14
  return if on_ignore_list?(hsh[:exception])
@@ -4,20 +4,38 @@ require 'chatterbox/services/email/mailer'
4
4
  module Chatterbox::Services
5
5
  class Email
6
6
  attr_reader :options
7
- @default_configuration = {}
8
-
7
+ # Return default configuration - defaults to empty hash
9
8
  def self.default_configuration
10
- @default_configuration
9
+ @default_configuration ||= {}
11
10
  end
12
-
11
+
12
+ # Configure Email service with default options
13
13
  def self.configure(config_options)
14
- @default_configuration = config_options
14
+ @default_configuration = config_options.with_indifferent_access
15
15
  end
16
16
 
17
+ # Deliver the a notification via email
18
+ #
19
+ # ==== Options
20
+ #
21
+ # * :summary - The subject of the message - required.
22
+ # * :body - The body of the email - if none provided, you will just send an email with a blank body.
23
+ # * :config - A sub-hash of configuration options.
24
+ # Optional if you have configured a default configuration with #configure.
25
+ # Config can contain any of the following options, all of which are pretty self explanatory:
26
+ #
27
+ # :to
28
+ # :from
29
+ # :content_type
30
+ # :reply_to
31
+ # :bcc
32
+ # :cc
17
33
  def self.deliver(options = {})
18
34
  new(options).deliver
19
35
  end
20
36
 
37
+ # Creates a new Email service with provided options.
38
+ # See Email::deliver for the valid options
21
39
  def initialize(options = {})
22
40
  @options = options
23
41
  merge_configs
@@ -25,6 +43,7 @@ module Chatterbox::Services
25
43
  validate_options
26
44
  end
27
45
 
46
+ # Deliver a notificaiton -- normally you should just use the class level method Email::deliver
28
47
  def deliver
29
48
  Mailer.deliver_message(options)
30
49
  end
@@ -1,5 +1 @@
1
- # rails catcher
2
- * make sure we push through request info for exceptions
3
- * wire ignore exceptions in rails catcher
4
- * wire up common idioms (or easy ability to) to grab current_user from request, current_url, etc
5
-
1
+ * have ExceptionNotification add top_level method to Chatterbox -- #notify_exception?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chatterbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Sanheim
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-26 00:00:00 -05:00
12
+ date: 2009-12-02 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency