jabber_delivery 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,3 @@
1
+ 0.0.1
2
+ -----
3
+ Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+ gemspec
3
+
4
+ gem "rake"
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Sergey 'Tangerine Cat' Kluchkowsky
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ Jabber Delivery
2
+ ---------------
3
+
4
+ This gem adds a method to ActionMailer which enables sending messages right to jabber.
5
+
6
+ Rails Setup
7
+ -----------
8
+
9
+ First add the gem to your `Gemfile` and run the `bundle` command to install it.
10
+
11
+ ```ruby
12
+ gem "jabber_delivery"
13
+ ```
14
+
15
+ Then, create file `config/jabber_delivery.yml` and put there jabber credentials you're going to use:
16
+
17
+ ```yaml
18
+ jid: foobar@somejabber.com
19
+ password: here_goes_your_password
20
+ ```
21
+
22
+ Now I can do in [devise](https://github.com/plataformatec/devise) resource:
23
+
24
+ ```ruby
25
+ def headers_for(action)
26
+ { :to => address, # Got address from email field with format {email|jabber}:(address here)
27
+ :delivery_method => delivery_method # Depending on prefix, use :smtp or :jabber_delivery (just for example)
28
+ }
29
+ end
30
+ ```
31
+
32
+ Hope it will help.
33
+
34
+ Project Status
35
+ --------------
36
+
37
+ Most of project's structure is *imported* from `letter_opener` gem and for now it's not so serious.
38
+
39
+
40
+ Development & Feedback
41
+ ----------------------
42
+
43
+ Special thanks to the [letter_opener](https://github.com/ryanb/letter_opener) gem for inspiring this project.
44
+
@@ -0,0 +1,4 @@
1
+ #
2
+ #
3
+ require "jabber_delivery/delivery_method"
4
+ require "jabber_delivery/railtie" if defined? Rails
@@ -0,0 +1,33 @@
1
+ require 'jabber_delivery/jabber_client'
2
+
3
+ #
4
+ module JabberDelivery
5
+ class DeliveryMethod
6
+ def initialize(options = {})
7
+ @options = options
8
+
9
+ raise "JID should be specified for jabber delivery" unless jid
10
+ raise "password should be specified for jabber delivery" unless password
11
+ end
12
+
13
+ def deliver!(mail)
14
+ jabber_client.deliver(mail.to.first, mail.body.to_s)
15
+ end
16
+
17
+ private
18
+ #
19
+ def jid
20
+ @jid ||= (@options[:jid] || @options["jid"])
21
+ end
22
+
23
+ #
24
+ def password
25
+ @password ||= (@options[:password] || @options["password"])
26
+ end
27
+
28
+ #
29
+ def jabber_client
30
+ @jabber_client ||= JabberClient.new(jid, password)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ #
2
+ require 'xmpp4r'
3
+
4
+ module JabberDelivery
5
+ class JabberClient
6
+
7
+ include Jabber
8
+
9
+ def initialize(jid, password)
10
+ @jid, @password = jid, password
11
+ end
12
+
13
+ def deliver(target_jid, message)
14
+ client.send(chat_message(target_jid, message))
15
+ end
16
+
17
+ private
18
+ #
19
+ def client
20
+ @client ||= Client.new(JID.new(@jid)).tap do |client|
21
+ client.connect
22
+ client.auth(@password)
23
+ end
24
+ end
25
+
26
+ #
27
+ def chat_message(target_jid, message)
28
+ Message.new(target_jid, message).tap do |m|
29
+ m.set_type(:chat)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,7 @@
1
+ module JabberDelivery
2
+ class Railtie < Rails::Railtie
3
+ initializer "jabber_delivery.add_delivery_method" do
4
+ ActionMailer::Base.add_delivery_method :jabber_delivery, JabberDelivery::DeliveryMethod, YAML.load_file(Rails.root.join("config/jabber_delivery.yml"))
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,47 @@
1
+ require "spec_helper"
2
+
3
+ describe JabberDelivery::DeliveryMethod do
4
+ JABBER_UID = "foo@bar.bz"
5
+ JABBER_PASSWORD = "asdfpoiuqwer"
6
+
7
+ TARGET_UID = "bazz@bar.bz"
8
+ MESSAGE = "Send more chunky bacon"
9
+
10
+ context "#deliver!" do
11
+ before(:each) do
12
+ jabber_uid = JABBER_UID
13
+ jabber_password = JABBER_PASSWORD
14
+
15
+ method = nil
16
+
17
+ Mail.defaults do
18
+ method = delivery_method JabberDelivery::DeliveryMethod, :jid => jabber_uid, :password => jabber_password
19
+ end
20
+
21
+ @method = method
22
+
23
+ ### Rather hack, 'cause I'm not too good in rspec yet
24
+ @method.stub(:dup).and_return(@method)
25
+
26
+ @jabber_client = mock("jabber_client")
27
+ @jabber_client.stub(:deliver)
28
+
29
+ @method.stub(:jabber_client).and_return(@jabber_client)
30
+ end
31
+
32
+ after(:each) do
33
+ mail = Mail.deliver do
34
+ to TARGET_UID
35
+ body MESSAGE
36
+ end
37
+ end
38
+
39
+ it "should reach for jabber client" do
40
+ @method.should_receive(:jabber_client)
41
+ end
42
+
43
+ it "should call jabber client's deliver method with parameters from `email'" do
44
+ @jabber_client.should_receive(:deliver).with(TARGET_UID, MESSAGE)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,35 @@
1
+ require "spec_helper"
2
+
3
+ describe JabberDelivery::JabberClient do
4
+ TARGET_JID = "target@jid.co"
5
+ MESSAGE = "Send me more chunky bacon"
6
+
7
+ before(:each) do
8
+ @jabber_client = JabberDelivery::JabberClient.new("foo@bar.bz", "123123")
9
+ @client_mock = mock("client")
10
+ @client_mock.stub!(:send)
11
+
12
+ @message_mock = mock("message")
13
+
14
+ @jabber_client.stub!(:client).and_return(@client_mock)
15
+ @jabber_client.stub!(:chat_message).and_return(@message_mock)
16
+ end
17
+
18
+ context "#deliver" do
19
+ after(:each) do
20
+ @jabber_client.deliver(TARGET_JID, MESSAGE)
21
+ end
22
+
23
+ it "should get client" do
24
+ @jabber_client.should_receive(:client)
25
+ end
26
+
27
+ it "should get chat_message" do
28
+ @jabber_client.should_receive(:chat_message)
29
+ end
30
+
31
+ it "should call client#send with chat message" do
32
+ @client_mock.should_receive(:send).with(@message_mock)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ Bundler.require(:default)
4
+
5
+ require "mail"
6
+
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.filter_run :focus => true
10
+ config.run_all_when_everything_filtered = true
11
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jabber_delivery
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tangerine Cat
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: xmpp4r
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
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: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.6.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.6.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: mail
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.3.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.3.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: ZenTest
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: pry
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: When mail is sent from your application, Jabber Delivery will send it
95
+ to jabber uid instead of email.
96
+ email: kaineer@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - lib/jabber_delivery/jabber_client.rb
102
+ - lib/jabber_delivery/delivery_method.rb
103
+ - lib/jabber_delivery/railtie.rb
104
+ - lib/jabber_delivery.rb
105
+ - spec/spec_helper.rb
106
+ - spec/jabber_delivery/jabber_client_spec.rb
107
+ - spec/jabber_delivery/delivery_method_spec.rb
108
+ - CHANGELOG.md
109
+ - LICENSE
110
+ - Gemfile
111
+ - README.md
112
+ homepage: http://github.com/kaineer/jabber_delivery
113
+ licenses: []
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: 1.3.4
130
+ requirements: []
131
+ rubyforge_project: jabber_delivery
132
+ rubygems_version: 1.8.23
133
+ signing_key:
134
+ specification_version: 3
135
+ summary: Send messages to jabber uid instead of email.
136
+ test_files: []