Class: Boppers::Notifier::Sendgrid

Inherits:
Object
  • Object
show all
Defined in:
lib/boppers/notifier/sendgrid.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username:, password:, domain:, email:, subscribe: nil) ⇒ Sendgrid

Returns a new instance of Sendgrid.



8
9
10
11
12
13
14
15
16
# File 'lib/boppers/notifier/sendgrid.rb', line 8

def initialize(username:, password:, domain:, email:, subscribe: nil)
  require "mail"

  @username = username
  @password = password
  @domain = domain
  @email = email
  @subscribe = subscribe
end

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



6
7
8
# File 'lib/boppers/notifier/sendgrid.rb', line 6

def domain
  @domain
end

#emailObject (readonly)

Returns the value of attribute email.



6
7
8
# File 'lib/boppers/notifier/sendgrid.rb', line 6

def email
  @email
end

#passwordObject (readonly)

Returns the value of attribute password.



6
7
8
# File 'lib/boppers/notifier/sendgrid.rb', line 6

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



6
7
8
# File 'lib/boppers/notifier/sendgrid.rb', line 6

def username
  @username
end

Instance Method Details

#call(title, message, _options) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/boppers/notifier/sendgrid.rb', line 18

def call(title, message, _options)
  mail = Mail.new
  mail.delivery_method :smtp,
                       address: "smtp.sendgrid.net",
                       port: 587,
                       user_name: username,
                       password: password,
                       domain: domain,
                       authentication: :plain,
                       enable_starttls_auto: true

  mail.subject(title)
  mail.to(email)
  mail.from("Boppers <noreply@boppers>")
  mail.part("text/plain") do |part|
    part.body = message
  end

  mail.deliver
end