action_messager 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.
- data/LICENSE +18 -0
- data/README +37 -0
- data/Rakefile +7 -0
- data/lib/action_messager/base.rb +31 -0
- data/lib/action_messager/version.rb +11 -0
- data/lib/action_messager.rb +11 -0
- data/tasks/gem.rake +59 -0
- data/tasks/test.rake +8 -0
- data/test/base_test.rb +53 -0
- data/test/test_helper.rb +6 -0
- metadata +89 -0
data/LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2008 James Golick, GiraffeSoft Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
5
|
+
deal in the Software without restriction, including without limitation the
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
16
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
= ActionMessager
|
2
|
+
|
3
|
+
ActionMessager is dead simple IM notifications for your app.
|
4
|
+
|
5
|
+
== Get It
|
6
|
+
|
7
|
+
$ sudo gem install action_messager
|
8
|
+
|
9
|
+
... or get the source ...
|
10
|
+
|
11
|
+
$ git clone git@github.com:giraffesoft/action_messager.git
|
12
|
+
|
13
|
+
== Usage
|
14
|
+
|
15
|
+
ActionMessager works just like ActionMailer. All you have to do start sending IM notifications to your users is subclass ActionMessager::Base; then, create a method that sets an array of recipients, and returns the message you'd like to send:
|
16
|
+
|
17
|
+
class JabberNotifier < ActionMessager::Base
|
18
|
+
def friendship_request(friendship_request)
|
19
|
+
@recipients = friendship_request.receiver.jabber_contact
|
20
|
+
|
21
|
+
"You have received a friendship request from #{friendship_request.sender.name}! Click here to accept or decline: #{friendship_request.url}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Then, wherever you'd like to send the notification:
|
26
|
+
|
27
|
+
JabberNotifier.deliver_friendship_request(friendship_request)
|
28
|
+
|
29
|
+
That's it!
|
30
|
+
|
31
|
+
== Credits
|
32
|
+
|
33
|
+
ActionMessager was created, and is maintained by {James Golick}[http://jamesgolick.com].
|
34
|
+
|
35
|
+
== License
|
36
|
+
|
37
|
+
ActionMessager is Copyright (c) 2008 James Golick, GiraffeSoft, Inc. It is released under the {MIT License}[http://en.wikipedia.org/wiki/MIT_License]
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module ActionMessager
|
2
|
+
class Base
|
3
|
+
include ActionController::UrlWriter if Object.const_defined?(:ActionController)
|
4
|
+
|
5
|
+
class_inheritable_accessor :jabber_settings
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def connection
|
9
|
+
raise ArgumentError.new('You must supply jabber credentials to use ActionMessager') unless [jabber_settings[:username], jabber_settings[:password]].select(&:blank?).empty?
|
10
|
+
@connection ||= Jabber::Simple.new(jabber_settings[:username], jabber_settings[:password])
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_missing(method, *args)
|
14
|
+
method.to_s =~ /deliver_.+?/ ? deliver(method.to_s.gsub(/deliver_/, '').intern, *args) : super
|
15
|
+
end
|
16
|
+
|
17
|
+
def deliver(method, *args)
|
18
|
+
messager = new
|
19
|
+
msg = messager.send(method, *args)
|
20
|
+
|
21
|
+
messager.recipients.each do |recipient|
|
22
|
+
connection.deliver recipient, msg
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private :new
|
27
|
+
end
|
28
|
+
|
29
|
+
attr_accessor :recipients
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
require "rubygems"
|
3
|
+
require "json"
|
4
|
+
require "xmpp4r-simple"
|
5
|
+
require "activesupport"
|
6
|
+
require "action_messager/version"
|
7
|
+
require "action_messager/base"
|
8
|
+
|
9
|
+
module ActionMessager
|
10
|
+
NAME = 'action_messager'
|
11
|
+
end
|
data/tasks/gem.rake
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rake/gempackagetask'
|
2
|
+
|
3
|
+
task :clean => :clobber_package
|
4
|
+
|
5
|
+
spec = Gem::Specification.new do |s|
|
6
|
+
s.name = ActionMessager::NAME
|
7
|
+
s.version = ActionMessager::Version::STRING
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.summary =
|
10
|
+
s.description = "Really simple jabber IM notifications."
|
11
|
+
s.author = "James Golick"
|
12
|
+
s.email = 'james@giraffesoft.ca'
|
13
|
+
s.homepage = 'http://jamesgolick.com/action_messager/'
|
14
|
+
|
15
|
+
s.required_ruby_version = '>= 1.8.6'
|
16
|
+
|
17
|
+
s.add_dependency 'activesupport', '>= 2.0.2'
|
18
|
+
s.add_dependency 'xmpp4r-simple', '>= 0.8.7'
|
19
|
+
s.add_dependency 'json_pure', '>= 0.8.7'
|
20
|
+
|
21
|
+
s.files = %w(LICENSE README Rakefile) +
|
22
|
+
Dir.glob("{lib,test,tasks}/**/*")
|
23
|
+
|
24
|
+
s.require_path = "lib"
|
25
|
+
end
|
26
|
+
|
27
|
+
Rake::GemPackageTask.new(spec) do |p|
|
28
|
+
p.gem_spec = spec
|
29
|
+
end
|
30
|
+
|
31
|
+
task :tag_warn do
|
32
|
+
puts "*" * 40
|
33
|
+
puts "Don't forget to tag the release:"
|
34
|
+
puts " git tag -a v#{ActionMessager::Version::STRING}"
|
35
|
+
puts "*" * 40
|
36
|
+
end
|
37
|
+
task :gem => :tag_warn
|
38
|
+
|
39
|
+
task :compile do
|
40
|
+
end
|
41
|
+
|
42
|
+
namespace :gem do
|
43
|
+
namespace :upload do
|
44
|
+
desc 'Upload gems to rubyforge.org'
|
45
|
+
task :rubyforge => :gem do
|
46
|
+
sh 'rubyforge login'
|
47
|
+
sh "rubyforge add_release giraffesoft action_messager #{ActionMessager::Version::STRING} pkg/#{spec.full_name}.gem"
|
48
|
+
sh "rubyforge add_file giraffesoft action_messager #{ActionMessager::Version::STRING} pkg/#{spec.full_name}.gem"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
task :install => [:clobber, :compile, :package] do
|
54
|
+
sh "sudo gem install pkg/#{spec.full_name}.gem"
|
55
|
+
end
|
56
|
+
|
57
|
+
task :uninstall => :clobber do
|
58
|
+
sh "sudo gem uninstall #{spec.name}"
|
59
|
+
end
|
data/tasks/test.rake
ADDED
data/test/base_test.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.dirname(__FILE__)+'/test_helper'
|
2
|
+
|
3
|
+
ActionMessager::Base.jabber_settings = {
|
4
|
+
:username => 'james',
|
5
|
+
:password => 'swordfish'
|
6
|
+
}
|
7
|
+
|
8
|
+
class MockNotifier < ActionMessager::Base
|
9
|
+
end
|
10
|
+
|
11
|
+
class ActionMessagerTest < Test::Unit::TestCase
|
12
|
+
context "connection" do
|
13
|
+
should "establish connection to Jabber::Simple using settings credentials" do
|
14
|
+
Jabber::Simple.expects(:new).with('james', 'swordfish')
|
15
|
+
ActionMessager::Base.connection
|
16
|
+
end
|
17
|
+
|
18
|
+
should "raise ArgumentError if there are no credentials" do
|
19
|
+
ActionMessager::Base.jabber_settings = {
|
20
|
+
:username => '',
|
21
|
+
:password => ''
|
22
|
+
}
|
23
|
+
|
24
|
+
assert_raise(ArgumentError) do
|
25
|
+
ActionMessager::Base.connection
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "delivering messages" do
|
31
|
+
should "instantiate a new messager object" do
|
32
|
+
MockNotifier.expects(:new).returns(stub(:changeset => '', :recipients => []))
|
33
|
+
MockNotifier.deliver_changeset
|
34
|
+
end
|
35
|
+
|
36
|
+
should "call the changeset method on the new messager" do
|
37
|
+
notifier_instance = mock(:changeset => '', :recipients => [])
|
38
|
+
MockNotifier.stubs(:new).returns(notifier_instance)
|
39
|
+
MockNotifier.deliver_changeset
|
40
|
+
end
|
41
|
+
|
42
|
+
should "deliver the return value of the method to each of the recipients" do
|
43
|
+
@message = 'some message'
|
44
|
+
connection = mock
|
45
|
+
connection.expects(:deliver).with('james@giraffesoft.ca', 'some message')
|
46
|
+
connection.expects(:deliver).with('tony@arktyp.ca', 'some message')
|
47
|
+
MockNotifier.stubs(:connection).returns(connection)
|
48
|
+
MockNotifier.any_instance.stubs(:changeset).returns(@message)
|
49
|
+
MockNotifier.any_instance.stubs(:recipients).returns(%w(james@giraffesoft.ca tony@arktyp.ca))
|
50
|
+
MockNotifier.deliver_changeset
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: action_messager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Golick
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-04-06 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activesupport
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.0.2
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: xmpp4r-simple
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 0.8.7
|
32
|
+
version:
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: json_pure
|
35
|
+
version_requirement:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.8.7
|
41
|
+
version:
|
42
|
+
description: Really simple jabber IM notifications.
|
43
|
+
email: james@giraffesoft.ca
|
44
|
+
executables: []
|
45
|
+
|
46
|
+
extensions: []
|
47
|
+
|
48
|
+
extra_rdoc_files: []
|
49
|
+
|
50
|
+
files:
|
51
|
+
- LICENSE
|
52
|
+
- README
|
53
|
+
- Rakefile
|
54
|
+
- lib/action_messager
|
55
|
+
- lib/action_messager/base.rb
|
56
|
+
- lib/action_messager/version.rb
|
57
|
+
- lib/action_messager.rb
|
58
|
+
- test/base_test.rb
|
59
|
+
- test/test_helper.rb
|
60
|
+
- tasks/gem.rake
|
61
|
+
- tasks/test.rake
|
62
|
+
has_rdoc: false
|
63
|
+
homepage: http://jamesgolick.com/action_messager/
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 1.8.6
|
74
|
+
version:
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0"
|
80
|
+
version:
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 0.9.5
|
85
|
+
signing_key:
|
86
|
+
specification_version: 2
|
87
|
+
summary: Really simple jabber IM notifications.
|
88
|
+
test_files: []
|
89
|
+
|