postageapp 1.2.6 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87918c47d50e1751788cda27b312a59b3ee55b32
4
- data.tar.gz: 983a6fe90bf14de8fa3772bb9f94abc00c0df4b9
3
+ metadata.gz: 99701f8c8bb6345d893d0e891e4080b574934fd2
4
+ data.tar.gz: 96c72f588f097c9a04ed8e0d47dc1ca836f96799
5
5
  SHA512:
6
- metadata.gz: b5711ee6b20b410068969d9b5aa2dcda4089f8db04a64abb957f3b54f56ec7ea2a42d98cbb7a491b7ea795d4b488b03525def4019b4eeefccfaf70adaef55805
7
- data.tar.gz: 7676cb2ff7e3b55b5c8d1f4efcd62ffffd149705694d918e18a7a9b4f5cd640f10fe281721da2a42458dfb45d581a970ee91a2e7fc0a336d5a0082a8449f05ee
6
+ metadata.gz: 3bfdec8d06ffb5af34bd0e13897f46986fde993d36009c96aa34d0710e2ff5729415d157b1e7af28448592da86566b272fec80d4ea52d1038c254d506c098ac9
7
+ data.tar.gz: 8da78d92e5d62ca7e5a9e7e77d04dd33dee17977a37f372738cb1c58d278f954132f1ae722f04a5c7b9b76e53b05ac1cada4328517b9c8d74aef631ef09da37f
@@ -1,6 +1,6 @@
1
1
  namespace :postageapp do
2
2
  desc 'Show the current PostageApp configuration'
3
- task :config => :environment do
3
+ task config: :environment do
4
4
  puts "PostageApp Configuration"
5
5
  puts "------------------------"
6
6
  puts
@@ -30,12 +30,29 @@ namespace :postageapp do
30
30
  end
31
31
 
32
32
  desc 'Verify the PostageApp gem installation by requesting project info from the API'
33
- task :test => :environment do
34
-
35
- puts "Attempting to contact #{PostageApp.configuration.host} ..."
33
+ task test: :environment do
34
+ diag = PostageApp::Diagnostics.new(PostageApp.config)
35
+
36
+ puts "Resolving #{PostageApp.config.host.inspect}"
37
+ if (resolved = diag.host_resolved)
38
+ puts "\t#{resolved.join(',')}"
39
+ else
40
+ puts "\tCouldn't be resolved. [ERROR]"
41
+ end
42
+
43
+ if (PostageApp.config.proxy?)
44
+ puts "Resolving #{PostageApp.config.proxy_host.inspect}"
45
+ if (resolved = diag.proxy_host_resolved)
46
+ puts "\t#{resolved.join(',')}"
47
+ else
48
+ puts "\tCouldn't be resolved. [ERROR]"
49
+ end
50
+ end
51
+
52
+ puts "Trying to contact #{PostageApp.configuration.url}..."
36
53
  response = PostageApp::Request.new(:get_project_info).send
37
54
 
38
- if response.ok?
55
+ if (response.ok?)
39
56
  project_name = response.data['project']['name']
40
57
  project_url = response.data['project']['url']
41
58
  user_emails = response.data['project']['users']
@@ -52,7 +69,8 @@ END
52
69
  # Most likely a single user if it's a new project
53
70
  puts 'Sending test message to users in the project...'
54
71
  r = send_test_message(user_emails)
55
- if r.ok?
72
+
73
+ if (r.ok?)
56
74
  puts "Message was successfully sent!\n\n"
57
75
  puts 'Your application is ready to use PostageApp!'
58
76
  else
@@ -60,7 +78,6 @@ END
60
78
  puts 'This was the response:'
61
79
  puts r.to_yaml
62
80
  end
63
-
64
81
  else
65
82
  puts 'Failed to fetch information about your project. This was the response:'
66
83
  puts response.to_yaml
@@ -68,7 +85,7 @@ END
68
85
  end
69
86
 
70
87
  desc 'Manually trigger resend of all failed emails'
71
- task :resend_failed_emails => :environment do
88
+ task resend_failed_emails: :environment do
72
89
  puts 'Attempting to resend failed emails...'
73
90
  PostageApp::FailedRequest.resend_all
74
91
  puts 'Done!'
@@ -2,22 +2,11 @@ require 'net/http'
2
2
  require 'net/https'
3
3
  require 'digest'
4
4
  require 'logger'
5
+ require 'fileutils'
5
6
 
6
7
  require 'json'
7
8
  require 'base64'
8
9
 
9
- require 'postageapp/utils'
10
- require 'postageapp/version'
11
- require 'postageapp/configuration'
12
- require 'postageapp/logger'
13
- require 'postageapp/request'
14
- require 'postageapp/failed_request'
15
- require 'postageapp/response'
16
- require 'postageapp/mail'
17
- require 'postageapp/mail/delivery_method'
18
-
19
- require 'postageapp/rails/railtie' if (defined?(Rails::Railtie))
20
-
21
10
  module PostageApp
22
11
  class Error < StandardError ; end
23
12
 
@@ -31,8 +20,12 @@ module PostageApp
31
20
  # If you do not want/need to initialize the gem in this way, you can use the environment
32
21
  # variable POSTAGEAPP_API_KEY to set up your key.
33
22
 
34
- def self.configure
35
- yield(configuration)
23
+ def self.configure(reset = false)
24
+ if (reset)
25
+ self.configuration_reset!
26
+ end
27
+
28
+ yield(self.configuration)
36
29
  end
37
30
 
38
31
  # Accessor for the PostageApp::Configuration object
@@ -42,6 +35,10 @@ module PostageApp
42
35
  @configuration ||= Configuration.new
43
36
  end
44
37
 
38
+ def self.configuration_reset!
39
+ @configuration = nil
40
+ end
41
+
45
42
  class << self
46
43
  alias :config :configuration
47
44
  end
@@ -61,6 +58,20 @@ module PostageApp
61
58
  end
62
59
  end
63
60
 
61
+ require 'postageapp/configuration'
62
+ require 'postageapp/diagnostics'
63
+ require 'postageapp/failed_request'
64
+ require 'postageapp/http'
65
+ require 'postageapp/logger'
66
+ require 'postageapp/request'
67
+ require 'postageapp/response'
68
+ require 'postageapp/mail'
69
+ require 'postageapp/mail/delivery_method'
70
+ require 'postageapp/utils'
71
+ require 'postageapp/version'
72
+
73
+ require 'postageapp/rails/railtie' if (defined?(Rails::Railtie))
74
+
64
75
  require 'postageapp/mail/extensions'
65
76
 
66
77
  if (defined?(::Mail))
@@ -38,19 +38,41 @@
38
38
  # Advanced Options
39
39
  # ----------------
40
40
  # :port - The port to make HTTP/HTTPS requests (default based on secure option)
41
- # :protocol - Set to either `http` or `https` (default based on secure option)
41
+ # :scheme - Set to either `http` or `https` (default based on secure option)
42
42
  # :requests_to_resend - List of API calls that should be replayed if they fail.
43
43
  # (default: send_message)
44
44
 
45
45
  class PostageApp::Configuration
46
+ # == Constants ============================================================
47
+
48
+ HOST_DEFAULT = 'api.postageapp.com'.freeze
49
+
50
+ SOCKS5_PORT_DEFAULT = 1080
51
+ HTTP_PORT_DEFAULT = 80
52
+ HTTPS_PORT_DEFAULT = 443
53
+
54
+ SCHEME_FOR_SECURE = {
55
+ true => 'https'.freeze,
56
+ false => 'http'.freeze
57
+ }.freeze
58
+
59
+ PATH_DEFAULT = '/'.freeze
60
+
61
+ FRAMEWORK_DEFAULT = 'Ruby'.freeze
62
+ ENVIRONMENT_DEFAULT = 'production'.freeze
63
+
64
+ # == Properties ===========================================================
65
+
46
66
  attr_accessor :secure
47
- attr_writer :protocol
67
+ attr_writer :scheme
48
68
  attr_accessor :host
49
69
  attr_writer :port
50
70
  attr_accessor :proxy_host
51
- attr_accessor :proxy_port
71
+ attr_writer :proxy_port
52
72
  attr_accessor :proxy_user
53
73
  attr_accessor :proxy_pass
74
+
75
+ attr_accessor :verify_certificate
54
76
  attr_accessor :http_open_timeout
55
77
  attr_accessor :http_read_timeout
56
78
  attr_accessor :recipient_override
@@ -59,23 +81,41 @@ class PostageApp::Configuration
59
81
  attr_accessor :framework
60
82
  attr_accessor :environment
61
83
  attr_accessor :logger
84
+
85
+ # == Instance Methods =====================================================
62
86
 
63
87
  def initialize
64
88
  @secure = true
65
- @host = 'api.postageapp.com'
89
+ @verify_certificate = true
90
+
91
+ @host = ENV['POSTAGEAPP_HOST'] || HOST_DEFAULT
92
+
93
+ @proxy_port = SOCKS5_PORT_DEFAULT
66
94
 
67
95
  @http_open_timeout = 5
68
96
  @http_read_timeout = 10
69
97
 
70
98
  @requests_to_resend = %w[ send_message ]
71
99
 
72
- @framework = 'Ruby'
73
-
74
- @environment = 'production'
100
+ @framework = FRAMEWORK_DEFAULT
101
+ @environment = ENVIRONMENT_DEFAULT
75
102
  end
76
103
 
77
104
  alias_method :secure?, :secure
78
-
105
+ alias_method :verify_certificate?, :verify_certificate
106
+
107
+ def port_default?
108
+ if (self.secure?)
109
+ self.port == HTTPS_PORT_DEFAULT
110
+ else
111
+ self.port == HTTP_PORT_DEFAULT
112
+ end
113
+ end
114
+
115
+ def proxy?
116
+ self.proxy_host and self.proxy_host.match(/\A\S+\z/)
117
+ end
118
+
79
119
  # Assign which API key is used to make API calls. Can also be specified
80
120
  # using the `POSTAGEAPP_API_KEY` environment variable.
81
121
  def api_key=(key)
@@ -88,34 +128,35 @@ class PostageApp::Configuration
88
128
  @api_key ||= ENV['POSTAGEAPP_API_KEY']
89
129
  end
90
130
 
91
- # Returns the HTTP protocol used to make API calls
92
- def protocol
93
- @protocol ||= (secure? ? 'https' : 'http')
131
+ # Returns the HTTP scheme used to make API calls
132
+ def scheme
133
+ @scheme ||= SCHEME_FOR_SECURE[self.secure?]
94
134
  end
135
+
136
+ alias_method :protocol=, :scheme=
137
+ alias_method :protocol, :scheme
95
138
 
96
139
  # Returns the port used to make API calls
97
140
  def port
98
- @port ||= (secure? ? 443 : 80)
141
+ @port ||= (self.secure? ? HTTPS_PORT_DEFAULT : HTTP_PORT_DEFAULT)
142
+ end
143
+
144
+ # Returns the port used to connect via SOCKS5
145
+ def proxy_port
146
+ @proxy_port ||= SOCKS5_PORT_DEFAULT
99
147
  end
100
148
 
101
149
  # Returns the endpoint URL to make API calls
102
150
  def url
103
- "#{self.protocol}://#{self.host}:#{self.port}"
151
+ '%s://%s%s' % [
152
+ self.scheme,
153
+ self.host,
154
+ self.port_default? ? '' : (':%d' % self.port)
155
+ ]
104
156
  end
105
157
 
106
- # Returns a properly configured Net::HTTP connection
158
+ # Returns a connection aimed at the API endpoint
107
159
  def http
108
- http = Net::HTTP::Proxy(
109
- self.proxy_host,
110
- self.proxy_port,
111
- self.proxy_user,
112
- self.proxy_pass
113
- ).new(self.host, self.port)
114
-
115
- http.read_timeout = self.http_read_timeout
116
- http.open_timeout = self.http_open_timeout
117
- http.use_ssl = self.secure?
118
-
119
- http
160
+ PostageApp::HTTP.connect(self)
120
161
  end
121
162
  end
@@ -0,0 +1,30 @@
1
+ require 'socket'
2
+
3
+ class PostageApp::Diagnostics
4
+ # == Instance Methods =====================================================
5
+
6
+ def initialize(config)
7
+ @config = config
8
+ end
9
+
10
+ def proxy_host_resolved
11
+ resolve(@config.proxy_host, 'socks5')
12
+ end
13
+
14
+ def host_resolved
15
+ resolve(@config.host, @config.protocol)
16
+ end
17
+
18
+ protected
19
+ def resolve(fqdn, service)
20
+ return unless (fqdn)
21
+
22
+ Socket.getaddrinfo(fqdn, service).map do |e|
23
+ # Result: [ family, port, name, ip, faily, socktype, protocol ]
24
+ e[3]
25
+ end.uniq
26
+
27
+ rescue SocketError
28
+ # Couldn't resolve, so nil
29
+ end
30
+ end
@@ -1,4 +1,6 @@
1
1
  module PostageApp::FailedRequest
2
+ # == Module Methods =======================================================
3
+
2
4
  # Stores request object into a file for future re-send
3
5
  # returns true if stored, false if not (due to undefined project path)
4
6
  def self.store(request)
@@ -0,0 +1,32 @@
1
+ module PostageApp::HTTP
2
+ # == Moduule Methods ======================================================
3
+
4
+ def self.connect(config)
5
+ connector =
6
+ if (config.proxy?)
7
+ Net::HTTP::Proxy(
8
+ config.proxy_host,
9
+ config.proxy_port || SOCKS5_PORT_DEFAULT,
10
+ config.proxy_user,
11
+ config.proxy_pass
12
+ )
13
+ else
14
+ Net::HTTP
15
+ end
16
+
17
+ http = connector.new(config.host, config.port)
18
+
19
+ unless (config.verify_certificate?)
20
+ context = OpenSSL::SSL::SSLContext.new
21
+ context.verify_mode = OpenSSL::SSL::VERIFY_NONE
22
+
23
+ http.send(:instance_variable_set, :@ssl_context, context)
24
+ end
25
+
26
+ http.read_timeout = config.http_read_timeout
27
+ http.open_timeout = config.http_open_timeout
28
+ http.use_ssl = config.secure?
29
+
30
+ http
31
+ end
32
+ end
@@ -1,4 +1,6 @@
1
1
  class PostageApp::Logger < ::Logger
2
+ # == Instance Methods =====================================================
3
+
2
4
  def format_message(severity, datetime, progname, msg)
3
5
  "[%s] %s\n" % [
4
6
  datetime.strftime('%m/%d/%Y %H:%M:%S %Z'),
@@ -1,3 +1,3 @@
1
- class PostageApp::Mail
1
+ module PostageApp::Mail
2
2
  require 'postageapp/mail/arguments'
3
3
  end
@@ -1,10 +1,16 @@
1
1
  class PostageApp::Request
2
+ # == Constants ============================================================
3
+
2
4
  API_VERSION = '1.0'
3
5
 
4
6
  HEADERS_DEFAULT = {
5
7
  'Content-type' => 'application/json',
6
8
  'Accept' => 'text/json, application/json'
7
9
  }
10
+
11
+ TimeoutError = defined?(::Timeout) ? ::Timeout::Error : ::TimeoutError
12
+
13
+ # == Properties ===========================================================
8
14
 
9
15
  # Unique ID (UID) for the request
10
16
  attr_writer :uid
@@ -19,6 +25,8 @@ class PostageApp::Request
19
25
  # Assigns the API key to be used for the request
20
26
  attr_accessor :api_key
21
27
 
28
+ # == Class Methods ========================================================
29
+
22
30
  # Returns a user-agent string used for identification when making API calls.
23
31
  def self.user_agent
24
32
  @user_agent ||=
@@ -28,6 +36,8 @@ class PostageApp::Request
28
36
  PostageApp.configuration.framework
29
37
  ]
30
38
  end
39
+
40
+ # == Instance Methods =====================================================
31
41
 
32
42
  # Creates a new Request with the given API call method and arguments.
33
43
  def initialize(method, arguments = nil)
@@ -45,18 +55,19 @@ class PostageApp::Request
45
55
 
46
56
  PostageApp.logger.info(self)
47
57
 
48
- http_response = begin
49
- http.post(
50
- url.path,
51
- self.arguments_to_send.to_json,
52
- HEADERS_DEFAULT.merge(
53
- 'User-Agent' => self.class.user_agent
58
+ http_response =
59
+ begin
60
+ http.post(
61
+ url.path,
62
+ self.arguments_to_send.to_json,
63
+ HEADERS_DEFAULT.merge(
64
+ 'User-Agent' => self.class.user_agent
65
+ )
54
66
  )
55
- )
56
67
 
57
- rescue TimeoutError, Errno::ECONNREFUSED
58
- nil
59
- end
68
+ rescue TimeoutError, Errno::ECONNREFUSED => e
69
+ e
70
+ end
60
71
 
61
72
  response = PostageApp::Response.new(http_response)
62
73
 
@@ -1,4 +1,11 @@
1
1
  class PostageApp::Response
2
+ # == Constants ============================================================
3
+
4
+ STATUS_TIMEOUT = 'timeout'.freeze
5
+ STATUS_FAIL = 'fail'.freeze
6
+
7
+ # == Properties ===========================================================
8
+
2
9
  # The UID should match the Request's UID. If Request didn't provide with one
3
10
  # PostageApp service should generate it for the Response
4
11
  attr_reader :uid
@@ -15,22 +22,29 @@ class PostageApp::Response
15
22
  attr_reader :data
16
23
 
17
24
  attr_reader :exception
25
+
26
+ # == Instance Methods =====================================================
18
27
 
19
28
  # Takes in Net::HTTPResponse object as the attribute.
20
29
  # If something goes wrong Response will be thought of as failed
21
30
  def initialize(http_response)
22
- hash = JSON::parse(http_response.body)
23
-
24
- _response = hash['response']
31
+ case (http_response)
32
+ when Exception
33
+ @status = STATUS_TIMEOUT
34
+ @message = '[%s] %s' % [ http_response.class, http_response.to_s ]
35
+ else
36
+ hash = JSON::parse(http_response.body)
37
+ _response = hash['response']
25
38
 
26
- @status = _response['status']
27
- @uid = _response['uid']
28
- @message = _response['message']
39
+ @status = _response['status']
40
+ @uid = _response['uid']
41
+ @message = _response['message']
29
42
 
30
- @data = hash['data']
43
+ @data = hash['data']
44
+ end
31
45
 
32
46
  rescue => e
33
- @status = 'fail'
47
+ @status = STATUS_FAIL
34
48
  @exception = '[%s] %s' % [ e.class, e ]
35
49
  end
36
50
 
@@ -31,14 +31,3 @@ class Hash
31
31
  end
32
32
  end
33
33
  end
34
-
35
- class Net::HTTP
36
- # Getting rid of the 'warning: peer certificate won't be verified in this SSL session'
37
- alias_method :__initialize, :initialize
38
- def initialize(*args)
39
- __initialize(*args)
40
-
41
- @ssl_context = OpenSSL::SSL::SSLContext.new
42
- @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
43
- end
44
- end
@@ -1,3 +1,3 @@
1
1
  module PostageApp
2
- VERSION = '1.2.6'.freeze
2
+ VERSION = '1.3.0'.freeze
3
3
  end
@@ -8,19 +8,19 @@ Gem::Specification.new do |s|
8
8
  s.name = 'postageapp'
9
9
  s.version = PostageApp::VERSION
10
10
  s.authors = [
11
- 'Oleg Khabarov',
12
11
  'Scott Tadman',
12
+ 'Oleg Khabarov',
13
13
  'The Working Group Inc.'
14
14
  ]
15
15
  s.email = [
16
- 'oleg@khabarov.ca',
17
- 'tadman@postageapp.com'
16
+ 'tadman@postageapp.com',
17
+ 'oleg@khabarov.ca'
18
18
  ]
19
19
 
20
20
  s.homepage = 'http://github.com/postageapp/postageapp-ruby'
21
21
 
22
- s.summary = 'Client for PostageApp Email API'
23
- s.description = 'Official client for the PostageApp email service'
22
+ s.summary = 'Client library for PostageApp Email API'
23
+ s.description = 'PostageApp Library for Ruby and Ruby on Rails applications'
24
24
  s.license = 'MIT'
25
25
 
26
26
  s.files = `git ls-files`.split("\n")
@@ -29,6 +29,6 @@ Gem::Specification.new do |s|
29
29
 
30
30
  s.required_ruby_version = '>= 1.9.3'
31
31
 
32
- s.add_dependency 'json'
33
- s.add_dependency 'mail'
32
+ s.add_dependency 'json', '~> 1.8'
33
+ s.add_dependency 'mail', '~> 2.4'
34
34
  end
@@ -1,18 +1,20 @@
1
- require File.expand_path('helper', File.dirname(__FILE__))
1
+ require_relative './helper'
2
2
 
3
3
  class ConfigurationTest < MiniTest::Test
4
4
  def test_initialization_defaults
5
5
  config = PostageApp::Configuration.new
6
6
 
7
7
  assert_equal true, config.secure
8
- assert_equal nil,config.api_key
9
- assert_equal 'https', config.protocol
10
- assert_equal 'api.postageapp.com', config.host
8
+ assert_equal ENV['POSTAGEAPP_API_KEY'], config.api_key
9
+ assert_equal 'https', config.scheme
10
+ assert_equal ENV['POSTAGEAPP_API_HOST'] || 'api.postageapp.com', config.host
11
11
  assert_equal 443, config.port
12
+
12
13
  assert_equal nil, config.proxy_host
13
- assert_equal nil, config.proxy_port
14
+ assert_equal 1080, config.proxy_port
14
15
  assert_equal nil, config.proxy_user
15
16
  assert_equal nil, config.proxy_pass
17
+
16
18
  assert_equal 5, config.http_open_timeout
17
19
  assert_equal 10, config.http_read_timeout
18
20
  assert_equal nil, config.recipient_override
@@ -26,10 +28,10 @@ class ConfigurationTest < MiniTest::Test
26
28
  def test_initialization_overrides
27
29
  config = PostageApp::Configuration.new
28
30
 
29
- config.protocol = 'http'
30
- config.port = 999
31
+ config.scheme = 'http'
32
+ config.port = 999
31
33
 
32
- assert_equal 'http', config.protocol
34
+ assert_equal 'http', config.scheme
33
35
  assert_equal 999, config.port
34
36
  end
35
37
 
@@ -37,11 +39,13 @@ class ConfigurationTest < MiniTest::Test
37
39
  config = PostageApp::Configuration.new
38
40
 
39
41
  config.secure = true
42
+
40
43
  assert_equal true, config.secure
41
- assert_equal 'https', config.protocol
44
+ assert_equal 'https', config.scheme
42
45
  assert_equal 443, config.port
43
46
 
44
- assert config.secure?
47
+ assert_equal true, config.secure?
48
+ assert_equal true, config.port_default?
45
49
  end
46
50
 
47
51
  def test_initialization_for_insecure
@@ -49,7 +53,7 @@ class ConfigurationTest < MiniTest::Test
49
53
 
50
54
  config.secure = false
51
55
  assert_equal false, config.secure
52
- assert_equal 'http', config.protocol
56
+ assert_equal 'http', config.scheme
53
57
  assert_equal 80, config.port
54
58
 
55
59
  assert !config.secure?
@@ -70,6 +74,9 @@ class ConfigurationTest < MiniTest::Test
70
74
  config = PostageApp::Configuration.new
71
75
 
72
76
  config.host = 'api.postageapp.com'
73
- assert_equal 'https://api.postageapp.com:443', config.url
77
+
78
+ assert_equal true, config.port_default?
79
+
80
+ assert_equal 'https://api.postageapp.com', config.url
74
81
  end
75
82
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('helper', File.dirname(__FILE__))
1
+ require_relative './helper'
2
2
 
3
3
  class FailedRequestTest < MiniTest::Test
4
4
  def setup
@@ -45,24 +45,11 @@ class MiniTest::Test
45
45
  def setup
46
46
  # Resetting to default configuration
47
47
 
48
- PostageApp.configure do |config|
49
- config.api_key = '1234567890abcdef'
50
- config.secure = true
51
- config.protocol = 'https'
52
- config.host = 'api.postageapp.com'
53
- config.port = 443
54
- config.proxy_host = nil
55
- config.proxy_port = nil
56
- config.proxy_user = nil
57
- config.proxy_pass = nil
58
- config.http_open_timeout = 5
59
- config.http_read_timeout = 10
60
- config.recipient_override = nil
48
+ PostageApp.configure(:reset) do |config|
61
49
  config.requests_to_resend = %w( send_message )
62
50
  config.project_root = File.expand_path('../', __FILE__)
63
- config.environment = 'production'
64
51
  config.logger = nil
65
- config.framework = 'undefined framework'
52
+ config.framework = 'Ruby [Test]'
66
53
  end
67
54
 
68
55
  if (defined?(ActionMailer))
@@ -1,20 +1,17 @@
1
- require File.expand_path('helper', File.dirname(__FILE__))
1
+ require_relative './helper'
2
2
 
3
3
  class LiveTest < MiniTest::Test
4
4
  # Note: Need access to a live PostageApp.com account
5
5
  # See helper.rb to set host / api key
6
6
 
7
- if (ENV['POSTAGEAPP_LIVE_TESTS'])
8
- def setup
9
- super
10
-
11
- PostageApp.configure do |config|
12
- config.secure = false
13
- config.host = 'api.postageapp.local'
14
- config.api_key = 'PROJECT_API_KEY'
15
- end
7
+ if (ENV['POSTAGEAPP_API_KEY'])
8
+ def test_configuration
9
+ config = PostageApp.config
10
+
11
+ assert config
12
+ assert_equal ENV['POSTAGEAPP_API_KEY'], config.api_key
16
13
  end
17
-
14
+
18
15
  def test_request_get_method_list
19
16
  request = PostageApp::Request.new(:get_method_list)
20
17
  response = request.send
@@ -25,14 +22,34 @@ class LiveTest < MiniTest::Test
25
22
  assert_equal nil, response.message
26
23
  assert_equal(
27
24
  {
28
- 'methods' => 'get_account_info, get_message_receipt, get_method_list, get_project_info, send_message'
25
+ 'methods' => %w[
26
+ get_account_info
27
+ get_message_receipt
28
+ get_message_transmissions
29
+ get_messages
30
+ get_method_list
31
+ get_metrics
32
+ get_project_info
33
+ get_recipients_list
34
+ get_suppression_list
35
+ message_delivery_status
36
+ message_status
37
+ messages_history
38
+ project_create
39
+ project_destroy
40
+ project_info
41
+ send_message
42
+ test_mail_server
43
+ test_recipient
44
+ ].join(', ')
29
45
  },
30
46
  response.data
31
47
  )
32
48
  end
33
49
 
34
50
  def test_request_send_message
35
- request = PostageApp::Request.new(:send_message, {
51
+ request = PostageApp::Request.new(
52
+ :send_message,
36
53
  headers: {
37
54
  'from' => 'sender@example.com',
38
55
  'subject' => 'Test Message'
@@ -42,7 +59,7 @@ class LiveTest < MiniTest::Test
42
59
  'text/plain' => 'text content',
43
60
  'text/html' => 'html content'
44
61
  }
45
- })
62
+ )
46
63
 
47
64
  response = request.send
48
65
 
@@ -74,35 +91,43 @@ class LiveTest < MiniTest::Test
74
91
  response = request.send
75
92
 
76
93
  assert_equal 'PostageApp::Response', response.class.name
77
- assert_equal 'internal_server_error', response.status
94
+ assert_equal 'call_error', response.status
95
+
78
96
  assert_match(/\A\w{40}$/, response.uid)
79
- assert_match(/\ANo action responded to non_existant/, response.message)
97
+ assert_match(/\ARequest could not be processed/, response.message)
80
98
  assert_equal nil, response.data
81
99
  end
82
100
 
83
101
  # Testable under ruby 1.9.2 Probably OK in production too... Probably
84
102
  # Lunchtime reading: http://ph7spot.com/musings/system-timer
85
103
  def test_request_timeout
86
- PostageApp.configuration.host = '127.0.0.254'
104
+ PostageApp.configuration.host = '127.0.0.255'
87
105
 
88
106
  request = PostageApp::Request.new(:get_method_list)
89
107
 
90
108
  response = request.send
91
109
 
92
110
  assert_equal 'PostageApp::Response', response.class.name
93
- assert_equal 'fail', response.status
111
+ assert_equal 'timeout', response.status
94
112
  end
95
113
 
96
- def test_deliver_with_custom_postage_variables
97
- response = if ActionMailer::VERSION::MAJOR < 3
98
- require File.expand_path('../mailer/action_mailer_2/notifier', __FILE__)
99
- Notifier.deliver_with_custom_postage_variables
100
- else
101
- require File.expand_path('../mailer/action_mailer_3/notifier', __FILE__)
102
- Notifier.with_custom_postage_variables.deliver
114
+ if (defined?(Rails))
115
+ def test_deliver_with_custom_postage_variables
116
+ response =
117
+ if (ActionMailer::VERSION::MAJOR < 3)
118
+ require File.expand_path('../mailer/action_mailer_2/notifier', __FILE__)
119
+
120
+ Notifier.deliver_with_custom_postage_variables
121
+ else
122
+ require File.expand_path('../mailer/action_mailer_3/notifier', __FILE__)
123
+
124
+ Notifier.with_custom_postage_variables.deliver
125
+ end
126
+
127
+ assert_equal 'ok', response.status
128
+ assert_equal true, response.ok?
103
129
  end
104
- assert response.ok?
105
- end
130
+ end
106
131
  else
107
132
  puts "\e[0m\e[31mSkipping #{File.basename(__FILE__)}\e[0m"
108
133
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('helper', File.dirname(__FILE__))
1
+ require_relative './helper'
2
2
 
3
3
  class MailerDeliveryTest < MiniTest::Test
4
4
  def setup
@@ -1,4 +1,5 @@
1
- # Test mailer for ActionMailer 2
1
+ # Test mailer for ActionMailer 2.x
2
+
2
3
  class Notifier < PostageApp::Mailer
3
4
  self.template_root = File.dirname(__FILE__)
4
5
 
@@ -31,14 +32,14 @@ class Notifier < PostageApp::Mailer
31
32
  )
32
33
 
33
34
  part(
34
- :content_type => 'text/plain',
35
- :body => 'text content'
35
+ content_type: 'text/plain',
36
+ body: 'text content'
36
37
  )
37
38
 
38
39
  attachment(
39
- :content_type => 'image/jpeg',
40
- :filename => 'foo.jpg',
41
- :body => '123456789'
40
+ content_type: 'image/jpeg',
41
+ filename: 'foo.jpg',
42
+ body: '123456789'
42
43
  )
43
44
  end
44
45
 
@@ -46,9 +47,9 @@ class Notifier < PostageApp::Mailer
46
47
  setup_headers
47
48
 
48
49
  attachment(
49
- :content_type => 'image/jpeg',
50
- :filename => 'foo.jpg',
51
- :body => '123456789'
50
+ content_type: 'image/jpeg',
51
+ filename: 'foo.jpg',
52
+ body: '123456789'
52
53
  )
53
54
  end
54
55
 
@@ -1,4 +1,4 @@
1
- # Test mailer for ActionMailer 3 and 4
1
+ # Test mailer for ActionMailer 3.x+
2
2
 
3
3
  class Notifier < PostageApp::Mailer
4
4
  self.append_view_path(File.dirname(__FILE__))
@@ -66,9 +66,9 @@ class Notifier < PostageApp::Mailer
66
66
  postageapp_uid 'custom_uid'
67
67
 
68
68
  mail(
69
- :from => 'sender@example.com',
70
- :subject => 'Test Message',
71
- :to => {
69
+ from: 'sender@example.com',
70
+ subject: 'Test Message',
71
+ to: {
72
72
  'test1@example.net' => { 'name' => 'Test 1' },
73
73
  'test2@example.net' => { 'name' => 'Test 2' }
74
74
  }
@@ -76,11 +76,11 @@ class Notifier < PostageApp::Mailer
76
76
  end
77
77
 
78
78
  private
79
- def headers_hash(options = { })
79
+ def headers_hash(options = nil)
80
80
  {
81
- :from => 'sender@example.com',
82
- :to => 'recipient@example.net',
83
- :subject => 'Test Message'
84
- }.merge(options)
81
+ from: 'sender@example.com',
82
+ to: 'recipient@example.net',
83
+ subject: 'Test Message'
84
+ }.merge(options || { })
85
85
  end
86
86
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('helper', File.dirname(__FILE__))
1
+ require_relative './helper'
2
2
 
3
3
  class Mailer2Test < MiniTest::Test
4
4
  require_action_mailer(2) do
@@ -1,4 +1,4 @@
1
- require File.expand_path('helper', File.dirname(__FILE__))
1
+ require_relative './helper'
2
2
 
3
3
  class Mailer3Test < MiniTest::Test
4
4
  require_action_mailer(3) do
@@ -1,4 +1,4 @@
1
- require File.expand_path('helper', File.dirname(__FILE__))
1
+ require_relative './helper'
2
2
 
3
3
  class Mailer4Test < MiniTest::Test
4
4
  require_action_mailer(4) do
@@ -1,4 +1,4 @@
1
- require File.expand_path('helper', File.dirname(__FILE__))
1
+ require_relative './helper'
2
2
 
3
3
  class MailerHelperMethodsTest < MiniTest::Test
4
4
  def test_mailer_helper_methods
@@ -1,4 +1,4 @@
1
- require File.expand_path('helper', File.dirname(__FILE__))
1
+ require_relative './helper'
2
2
 
3
3
  class PostageAppTest < MiniTest::Test
4
4
  def test_method_configure
@@ -9,6 +9,9 @@ class PostageAppTest < MiniTest::Test
9
9
 
10
10
  assert_equal 'abcdefg12345', PostageApp.configuration.api_key
11
11
  assert_equal 'test.test', PostageApp.configuration.host
12
+
13
+ ensure
14
+ PostageApp.configuration_reset!
12
15
  end
13
16
 
14
17
  def test_logger
@@ -1,4 +1,4 @@
1
- require File.expand_path('helper', File.dirname(__FILE__))
1
+ require_relative './helper'
2
2
 
3
3
  require File.expand_path('../lib/postageapp/rails/rails', File.dirname(__FILE__))
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('helper', File.dirname(__FILE__))
1
+ require_relative './helper'
2
2
 
3
3
  class RequestTest < MiniTest::Test
4
4
  def test_method_uid
@@ -34,22 +34,22 @@ class RequestTest < MiniTest::Test
34
34
 
35
35
  args = request.arguments_to_send
36
36
 
37
- assert_equal '1234567890abcdef', args['api_key']
37
+ assert !args['api_key'].empty?
38
38
  assert_match(/^\w{40}$/, args['uid'])
39
39
 
40
40
  payload = args['arguments']
41
41
 
42
42
  assert_equal 'sender@test.test', payload['headers']['from']
43
- assert_equal 'Test Message', payload['headers']['subject']
44
- assert_equal 'test@test.test', payload['recipients']
45
- assert_equal 'text content', payload['content']['text/plain']
46
- assert_equal 'html content', payload['content']['text/html']
43
+ assert_equal 'Test Message', payload['headers']['subject']
44
+ assert_equal 'test@test.test', payload['recipients']
45
+ assert_equal 'text content', payload['content']['text/plain']
46
+ assert_equal 'html content', payload['content']['text/html']
47
47
 
48
48
  request.arguments = { 'data' => 'content' }
49
49
 
50
50
  args = request.arguments_to_send
51
51
 
52
- assert_equal '1234567890abcdef', args['api_key']
52
+ assert !args['api_key'].empty?
53
53
  assert_match(/^\w{40}$/, args['uid'])
54
54
  assert_equal 'content', args['arguments']['data']
55
55
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('helper', File.dirname(__FILE__))
1
+ require_relative './helper'
2
2
 
3
3
  class ResponseTest < MiniTest::Test
4
4
  def test_initialization
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postageapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.6
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - Oleg Khabarov
8
7
  - Scott Tadman
8
+ - Oleg Khabarov
9
9
  - The Working Group Inc.
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-08-16 00:00:00.000000000 Z
13
+ date: 2016-09-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - '>='
19
+ - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: '1.8'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - '>='
26
+ - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: '0'
28
+ version: '1.8'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: mail
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - '>='
33
+ - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: '0'
35
+ version: '2.4'
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - '>='
40
+ - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: '0'
43
- description: Official client for the PostageApp email service
42
+ version: '2.4'
43
+ description: PostageApp Library for Ruby and Ruby on Rails applications
44
44
  email:
45
- - oleg@khabarov.ca
46
45
  - tadman@postageapp.com
46
+ - oleg@khabarov.ca
47
47
  executables: []
48
48
  extensions: []
49
49
  extra_rdoc_files: []
50
50
  files:
51
- - .gitignore
52
- - .travis.yml
51
+ - ".gitignore"
52
+ - ".travis.yml"
53
53
  - Gemfile
54
54
  - LICENSE
55
55
  - README.md
@@ -62,7 +62,9 @@ files:
62
62
  - lib/generators/postageapp/postageapp_generator.rb
63
63
  - lib/postageapp.rb
64
64
  - lib/postageapp/configuration.rb
65
+ - lib/postageapp/diagnostics.rb
65
66
  - lib/postageapp/failed_request.rb
67
+ - lib/postageapp/http.rb
66
68
  - lib/postageapp/logger.rb
67
69
  - lib/postageapp/mail.rb
68
70
  - lib/postageapp/mail/arguments.rb
@@ -133,18 +135,18 @@ require_paths:
133
135
  - lib
134
136
  required_ruby_version: !ruby/object:Gem::Requirement
135
137
  requirements:
136
- - - '>='
138
+ - - ">="
137
139
  - !ruby/object:Gem::Version
138
140
  version: 1.9.3
139
141
  required_rubygems_version: !ruby/object:Gem::Requirement
140
142
  requirements:
141
- - - '>='
143
+ - - ">="
142
144
  - !ruby/object:Gem::Version
143
145
  version: '0'
144
146
  requirements: []
145
147
  rubyforge_project:
146
- rubygems_version: 2.0.14.1
148
+ rubygems_version: 2.5.1
147
149
  signing_key:
148
150
  specification_version: 4
149
- summary: Client for PostageApp Email API
151
+ summary: Client library for PostageApp Email API
150
152
  test_files: []