pdm-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pdm-rails.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,58 @@
1
+ module Pdm
2
+ module Rails
3
+ class Delivery
4
+
5
+ require "pdm/mail"
6
+
7
+ attr_accessor :fallback
8
+ attr_accessor :settings
9
+
10
+ def initialize(settings = {})
11
+ @settings = settings.dup
12
+ @fallback = settings.delete(:fallback)
13
+ end
14
+
15
+
16
+ def logger
17
+ ::Rails.logger
18
+ end
19
+
20
+ def deliver_without_pdm!(mail)
21
+ if @fallback
22
+ ActionMailer::Base.wrap_delivery_behavior(mail, @fallback)
23
+ mail.deliver!
24
+ end
25
+ end
26
+
27
+ def deliver!(mail)
28
+ pdm_mail = Pdm::Mail.new(mail, settings)
29
+
30
+ begin
31
+ if (res = pdm_mail.deliver)
32
+ case res
33
+ when Net::HTTPSuccess
34
+ logger.debug("Delivered #{mail.subject.inspect} to #{mail.to.inspect} " +
35
+ "via PDM #{pdm_mail.guid}.")
36
+ return mail
37
+ else
38
+ logger.error("Unable to deliver mail via PDM: Got response #{res.inspect}.")
39
+ end
40
+ else
41
+ logger.error("Unable to deliver mail via PDM. No response? :-(")
42
+ end
43
+ rescue Pdm::Error => e
44
+ logger.error("Got an error talking to PDM: " +
45
+ [e.class.name, e.message].join(": "))
46
+ raise(e) if @fallback.nil?
47
+ end
48
+
49
+ if @fallback
50
+ deliver_without_pdm!(mail)
51
+ else
52
+ e = RuntimeError.new("No success from PDM. No fallback possible.")
53
+ Pdm::Error.extend_and_raise(e)
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,19 @@
1
+ module Pdm
2
+ module Rails
3
+
4
+ class Railtie < ::Rails::Railtie
5
+
6
+ require "action_mailer"
7
+ require "pdm-rails/delivery"
8
+
9
+ # Register the :pdm delivery method. This will also add a
10
+ # +pdm_settings+ method to customize the various bits.
11
+ settings = {
12
+ :api_key => nil,
13
+ :logger => ::Rails.logger,
14
+ }
15
+ settings = Pdm.default_options.merge(settings)
16
+ ActionMailer::Base.add_delivery_method(:pdm, Pdm::Rails::Delivery, settings)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ module Pdm
2
+ module Rails
3
+
4
+ def version
5
+ "0.0.1"
6
+ end
7
+ module_function :version
8
+ end
9
+ end
data/lib/pdm-rails.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "pdm-rails/version"
2
+
3
+ module Pdm
4
+ module Rails
5
+
6
+ require "pdm-rails/delivery"
7
+ end
8
+ end
9
+
10
+ require "pdm-rails/railtie" if defined?(Rails)
data/pdm-rails.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/pdm-rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["PipeDevMail"]
6
+ gem.email = ["support@pipedevmail.com"]
7
+ gem.description = %q{Use the PipeDevMail gem within Rails}
8
+ gem.summary = %q{Interact with the PDM API from Rails}
9
+ gem.homepage = ""
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "pdm-rails"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Pdm::Rails.version
17
+
18
+ gem.add_development_dependency("rake")
19
+ gem.add_runtime_dependency("rails", ">= 3.0.0")
20
+ gem.add_runtime_dependency("pdm")
21
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pdm-rails
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - PipeDevMail
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-10-18 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :development
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ name: rake
33
+ version_requirements: *id001
34
+ prerelease: false
35
+ - !ruby/object:Gem::Dependency
36
+ type: :runtime
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 7
43
+ segments:
44
+ - 3
45
+ - 0
46
+ - 0
47
+ version: 3.0.0
48
+ name: rails
49
+ version_requirements: *id002
50
+ prerelease: false
51
+ - !ruby/object:Gem::Dependency
52
+ type: :runtime
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ name: pdm
63
+ version_requirements: *id003
64
+ prerelease: false
65
+ description: Use the PipeDevMail gem within Rails
66
+ email:
67
+ - support@pipedevmail.com
68
+ executables: []
69
+
70
+ extensions: []
71
+
72
+ extra_rdoc_files: []
73
+
74
+ files:
75
+ - .gitignore
76
+ - Gemfile
77
+ - Rakefile
78
+ - lib/pdm-rails.rb
79
+ - lib/pdm-rails/delivery.rb
80
+ - lib/pdm-rails/railtie.rb
81
+ - lib/pdm-rails/version.rb
82
+ - pdm-rails.gemspec
83
+ has_rdoc: true
84
+ homepage: ""
85
+ licenses: []
86
+
87
+ post_install_message:
88
+ rdoc_options: []
89
+
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 3
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ requirements: []
111
+
112
+ rubyforge_project:
113
+ rubygems_version: 1.6.2
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: Interact with the PDM API from Rails
117
+ test_files: []
118
+