Class: GoogleHttpActionmailer::DeliveryMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/google_http_actionmailer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ DeliveryMethod

Returns a new instance of DeliveryMethod.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/google_http_actionmailer.rb', line 13

def initialize(params)
  @service = Google::Apis::GmailV1::GmailService.new

  @service.authorization = params[:authorization]
  @service.request_options.merge params[:request_options]

  unless params[:client_options].nil?
    @service.client_options.members.each do |opt|
      opt = opt.to_sym
      unless params[:client_options][opt].nil?
        @service.client_options[opt] = params[:client_options][opt]
      end
    end
  end

  @message_options = params[:message_options] || {}
end

Instance Attribute Details

#message_optionsObject (readonly)

Returns the value of attribute message_options.



11
12
13
# File 'lib/google_http_actionmailer.rb', line 11

def message_options
  @message_options
end

#serviceObject (readonly)

Returns the value of attribute service.



10
11
12
# File 'lib/google_http_actionmailer.rb', line 10

def service
  @service
end

Instance Method Details

#deliver!(mail) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/google_http_actionmailer.rb', line 31

def deliver!(mail)
  user_id = message_options[:user_id] || 'me'
  message = Google::Apis::GmailV1::Message.new(
    raw:       mail.to_s,
    thread_id: mail['Thread-ID']
  )

  service.send_user_message(user_id, message, message_options)
end