Class: SendgridTemplate::Configuration

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

Constant Summary collapse

API_URL =
'https://api.sendgrid.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Configuration

Returns a new instance of Configuration.



8
9
10
# File 'lib/sendgrid_template/configuration.rb', line 8

def initialize(options = {})
  @api_key = options[:api_key]
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



6
7
8
# File 'lib/sendgrid_template/configuration.rb', line 6

def api_key
  @api_key
end

Instance Method Details

#connectObject



12
13
14
15
16
17
18
19
20
# File 'lib/sendgrid_template/configuration.rb', line 12

def connect
  @conn ||= Faraday.new(url: API_URL) do |h|
    h.headers[:content_type] = 'application/json'
    h.headers['Authorization'] = "Bearer #{@api_key}"
    h.adapter(Faraday.default_adapter)
  end

  @conn
end