postmark 0.2.5 → 0.3.0
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/README.rdoc +5 -0
- data/VERSION +1 -1
- data/lib/postmark.rb +24 -2
- data/lib/postmark/response_parsers/active_support.rb +10 -0
- data/lib/postmark/response_parsers/json.rb +10 -0
- data/lib/postmark/response_parsers/yajl.rb +11 -0
- data/postmark.gemspec +8 -5
- data/spec/postmark_spec.rb +15 -0
- data/spec/spec_helper.rb +7 -1
- metadata +5 -2
data/README.rdoc
CHANGED
@@ -37,6 +37,11 @@ Then
|
|
37
37
|
The gem relies on TMail for building the message. You will also need postmark account, server and sender signature set up to use it.
|
38
38
|
If you plan using it in a rails project, check out the postmark-rails gem, which is meant to integrate with ActionMailer.
|
39
39
|
|
40
|
+
The plugin will try to use ActiveSupport Json if it is already included. If not, it will attempt using the built-in ruby Json library.
|
41
|
+
You can also explicitly specify which one to be used, using
|
42
|
+
|
43
|
+
Postmark.response_parser_class = :Json # :ActiveSupport or :Yajl is also supported.
|
44
|
+
|
40
45
|
== Limitations
|
41
46
|
Currently postmark API does not support multiple recipients, or attachments. For more information, check the docs here:
|
42
47
|
TODO: URL to docs.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/postmark.rb
CHANGED
@@ -2,7 +2,6 @@ require 'net/http'
|
|
2
2
|
require 'net/https'
|
3
3
|
require 'rubygems'
|
4
4
|
require 'tmail'
|
5
|
-
require 'json'
|
6
5
|
require 'postmark/tmail_mail_extension'
|
7
6
|
|
8
7
|
module Postmark
|
@@ -12,6 +11,12 @@ module Postmark
|
|
12
11
|
class InvalidMessageError < StandardError; end
|
13
12
|
class InternalServerError < StandardError; end
|
14
13
|
|
14
|
+
module ResponseParsers
|
15
|
+
autoload :Json, 'postmark/response_parsers/json'
|
16
|
+
autoload :ActiveSupport, 'postmark/response_parsers/active_support'
|
17
|
+
autoload :Yajl, 'postmark/response_parsers/yajl'
|
18
|
+
end
|
19
|
+
|
15
20
|
HEADERS = {
|
16
21
|
'Content-type' => 'application/json',
|
17
22
|
'Accept' => 'application/json'
|
@@ -21,6 +26,12 @@ module Postmark
|
|
21
26
|
attr_accessor :host, :host_path, :port, :secure, :api_key, :http_open_timeout, :http_read_timeout,
|
22
27
|
:proxy_host, :proxy_port, :proxy_user, :proxy_pass
|
23
28
|
|
29
|
+
attr_writer :response_parser_class
|
30
|
+
|
31
|
+
def response_parser_class
|
32
|
+
@response_parser_class ||= Object.const_defined?(:ActiveSupport) ? :ActiveSupport : :Json
|
33
|
+
end
|
34
|
+
|
24
35
|
# The port on which your Postmark server runs.
|
25
36
|
def port
|
26
37
|
@port || (secure ? 443 : 80)
|
@@ -59,6 +70,7 @@ module Postmark
|
|
59
70
|
end
|
60
71
|
|
61
72
|
def send_through_postmark(message) #:nodoc:
|
73
|
+
ResponseParsers.const_get(response_parser_class) # loads JSON lib, defining #to_json
|
62
74
|
http = Net::HTTP::Proxy(proxy_host,
|
63
75
|
proxy_port,
|
64
76
|
proxy_user,
|
@@ -87,7 +99,15 @@ module Postmark
|
|
87
99
|
end
|
88
100
|
|
89
101
|
def error_message(response_body)
|
90
|
-
|
102
|
+
decode_json(response_body)["Message"]
|
103
|
+
end
|
104
|
+
|
105
|
+
def decode_json(data)
|
106
|
+
ResponseParsers.const_get(response_parser_class).decode(data)
|
107
|
+
end
|
108
|
+
|
109
|
+
def encode_json(data)
|
110
|
+
ResponseParsers.const_get(response_parser_class).encode(data)
|
91
111
|
end
|
92
112
|
|
93
113
|
def convert_tmail(message)
|
@@ -107,4 +127,6 @@ module Postmark
|
|
107
127
|
|
108
128
|
end
|
109
129
|
|
130
|
+
self.response_parser_class = nil
|
131
|
+
|
110
132
|
end
|
data/postmark.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{postmark}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Petyo Ivanov"]
|
12
|
-
s.date = %q{2009-12-
|
12
|
+
s.date = %q{2009-12-15}
|
13
13
|
s.description = %q{Ruby gem for sending emails through http://postmarkapp.com HTTP API. It relieas on TMail::Mail for message construction.}
|
14
14
|
s.email = %q{underlog@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -28,6 +28,10 @@ Gem::Specification.new do |s|
|
|
28
28
|
"features/step_definitions/postmark_steps.rb",
|
29
29
|
"features/support/env.rb",
|
30
30
|
"lib/postmark.rb",
|
31
|
+
"lib/postmark/response_parsers/active_support.rb",
|
32
|
+
"lib/postmark/response_parsers/json.rb",
|
33
|
+
"lib/postmark/response_parsers/yajl.rb",
|
34
|
+
"lib/postmark/tmail_mail_extension.rb",
|
31
35
|
"lib/postmark/tmail_mail_extension.rb",
|
32
36
|
"postmark.gemspec",
|
33
37
|
"spec/postmark_spec.rb",
|
@@ -69,4 +73,3 @@ Gem::Specification.new do |s|
|
|
69
73
|
s.add_dependency(%q<tmail>, [">= 0"])
|
70
74
|
end
|
71
75
|
end
|
72
|
-
|
data/spec/postmark_spec.rb
CHANGED
@@ -102,4 +102,19 @@ describe "Postmark" do
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
+
context "JSON library support" do
|
106
|
+
[:Json, :ActiveSupport, :Yajl].each do |lib|
|
107
|
+
begin
|
108
|
+
original_parser_class = Postmark.response_parser_class
|
109
|
+
Postmark.response_parser_class = lib
|
110
|
+
it "parses error message with #{lib}" do
|
111
|
+
Postmark.error_message(%({"Message":"OK"})).should == "OK"
|
112
|
+
end
|
113
|
+
Postmark.response_parser_class = original_parser_class
|
114
|
+
rescue LoadError # No ActiveSupport or Yajl :(
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
105
120
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,6 +6,12 @@ require 'ruby-debug'
|
|
6
6
|
require 'spec'
|
7
7
|
require 'spec/autorun'
|
8
8
|
|
9
|
+
if ENV['JSONGEM']
|
10
|
+
# `JSONGEM=Yajl rake spec`
|
11
|
+
Postmark.response_parser_class = ENV['JSONGEM'].to_sym
|
12
|
+
puts "Setting ResponseParser class to #{Postmark::ResponseParsers.const_get Postmark.response_parser_class}"
|
13
|
+
end
|
14
|
+
|
9
15
|
Spec::Runner.configure do |config|
|
10
|
-
|
16
|
+
|
11
17
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postmark
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Petyo Ivanov
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-15 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -63,6 +63,9 @@ files:
|
|
63
63
|
- features/step_definitions/postmark_steps.rb
|
64
64
|
- features/support/env.rb
|
65
65
|
- lib/postmark.rb
|
66
|
+
- lib/postmark/response_parsers/active_support.rb
|
67
|
+
- lib/postmark/response_parsers/json.rb
|
68
|
+
- lib/postmark/response_parsers/yajl.rb
|
66
69
|
- lib/postmark/tmail_mail_extension.rb
|
67
70
|
- postmark.gemspec
|
68
71
|
- spec/postmark_spec.rb
|