Skip to content

Nest BaseInterface under sendgrid namespace #487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 34 additions & 32 deletions lib/sendgrid/base_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,41 @@
require_relative 'version'

# Initialize the HTTP client
class BaseInterface
attr_accessor :client
attr_reader :request_headers, :host, :version, :impersonate_subuser, :http_options
module SendGrid
class BaseInterface
attr_accessor :client
attr_reader :request_headers, :host, :version, :impersonate_subuser, :http_options

# * *Args* :
# - +auth+ -> authorization header value
# - +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
# - +impersonate_subuser+ -> the subuser to impersonate, will be passed
# in the "On-Behalf-Of" header
# - +http_options+ -> http options that you want to be globally applied to each request
#
def initialize(auth:, host:, request_headers: nil, version: nil, impersonate_subuser: nil, http_options: {})
@auth = auth
@host = host
@version = version || 'v3'
@impersonate_subuser = impersonate_subuser
@user_agent = "sendgrid/#{SendGrid::VERSION};ruby"
@request_headers = JSON.parse('
{
"Authorization": "' + @auth + '",
"Accept": "application/json",
"User-Agent": "' + @user_agent + '"
}
')
@request_headers['On-Behalf-Of'] = @impersonate_subuser if @impersonate_subuser
# * *Args* :
# - +auth+ -> authorization header value
# - +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
# - +impersonate_subuser+ -> the subuser to impersonate, will be passed
# in the "On-Behalf-Of" header
# - +http_options+ -> http options that you want to be globally applied to each request
#
def initialize(auth:, host:, request_headers: nil, version: nil, impersonate_subuser: nil, http_options: {})
@auth = auth
@host = host
@version = version || 'v3'
@impersonate_subuser = impersonate_subuser
@user_agent = "sendgrid/#{SendGrid::VERSION};ruby"
@request_headers = JSON.parse('
{
"Authorization": "' + @auth + '",
"Accept": "application/json",
"User-Agent": "' + @user_agent + '"
}
')
@request_headers['On-Behalf-Of'] = @impersonate_subuser if @impersonate_subuser

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