Class: SendGridMailer::Api

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/send_grid_mailer/api.rb

Instance Method Summary collapse

Methods included from Logger

#log_api_error_response, #log_api_success_response, #log_definition

Constructor Details

#initialize(api_key) ⇒ Api

Returns a new instance of Api.



5
6
7
# File 'lib/send_grid_mailer/api.rb', line 5

def initialize(api_key)
  @api_key = api_key || raise(SendGridMailer::InvalidApiKey)
end

Instance Method Details

#get_template(sg_definition) ⇒ Object



14
15
16
17
# File 'lib/send_grid_mailer/api.rb', line 14

def get_template(sg_definition)
  response = sg_api.client.templates._(sg_definition.mail.template_id).get()
  handle_response(response, :template)
end

#send_mail(sg_definition) ⇒ Object



9
10
11
12
# File 'lib/send_grid_mailer/api.rb', line 9

def send_mail(sg_definition)
  response = sg_api.client.mail._('send').post(request_body: sg_definition.to_json)
  handle_response(response, :mail)
end