simple_postmark18 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,14 @@
1
+ require 'active_support/core_ext/object/blank'
2
+ require 'active_support/inflector/methods'
3
+ require 'httparty'
4
+ require 'json'
5
+ require 'mail'
6
+
7
+ module SimplePostmark
8
+ require 'simple_postmark/mail_ext/message'
9
+ require 'simple_postmark/mail_ext/part'
10
+
11
+ require 'simple_postmark/delivery_method'
12
+
13
+ require 'simple_postmark/railtie' if defined?(Rails)
14
+ end
@@ -0,0 +1,19 @@
1
+ module Mail
2
+ class SimplePostmark
3
+ include HTTParty
4
+
5
+ def initialize(values)
6
+ self.settings = { :api_key => '********-****-****-****-************' }.merge(values)
7
+ end
8
+
9
+ attr_accessor :settings
10
+ base_uri 'http://api.postmarkapp.com'
11
+ headers 'Accept' => 'application/json', 'ContentType' => 'application/json'
12
+
13
+ def deliver!(mail)
14
+ api_key = { 'X-Postmark-Server-Token' => settings[:api_key].to_s }
15
+
16
+ self.class.post('/email', :headers => self.class.headers.merge(api_key), :body => mail.to_postmark.to_json)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,37 @@
1
+ module Mail
2
+ class Message
3
+ def html_body
4
+ if html_part.present?
5
+ html_part.to_postmark['Content']
6
+ else
7
+ body if content_type.to_s.include?('text/html')
8
+ end
9
+ end
10
+
11
+ def tag(val = nil)
12
+ default(:tag, val)
13
+ end
14
+
15
+ def tag=(val)
16
+ header[:tag] = val
17
+ end
18
+
19
+ def text_body
20
+ text_part.present? ? text_part.to_postmark['Content'] : body
21
+ end
22
+
23
+ def to_postmark
24
+ hash = {}
25
+
26
+ %w[attachments bcc cc from html_body reply_to subject tag text_body to].each do |key|
27
+ hash[key.camelcase] = case (value = send(key).presence or next)
28
+ when AttachmentsList then value.map(&:to_postmark)
29
+ when Array then value.join(', ')
30
+ else value.to_s
31
+ end
32
+ end
33
+
34
+ hash
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,11 @@
1
+ module Mail
2
+ class Part
3
+ def to_postmark
4
+ {}.tap do |hash|
5
+ hash['Content'] = attachment? ? [read].pack('m') : body.to_s
6
+ hash['ContentType'] = mime_type
7
+ hash['Name'] = filename
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module SimplePostmark
2
+ class Railtie < ::Rails::Railtie
3
+ ActionMailer::Base.add_delivery_method(:simple_postmark, Mail::SimplePostmark, :api_key => nil)
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module SimplePostmark
2
+ VERSION = '0.4.0'
3
+ end
metadata ADDED
@@ -0,0 +1,185 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_postmark18
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
+ platform: ruby
12
+ authors:
13
+ - Mario Uher
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-12 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activesupport
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ version: "3.0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: httparty
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: json
52
+ prerelease: false
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
+ type: :runtime
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: mail
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ type: :runtime
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: minitest
80
+ prerelease: false
81
+ requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ type: :development
91
+ version_requirements: *id005
92
+ - !ruby/object:Gem::Dependency
93
+ name: purdytest
94
+ prerelease: false
95
+ requirement: &id006 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ type: :development
105
+ version_requirements: *id006
106
+ - !ruby/object:Gem::Dependency
107
+ name: rails
108
+ prerelease: false
109
+ requirement: &id007 !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ~>
113
+ - !ruby/object:Gem::Version
114
+ hash: 7
115
+ segments:
116
+ - 3
117
+ - 0
118
+ version: "3.0"
119
+ type: :development
120
+ version_requirements: *id007
121
+ - !ruby/object:Gem::Dependency
122
+ name: webmock
123
+ prerelease: false
124
+ requirement: &id008 !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ hash: 3
130
+ segments:
131
+ - 0
132
+ version: "0"
133
+ type: :development
134
+ version_requirements: *id008
135
+ description: "SimplePostmark makes it easy to send mails via Postmark\xE2\x84\xA2 using Rails 3's ActionMailer."
136
+ email: uher.mario@gmail.com
137
+ executables: []
138
+
139
+ extensions: []
140
+
141
+ extra_rdoc_files: []
142
+
143
+ files:
144
+ - lib/simple_postmark/delivery_method.rb
145
+ - lib/simple_postmark/mail_ext/message.rb
146
+ - lib/simple_postmark/mail_ext/part.rb
147
+ - lib/simple_postmark/railtie.rb
148
+ - lib/simple_postmark/version.rb
149
+ - lib/simple_postmark.rb
150
+ has_rdoc: true
151
+ homepage: https://www.github.com/haihappen/simple_postmark
152
+ licenses: []
153
+
154
+ post_install_message:
155
+ rdoc_options: []
156
+
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ hash: 3
165
+ segments:
166
+ - 0
167
+ version: "0"
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ hash: 3
174
+ segments:
175
+ - 0
176
+ version: "0"
177
+ requirements: []
178
+
179
+ rubyforge_project:
180
+ rubygems_version: 1.6.2
181
+ signing_key:
182
+ specification_version: 3
183
+ summary: "A simple way to use Postmark\xE2\x84\xA2 with your Rails app."
184
+ test_files: []
185
+