Skip to content
Open
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions examples/company_info_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'mailtrap'

account_id = 3229
sending_domain_id = 1
client = Mailtrap::Client.new(api_key: 'your-api-key')
company_info_api = Mailtrap::CompanyInfoAPI.new(account_id, client)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sometimes its {endpoint}_api and sometimes just {endpoint} name of the variable, maybe worth to have single style.


# Create company info for a sending domain
company_info_api.create(
sending_domain_id,
name: 'Mailtrap',
address: '123 Main St',
city: 'San Francisco',
country: 'US',
zip_code: '94105',
website_url: 'https://mailtrap.io',
info_level: 'business'
)
# => #<struct Mailtrap::CompanyInfo name="Mailtrap", address="123 Main St", ...>
9 changes: 9 additions & 0 deletions examples/sending_domains_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
sending_domain = sending_domains.get(sending_domain.id)
# => #<struct Mailtrap::SendingDomain id=1, domain_name="example.com">

# Update sending domain configuration
sending_domains.update(
sending_domain.id,
open_tracking_enabled: true,
click_tracking_enabled: true,
auto_unsubscribe_link_enabled: false
)
# => #<struct Mailtrap::SendingDomain id=1, domain_name="example.com", ...>

# Send setup email
sending_domains.send_setup_instructions(sending_domain.id, email: 'jonathan@mail.com')
# => nil
Expand Down
1 change: 1 addition & 0 deletions lib/mailtrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require_relative 'mailtrap/contact_imports_api'
require_relative 'mailtrap/suppressions_api'
require_relative 'mailtrap/sending_domains_api'
require_relative 'mailtrap/company_info_api'
require_relative 'mailtrap/email_logs_api'
require_relative 'mailtrap/projects_api'
require_relative 'mailtrap/inboxes_api'
Expand Down
29 changes: 29 additions & 0 deletions lib/mailtrap/company_info.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

module Mailtrap
# Data Transfer Object for Sending Domain Company Info
# @see https://docs.mailtrap.io/developers/management/sending-domains
# @attr_reader name [String, nil] Company or individual name
# @attr_reader address [String, nil] Street address
# @attr_reader city [String, nil] City
# @attr_reader country [String, nil] Country
# @attr_reader phone [String, nil] Phone number
# @attr_reader zip_code [String, nil] ZIP or postal code
# @attr_reader privacy_policy_url [String, nil] URL to the privacy policy page
# @attr_reader terms_of_service_url [String, nil] URL to the terms of service page
# @attr_reader website_url [String, nil] Company website URL or LinkedIn / personal website
# @attr_reader info_level [String, nil] Whether the sender is a "business" or "individual"
CompanyInfo = Struct.new(
:name,
:address,
:city,
:country,
:phone,
:zip_code,
:privacy_policy_url,
:terms_of_service_url,
:website_url,
:info_level,
keyword_init: true
)
end
78 changes: 78 additions & 0 deletions lib/mailtrap/company_info_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# frozen_string_literal: true

require_relative 'base_api'
require_relative 'company_info'

module Mailtrap
class CompanyInfoAPI
include BaseAPI

self.supported_options = %i[
name
address
city
country
phone
zip_code
privacy_policy_url
terms_of_service_url
website_url
info_level
].freeze

self.response_class = CompanyInfo

# Gets company information for a sending domain
# @param sending_domain_id [Integer] The sending domain ID
# @return [CompanyInfo] Company information
# @!macro api_errors
def get(sending_domain_id)
response = client.get(base_path(sending_domain_id))
build_entity(response[:data], CompanyInfo)
end

# Creates company information for a sending domain
# @param sending_domain_id [Integer] The sending domain ID
# @param [Hash] options The company info attributes
# @option options [String] :name Company or individual name
# @option options [String] :address Street address
# @option options [String] :city City
# @option options [String] :country Country
# @option options [String] :phone Phone number
# @option options [String] :zip_code ZIP or postal code
# @option options [String] :privacy_policy_url URL to the privacy policy page
# @option options [String] :terms_of_service_url URL to the terms of service page
# @option options [String] :website_url Company website URL
# @option options [String] :info_level Whether the sender is a "business" or "individual"
# @return [CompanyInfo] Created company information
# @!macro api_errors
# @raise [ArgumentError] If invalid options are provided
def create(sending_domain_id, options)
validate_options!(options, supported_options)
response = client.post(base_path(sending_domain_id), wrap_request(options))
build_entity(response[:data], CompanyInfo)
end

# Updates company information for a sending domain
# @param sending_domain_id [Integer] The sending domain ID
# @param [Hash] options The company info attributes to update
# @return [CompanyInfo] Updated company information
# @!macro api_errors
# @raise [ArgumentError] If invalid options are provided
def update(sending_domain_id, options)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question as before: shouldn’t it be upsert?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we split the endpoint though

validate_options!(options, supported_options)
response = client.patch(base_path(sending_domain_id), wrap_request(options))
build_entity(response[:data], CompanyInfo)
end

private

def base_path(sending_domain_id)
"/api/accounts/#{account_id}/sending_domains/#{sending_domain_id}/company_info"
end

def wrap_request(options)
{ company_info: options }
end
end
end
17 changes: 15 additions & 2 deletions lib/mailtrap/sending_domains_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Mailtrap
class SendingDomainsAPI
include BaseAPI

self.supported_options = %i[domain_name]
self.supported_options = %i[open_tracking_enabled click_tracking_enabled auto_unsubscribe_link_enabled]

self.response_class = SendingDomain

Expand All @@ -34,7 +34,7 @@ def get(domain_id)
# @!macro api_errors
# @raise [ArgumentError] If invalid options are provided
def create(options)
base_create(options)
base_create(options, %i[domain_name])
end

# Deletes a sending domain
Expand All @@ -45,6 +45,19 @@ def delete(domain_id)
base_delete(domain_id)
end

# Updates configuration settings for a sending domain
# @param domain_id [Integer] The sending domain ID
# @param [Hash] options The parameters to update
# @option options [Boolean] :open_tracking_enabled Enable open tracking for emails sent from this domain
# @option options [Boolean] :click_tracking_enabled Enable click tracking for links in emails sent from this domain
# @option options [Boolean] :auto_unsubscribe_link_enabled Automatically add an unsubscribe link to emails
# @return [SendingDomain] Updated sending domain
# @!macro api_errors
# @raise [ArgumentError] If invalid options are provided
def update(domain_id, options)
base_update(domain_id, options)
end

# Email DNS configuration instructions for the sending domain
# @param domain_id [Integer] The sending domain ID
# @param email [String] The email for instructions
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading