Sha256: c8aec0d8c90f1705ba12bb648d1ec219c9274c7b48fac2f54af1a3dc8b0407a7
Contents?: true
Size: 838 Bytes
Versions: 1
Compression:
Stored size: 838 Bytes
Contents
require 'rest-client' module SendgridContactPersist class << self attr_accessor :logger def persist(emails, custom_attrs = {}) return nil unless api_key = ENV['SENDGRID_API_KEY'] headers = {'Authorization' => "Bearer #{api_key}"} emails = [emails] unless emails.kind_of?(Array) data = [] emails.each do |email| data << {email: email}.merge(custom_attrs) end resp = RestClient.post 'https://api.sendgrid.com/v3/contactdb/recipients', data.to_json, headers SendgridContactPersist.logger.info "Contact(s) added to Sendgrid: #{emails}" resp end end class Railties < ::Rails::Railtie initializer 'Rails logger' do SendgridContactPersist.logger = Rails.logger end end if defined?(Rails) require 'sendgrid_contact_persist/engine' end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sendgrid_contact_persist-0.0.1 | lib/sendgrid_contact_persist.rb |