Class: Auth0::Emails::Provider::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/auth0/emails/provider/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



10
11
12
# File 'lib/auth0/emails/provider/client.rb', line 10

def initialize(client:)
  @client = client
end

Instance Method Details

#create(request_options: {}, **params) ⇒ Auth0::Types::CreateEmailProviderResponseContent

Create an email provider. The credentials object requires different properties depending on the email provider (which is specified using the name property):

  • mandrill requires api_key
  • sendgrid requires api_key
  • sparkpost requires api_key. Optionally, set region to eu to use the SparkPost service hosted in Western Europe; set to null to use the SparkPost service hosted in North America. eu or null are the only valid values for region.
  • mailgun requires api_key and domain. Optionally, set region to eu to use the Mailgun service hosted in Europe; set to null otherwise. eu or null are the only valid values for region.
  • ses requires accessKeyId, secretAccessKey, and region
  • smtp requires smtp_host, smtp_port, smtp_user, and smtp_pass

Depending on the type of provider it is possible to specify settings object with different configuration options, which will be used when sending an email:

  • smtp provider, settings may contain headers object.
    • When using AWS SES SMTP host, you may provide a name of configuration set in X-SES-Configuration-Set header. Value must be a string.
    • When using Sparkpost host, you may provide value for X-MSYS_API header. Value must be an object.
  • For ses provider, settings may contain message object, where you can provide a name of configuration set in configuration_set_name property. Value must be a string.

Examples:

client.emails.provider.create(
  name: "mailgun",
  credentials: {
    api_key: "api_key"
  }
)

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/auth0/emails/provider/client.rb', line 105

def create(request_options: {}, **params)
  params = Auth0::Internal::Types::Utils.normalize_keys(params)
  request = Auth0::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "emails/provider",
    body: Auth0::Emails::Provider::Types::CreateEmailProviderRequestContent.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Auth0::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    (response.body.to_s.empty? ? nil : Auth0::Types::CreateEmailProviderResponseContent.load(response.body))
  else
    error_class = Auth0::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#delete(request_options: {}, **_params) ⇒ untyped

Delete the email provider.

Examples:

client.emails.provider.delete

Parameters:

  • request_options (Hash) (defaults to: {})
  • _params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:

  • (untyped)

Raises:

  • (error_class)


142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/auth0/emails/provider/client.rb', line 142

def delete(request_options: {}, **_params)
  request = Auth0::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "DELETE",
    path: "emails/provider",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Auth0::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

  error_class = Auth0::Errors::ResponseError.subclass_for_code(code)
  raise error_class.new(response.body, code: code)
end

#get(request_options: {}, **params) ⇒ Auth0::Types::GetEmailProviderResponseContent

Retrieve details of the email provider configuration in your tenant. A list of fields to include or exclude may also be specified.

Examples:

client.emails.provider.get(
  fields: "fields",
  include_fields: true
)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :fields (String, nil)
  • :include_fields (Boolean, nil)

Returns:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/auth0/emails/provider/client.rb', line 35

def get(request_options: {}, **params)
  params = Auth0::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["fields"] = params[:fields] if params.key?(:fields)
  query_params["include_fields"] = params[:include_fields] if params.key?(:include_fields)

  request = Auth0::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "emails/provider",
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Auth0::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    (response.body.to_s.empty? ? nil : Auth0::Types::GetEmailProviderResponseContent.load(response.body))
  else
    error_class = Auth0::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#update(request_options: {}, **params) ⇒ Auth0::Types::UpdateEmailProviderResponseContent

Update an email provider. The credentials object requires different properties depending on the email provider (which is specified using the name property):

  • mandrill requires api_key
  • sendgrid requires api_key
  • sparkpost requires api_key. Optionally, set region to eu to use the SparkPost service hosted in Western Europe; set to null to use the SparkPost service hosted in North America. eu or null are the only valid values for region.
  • mailgun requires api_key and domain. Optionally, set region to eu to use the Mailgun service hosted in Europe; set to null otherwise. eu or null are the only valid values for region.
  • ses requires accessKeyId, secretAccessKey, and region
  • smtp requires smtp_host, smtp_port, smtp_user, and smtp_pass

Depending on the type of provider it is possible to specify settings object with different configuration options, which will be used when sending an email:

  • smtp provider, settings may contain headers object.

    • When using AWS SES SMTP host, you may provide a name of configuration set in X-SES-Configuration-Set header. Value must be a string.
    • When using Sparkpost host, you may provide value for X-MSYS_API header. Value must be an object.

    For ses provider, settings may contain message object, where you can provide a name of configuration set in configuration_set_name property. Value must be a string.

Examples:

client.emails.provider.update

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/auth0/emails/provider/client.rb', line 200

def update(request_options: {}, **params)
  params = Auth0::Internal::Types::Utils.normalize_keys(params)
  request = Auth0::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "PATCH",
    path: "emails/provider",
    body: Auth0::Emails::Provider::Types::UpdateEmailProviderRequestContent.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Auth0::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    (response.body.to_s.empty? ? nil : Auth0::Types::UpdateEmailProviderResponseContent.load(response.body))
  else
    error_class = Auth0::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end