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.



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

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] || {}
  @delivery_options = params[:delivery_options] || {}
end

Instance Attribute Details

#delivery_optionsObject (readonly)

Returns the value of attribute delivery_options.



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

def delivery_options
  @delivery_options
end

#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



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/google_http_actionmailer.rb', line 33

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']
  )

  before_send = delivery_options[:before_send]
  if before_send && before_send.respond_to?(:call)
    before_send.call(mail, message)
  end

  message = service.send_user_message(
    user_id,
    message,
    message_options
  )

  after_send = delivery_options[:after_send]
  if after_send && after_send.respond_to?(:call)
    after_send.call(mail, message)
  end
end