postageapp 1.2.0 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -7,3 +7,4 @@ test/log
7
7
  test/gemfiles/*.lock
8
8
  Gemfile.lock
9
9
  .ruby-version
10
+ *.gem
@@ -1,10 +1,13 @@
1
1
  language: ruby
2
- before_install: gem install bundler
2
+ before_install: "WITH_VERBOSE=1 script/with current bootstrap"
3
+ install: "WITH_VERBOSE=1 script/with current bundle install"
4
+ script: "WITH_VERBOSE=1 script/with current bundle exec rake test"
3
5
  rvm:
4
6
  - 1.9.3-p551
5
7
  - 2.0.0-p598
6
8
  - 2.1.5
7
9
  - 2.2.0
10
+ - 2.3.0
8
11
  gemfile:
9
12
  - test/gemfiles/Gemfile.ruby
10
13
  - test/gemfiles/Gemfile.rails-2.3.x
@@ -22,3 +25,13 @@ matrix:
22
25
  gemfile: test/gemfiles/Gemfile.rails-2.3.x
23
26
  - rvm: 2.2.0
24
27
  gemfile: test/gemfiles/Gemfile.rails-2.3.x
28
+ - rvm: 2.3.0
29
+ gemfile: test/gemfiles/Gemfile.rails-2.3.x
30
+ - rvm: 1.9.3-p551
31
+ gemfile: test/gemfiles/Gemfile.rails-2.3.x
32
+ - rvm: 1.9.3-p551
33
+ gemfile: test/gemfiles/Gemfile.rails-4.0.x
34
+ - rvm: 1.9.3-p551
35
+ gemfile: test/gemfiles/Gemfile.rails-4.1.x
36
+ - rvm: 1.9.3-p551
37
+ gemfile: test/gemfiles/Gemfile.rails-4.2.x
data/README.md CHANGED
@@ -274,4 +274,4 @@ end
274
274
 
275
275
  # Copyright
276
276
 
277
- (C) 2011-2015 Scott Tadman, Oleg Khabarov, [The Working Group, Inc](http://www.twg.ca/)
277
+ (C) 2011-2016 Scott Tadman, Oleg Khabarov, [PostageApp](http://www.postageapp.com/)
@@ -21,11 +21,11 @@ class PostageappGenerator < Rails::Generator::Base
21
21
 
22
22
  record do |m|
23
23
  m.template 'initializer.rb', 'config/initializers/postageapp.rb',
24
- :assigns => { :api_key => options[:api_key] },
25
- :collision => :force
24
+ assigns: { api_key: options[:api_key] },
25
+ collision: :force
26
26
  m.directory 'lib/tasks'
27
27
  m.file 'postageapp_tasks.rake', 'lib/tasks/postageapp_tasks.rake',
28
- :collision => :force
28
+ collision: :force
29
29
  m.rake 'postageapp:test'
30
30
  end
31
31
  end
@@ -1,23 +1,52 @@
1
1
  namespace :postageapp do
2
-
3
- desc 'Verify postageapp gem installation by requesting project info from PostageApp.com'
2
+ desc 'Show the current PostageApp configuration'
3
+ task :config => :environment do
4
+ puts "PostageApp Configuration"
5
+ puts "------------------------"
6
+ puts
7
+
8
+ config = PostageApp.config
9
+
10
+ puts "API Key: %s" % config.api_key
11
+ puts "API Endpoint: %s" % config.url
12
+ puts "Secure: %s" % [ config.secure? ? 'Yes' : 'No' ]
13
+
14
+ if (config.proxy_host)
15
+ puts "SOCKS5 Proxy: %s:%d" % [ config.proxy_host, config.proxy_port ]
16
+
17
+ if (config.proxy_user)
18
+ puts "SOCKS5 Auth: %s / %s" % [ config.proxy_user, config.proxy_pass ]
19
+ end
20
+ end
21
+
22
+ puts "Open Timeout: %d seconds" % [ config.http_open_timeout ]
23
+ puts "Read Timeout: %d seconds" % [ config.http_read_timeout ]
24
+
25
+ if (config.recipient_override)
26
+ puts "Recipient Override: %s" % [ config.recipient_override ]
27
+ end
28
+
29
+ puts "Environment: %s" % [ config.environment ]
30
+ end
31
+
32
+ desc 'Verify the PostageApp gem installation by requesting project info from the API'
4
33
  task :test => :environment do
5
34
 
6
35
  puts "Attempting to contact #{PostageApp.configuration.host} ..."
7
36
  response = PostageApp::Request.new(:get_project_info).send
8
37
 
9
38
  if response.ok?
10
- project_name = response.data['project']['name']
11
- project_url = response.data['project']['url']
12
- user_emails = response.data['project']['users']
39
+ project_name = response.data['project']['name']
40
+ project_url = response.data['project']['url']
41
+ user_emails = response.data['project']['users']
13
42
 
14
- puts %{
43
+ puts <<END
15
44
  Found Project:
16
45
  ----------------------------
17
46
  Name: #{ project_name }
18
47
  URL: #{ project_url }
19
48
  Users: #{ user_emails.keys.join(', ') }
20
- }
49
+ END
21
50
 
22
51
  # Sending test email to all users in the project
23
52
  # Most likely a single user if it's a new project
@@ -47,15 +76,15 @@ namespace :postageapp do
47
76
 
48
77
  end
49
78
 
50
- HTML_MESSAGE = %{
79
+ HTML_MESSAGE = <<END
51
80
  <h3> Hello {{name}}, </h3>
52
- <p> This is a html message generated by Postage plugin. </p>
53
- <p> If you received this message it means that your application is properly configured and is ready to use PostageApp service. </p>
54
- <p> Thank you, </p>
55
- <p> The PostageApp Team </p>
56
- }
81
+ <p>This is a html message generated by Postage plugin.</p>
82
+ <p>If you received this message it means that your application is properly configured and is ready to use PostageApp service.</p>
83
+ <p>Thank you,</p>
84
+ <p>The PostageApp Team</p>
85
+ END
57
86
 
58
- TEXT_MESSAGE = %{
87
+ TEXT_MESSAGE = <<END
59
88
  Hello {{name}}
60
89
 
61
90
  This is a plain text message generated by Postage plugin.
@@ -63,23 +92,27 @@ If you received this message it means that your application is properly configur
63
92
 
64
93
  Thank you,
65
94
  The PostageApp Team
66
- }
95
+ END
67
96
 
68
97
  def send_test_message(recipients)
69
- recipients_with_variables = {}
98
+ recipients_with_variables = { }
99
+
70
100
  recipients.each do |email, name|
71
- recipients_with_variables[email] = { 'name' => name }
101
+ recipients_with_variables[email] = {
102
+ 'name' => name
103
+ }
72
104
  end
73
105
 
74
- PostageApp::Request.new(:send_message,
75
- :message => {
76
- 'text/html' => HTML_MESSAGE,
106
+ PostageApp::Request.new(
107
+ :send_message,
108
+ message: {
109
+ 'text/html' => HTML_MESSAGE,
77
110
  'text/plain' => TEXT_MESSAGE
78
111
  },
79
- :recipients => recipients_with_variables,
80
- :headers => {
112
+ recipients: recipients_with_variables,
113
+ headers: {
81
114
  'Subject' => '[PostageApp] Test Message',
82
- 'From' => 'no-return@postageapp.com'
115
+ 'From' => 'no-return@postageapp.com'
83
116
  }
84
117
  ).send
85
- end
118
+ end
@@ -3,14 +3,14 @@ require 'rails/generators'
3
3
  # Rails 3 Generator
4
4
  class PostageappGenerator < Rails::Generators::Base
5
5
  class_option :api_key,
6
- :aliases => [ '-k=value', '--api-key=value' ],
7
- :type => :string,
8
- :desc => 'Your PostageApp API key'
6
+ aliases: [ '-k=value', '--api-key=value' ],
7
+ type: :string,
8
+ desc: 'Your PostageApp API key'
9
9
 
10
10
  def self.source_root
11
- @_hoptoad_source_root ||= File.expand_path(
12
- '../../../../generators/postageapp/templates',
13
- __FILE__
11
+ @__source_root ||= File.expand_path(
12
+ '../../../generators/postageapp/templates',
13
+ File.dirname(__FILE__)
14
14
  )
15
15
  end
16
16
 
@@ -63,4 +63,6 @@ end
63
63
 
64
64
  require 'postageapp/mail/extensions'
65
65
 
66
- PostageApp::Mail::Extensions.install!
66
+ if (defined?(::Mail))
67
+ PostageApp::Mail::Extensions.install!
68
+ end
@@ -1,64 +1,76 @@
1
+ # PostageApp::Configuration is used to retrieve and manipulate the options
2
+ # used to connect to the API. There are a number of options which can be set.
3
+ # The recommended method for doing this is via the initializer file that's
4
+ # generated upon installation: config/initializers/postageapp.rb
5
+
6
+ # Basic Options
7
+ # -------------
8
+ # :api_key - The API key used to send requests, can also be set via the
9
+ # POSTAGEAPP_API_KEY environment variable. (required)
10
+ # :secure - true for HTTPS, false for HTTP connections (default: true)
11
+ # :recipient_override - Email address to send all email to regardless of
12
+ # specified recipients. Used for testing.
13
+
14
+ # Non-Rails Options
15
+ # -----------------
16
+ # :project_root - The base path of the project, used to determine where to
17
+ # save log files and failed API calls.
18
+ # :framework - A string identifier for the framework being used. Shows up in
19
+ # the User-Agent identifier of requests.
20
+ # :environment - The operational mode of the application, typically either
21
+ # 'production' or 'development' but any string value is allowed.
22
+ # (default: 'production')
23
+ # :logger - Used to assign a specific logger.
24
+
25
+ # Network Options
26
+ # ---------------
27
+ # :host - The API host to connect to (default: 'api.postageapp.com')
28
+ # :http_open_timeout - HTTP open timeout in seconds (default: 2)
29
+ # :http_read_timeout - Read timeout in seconds (default: 5)
30
+
31
+ # Proxy Options
32
+ # -------------
33
+ # :proxy_host - Proxy server hostname
34
+ # :proxy_port - Proxy server port
35
+ # :proxy_user - Proxy server username
36
+ # :proxy_pass - Proxy server password
37
+
38
+ # Advanced Options
39
+ # ----------------
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)
42
+ # :requests_to_resend - List of API calls that should be replayed if they fail.
43
+ # (default: send_message)
44
+
1
45
  class PostageApp::Configuration
2
- # +true+ for https, +false+ for http connections (default: is +true+)
3
46
  attr_accessor :secure
4
-
5
- # The protocol used to connect to the service (default: 'https' for secure
6
- # and 'http' for insecure connections)
7
- attr_accessor :protocol
8
-
9
- # The host to connect to (default: 'api.postageapp.com')
47
+ attr_writer :protocol
10
48
  attr_accessor :host
11
-
12
- # The port on which PostageApp service runs (default: 443 for secure, 80 for
13
- # insecure connections)
14
49
  attr_writer :port
15
-
16
- # The hostname of the proxy server (if using a proxy)
17
50
  attr_accessor :proxy_host
18
-
19
- # The port of the proxy server (if using proxy)
20
51
  attr_accessor :proxy_port
21
-
22
- # The username for the proxy server (if using proxy)
23
52
  attr_accessor :proxy_user
24
-
25
- # The password for the proxy server (if using proxy)
26
53
  attr_accessor :proxy_pass
27
-
28
- # The HTTP open timeout in seconds (defaults to 2).
29
54
  attr_accessor :http_open_timeout
30
-
31
- # The HTTP read timeout in seconds (defaults to 5).
32
55
  attr_accessor :http_read_timeout
33
-
34
- # The email address that all send_message method should address
35
- # all messages while overriding original addresses
36
56
  attr_accessor :recipient_override
37
-
38
- # A list of API method names payloads of which are captured and resent
39
- # in case of service unavailability
40
57
  attr_accessor :requests_to_resend
41
-
42
- # The file path of the project. This is where logs and failed requests
43
- # can be stored
44
58
  attr_accessor :project_root
45
-
46
- # The framework PostageApp gem runs in
47
59
  attr_accessor :framework
48
-
49
- # Environment gem is running in
50
60
  attr_accessor :environment
51
-
52
- # The logger used by this gem
53
61
  attr_accessor :logger
54
62
 
55
63
  def initialize
56
64
  @secure = true
57
65
  @host = 'api.postageapp.com'
66
+
58
67
  @http_open_timeout = 5
59
68
  @http_read_timeout = 10
60
- @requests_to_resend = %w( send_message )
61
- @framework = 'undefined framework'
69
+
70
+ @requests_to_resend = %w[ send_message ]
71
+
72
+ @framework = 'Ruby'
73
+
62
74
  @environment = 'production'
63
75
  end
64
76
 
@@ -91,7 +103,7 @@ class PostageApp::Configuration
91
103
  "#{self.protocol}://#{self.host}:#{self.port}"
92
104
  end
93
105
 
94
- # Returns a properly config
106
+ # Returns a properly configured Net::HTTP connection
95
107
  def http
96
108
  http = Net::HTTP::Proxy(
97
109
  self.proxy_host,
@@ -5,7 +5,7 @@ module PostageApp::FailedRequest
5
5
  return false unless (self.store_path)
6
6
  return false unless (PostageApp.configuration.requests_to_resend.member?(request.method.to_s))
7
7
 
8
- unless (File.exists?(file_path(request.uid)))
8
+ unless (File.exist?(file_path(request.uid)))
9
9
  open(file_path(request.uid), 'wb') do |f|
10
10
  f.write(Marshal.dump(request))
11
11
  end
@@ -34,7 +34,7 @@ module PostageApp::FailedRequest
34
34
 
35
35
  receipt_response = PostageApp::Request.new(
36
36
  :get_message_receipt,
37
- :uid => filename
37
+ uid: filename
38
38
  ).send(true)
39
39
 
40
40
  if (receipt_response.fail?)
@@ -67,7 +67,7 @@ module PostageApp::FailedRequest
67
67
  # Initializing PostageApp::Request object from the file
68
68
  def self.initialize_request(uid)
69
69
  return false unless (self.store_path)
70
- return false unless (File.exists?(file_path(uid)))
70
+ return false unless (File.exist?(file_path(uid)))
71
71
 
72
72
  Marshal.load(File.read(file_path(uid)))
73
73
 
@@ -86,7 +86,7 @@ protected
86
86
  'tmp/postageapp_failed_requests'
87
87
  )
88
88
 
89
- unless (File.exists?(dir))
89
+ unless (File.exist?(dir))
90
90
  FileUtils.mkdir_p(dir)
91
91
  end
92
92
 
@@ -11,94 +11,11 @@ if (defined?(ActionMailer))
11
11
  # currently installed on the system. Assuming we're dealing only with
12
12
  # ones that come with Rails 2 and 3
13
13
  case (ActionMailer::VERSION::MAJOR)
14
- when 4
15
- require File.expand_path('mailer/mailer_4', File.dirname(__FILE__))
16
14
  when 3
17
15
  require File.expand_path('mailer/mailer_3', File.dirname(__FILE__))
18
- else
16
+ when 2
19
17
  require File.expand_path('mailer/mailer_2', File.dirname(__FILE__))
20
- end
21
- end
22
-
23
- # General helper methods for Request object to act more like TMail::Mail
24
- # of Mail for testing
25
- class PostageApp::Request
26
- # Getter and setter for headers. You can specify headers in the following
27
- # formats:
28
- # headers['Custom-Header'] = 'Custom Value'
29
- # headers 'Custom-Header-1' => 'Custom Value 1',
30
- # 'Custom-Header-2' => 'Custom Value 2'
31
- def headers(value = nil)
32
- _headers = self.arguments['headers'] ||= { }
33
-
34
- case (value)
35
- when Hash
36
- value.each do |k, v|
37
- _headers[k.to_s] = v.to_s
38
- end
39
- end
40
-
41
- _headers
42
- end
43
-
44
- def [](key)
45
- case (key)
46
- when :to, 'to'
47
- self.to
48
- when :from, 'from'
49
- self.from
50
- when :bcc, 'bcc'
51
- # Not supported via API at this time
52
- [ ]
53
- end
54
- end
55
-
56
- def to
57
- out = self.arguments_to_send.dig('arguments', 'recipients')
58
-
59
- case (out)
60
- when Hash
61
- out
62
- else
63
- [ out ].flatten
64
- end
65
- end
66
-
67
- def to=(list)
68
- self.arguments['recipients'] = list
69
- end
70
-
71
- def from
72
- [ self.arguments_to_send.dig('arguments', 'headers', 'from') ].flatten
73
- end
74
-
75
- def from=(address)
76
- _headers = self.arguments['headers'] ||= { }
77
-
78
- _headers['from'] = address.to_s
79
- end
80
-
81
- def bcc
82
- # Not supported natively via API at this time
83
- [ ]
84
- end
85
-
86
- def bcc=(list)
87
- # Not supported natively via API at this time
88
- end
89
-
90
- def subject
91
- self.arguments_to_send.dig('arguments', 'headers', 'subject')
92
- end
93
-
94
- def subject=(subject)
95
- _headers = self.arguments['headers'] ||= { }
96
-
97
- _headers['subject'] = subject.to_s
98
- end
99
-
100
- def body
101
- out = self.arguments_to_send.dig('arguments', 'content')
102
- out.is_a?(Hash) ? out.values.join("\n\n") : out.to_s
18
+ else
19
+ require File.expand_path('mailer/mailer_4', File.dirname(__FILE__))
103
20
  end
104
21
  end