Sha256: e63849e0f88883c8fe76402e1ab3dd8dac2ce57fd750b8695e50d8a870f58bd6

Contents?: true

Size: 1.2 KB

Versions: 11

Compression:

Stored size: 1.2 KB

Contents

# Quickly and easily access the SendGrid API.
require 'ruby_http_client'
require_relative 'version'

module SendGrid
  # Initialize the HTTP client
  class API
    attr_accessor :client
    attr_reader :request_headers, :host, :version
    # * *Args*    :
    #   - +api_key+ -> your SendGrid API key
    #   - +host+ -> the base URL for the API
    #   - +request_headers+ -> any headers that you want to be globally applied
    #   - +version+ -> the version of the API you wish to access,
    #                  currently only "v3" is supported
    #
    def initialize(api_key: nil, host: nil, request_headers: nil, version: nil)
      @api_key          = api_key
      @host             = host ? host : 'https://api.sendgrid.com'
      @version          = version ? version : 'v3'
      @user_agent       = "sendgrid/#{SendGrid::VERSION};ruby"
      @request_headers  = JSON.parse('
        {
          "Authorization": "Bearer ' + @api_key + '",
          "Accept": "application/json"
        }
      ')

      @request_headers = @request_headers.merge(request_headers) if request_headers
      @client = Client.new(host: "#{@host}/#{@version}",
                           request_headers: @request_headers)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
sendgrid-ruby-4.0.7 lib/sendgrid/client.rb
sendgrid-ruby-4.0.6 lib/sendgrid/client.rb
sendgrid-ruby-4.0.5 lib/sendgrid/client.rb
sendgrid-ruby-4.0.4 lib/sendgrid/client.rb
sendgrid-ruby-4.0.3 lib/sendgrid/client.rb
sendgrid-ruby-4.0.2 lib/sendgrid/client.rb
sendgrid-ruby-4.0.1 lib/sendgrid/client.rb
sendgrid-ruby-4.0.0 lib/sendgrid/client.rb
sendgrid-ruby-3.0.7 lib/sendgrid/client.rb
sendgrid-ruby-3.0.6 lib/sendgrid/client.rb
sendgrid-ruby-3.0.5 lib/sendgrid/client.rb