google-http-actionmailer 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4c49b1cf78e1d9525108d53bccf04f316115d289f0dbbf01d8e60da1916099a
4
- data.tar.gz: a49d301415298d9d6680d2cc2041f4a7874a9e0bf073f90a47c0e9744fa2003c
3
+ metadata.gz: 5681fb59448881c9fd4872b3e63c5d0b23ab8f5c8f329c0558fd5860881456ec
4
+ data.tar.gz: 94601ff306b9a1af4610b71c0566c1365a2061ed6c494674940c7d2dd0e16566
5
5
  SHA512:
6
- metadata.gz: 239cf6f032ba6ef893024d2fd90124055bdc36546dc943cc7ead7cb7188c9babf0ab16b5a5b00606a5efd4d338018753e84033244ec5c896b16cefe5f78abf59
7
- data.tar.gz: fb64d96c1383a39487966d7f60bf17261944b4ae694b5b8f1900e254784a8e511f9542fb8c5941a9a66f94ae86f4ae396d2fbd33f7e41b6ed519716918585944
6
+ metadata.gz: 791f3bb2d5cd9e10b8d21b67618fdce58e7f11373cf33aa838f122296c09afd932445e8763259ea29a1360a88e715ace1a763971961b0723fbd83772a8e06264
7
+ data.tar.gz: 76ed809027807736bacce6d0dd14c3e3bfe370123c5b48e45df9d64a04ae63246feef6f731a83f905dbbe248bbc806956e0bc598413db296beb88793aa49a9a0
data/README.md CHANGED
@@ -1,15 +1,13 @@
1
1
  # GoogleHttpActionmailer
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/google_http_actionmailer`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ An ActionMailer adapter to send email using Google's HTTPS Web API (instead of SMTP).
6
4
 
7
5
  ## Installation
8
6
 
9
7
  Add this line to your application's Gemfile:
10
8
 
11
9
  ```ruby
12
- gem 'google_http_actionmailer'
10
+ gem 'google-http-actionmailer'
13
11
  ```
14
12
 
15
13
  And then execute:
@@ -18,11 +16,43 @@ And then execute:
18
16
 
19
17
  Or install it yourself as:
20
18
 
21
- $ gem install google_http_actionmailer
19
+ $ gem install google-http-actionmailer
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ Set up your `authorization` as described in the [Google API Client](https://github.com/google/google-api-ruby-client/#authorization) (the easiest method is to pass a valid access token), edit `config/application.rb` or `config/environments/$ENVIRONMENT.rb` and add/change the following to the ActionMailer configuration:
24
+
25
+ ```ruby
26
+ config.action_mailer.delivery_method = :google_http_actionmailer
27
+ config.action_mailer.google_http_actionmailer_settings = {
28
+ authorization: ...,
29
+ client_options: {
30
+ application_name: ...,
31
+ application_version: ...,
32
+ },
33
+ request_options: {
34
+ retries: ...,
35
+ header: ...,
36
+ },
37
+ message_options: {
38
+ fields: ...,
39
+ content_type: ...,
40
+ }
41
+ }
42
+ ```
43
+
44
+ For client and request options, you can look [here](https://github.com/google/google-api-ruby-client/blob/master/lib/google/apis/options.rb). And for message options, you can look at the `send_user_message` method [here](https://github.com/google/google-api-ruby-client/blob/master/generated/google/apis/gmail_v1/service.rb#L1150).
45
+
46
+ For dynamic setting of delivery method (this may be required given the access tokens usually expire):
47
+
48
+ ```ruby
49
+ mail.delivery_method(
50
+ GoogleHttpActionmailer::DeliveryMethod, {
51
+ authorization: ...
52
+ })
53
+ ```
54
+
55
+ Normal ActionMailer usage will now transparently be sent using Google's HTTPS API.
26
56
 
27
57
  ## Development
28
58
 
@@ -1,3 +1,3 @@
1
1
  module GoogleHttpActionmailer
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -9,6 +9,7 @@ module GoogleHttpActionmailer
9
9
  class DeliveryMethod
10
10
  attr_reader :service
11
11
  attr_reader :message_options
12
+ attr_reader :delivery_options
12
13
 
13
14
  def initialize(params)
14
15
  @service = Google::Apis::GmailV1::GmailService.new
@@ -26,6 +27,7 @@ module GoogleHttpActionmailer
26
27
  end
27
28
 
28
29
  @message_options = params[:message_options] || {}
30
+ @delivery_options = params[:delivery_options] || {}
29
31
  end
30
32
 
31
33
  def deliver!(mail)
@@ -35,7 +37,21 @@ module GoogleHttpActionmailer
35
37
  thread_id: mail['Thread-ID']
36
38
  )
37
39
 
38
- service.send_user_message(user_id, message, message_options)
40
+ before_send = delivery_options[:before_send]
41
+ if before_send && before_send.respond_to?(:call)
42
+ before_send.call(mail, message)
43
+ end
44
+
45
+ message = service.send_user_message(
46
+ user_id,
47
+ message,
48
+ message_options
49
+ )
50
+
51
+ after_send = delivery_options[:after_send]
52
+ if after_send && after_send.respond_to?(:call)
53
+ after_send.call(mail, message)
54
+ end
39
55
  end
40
56
  end
41
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-http-actionmailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kartik Luke Singh
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-19 00:00:00.000000000 Z
11
+ date: 2018-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mail