-
Notifications
You must be signed in to change notification settings - Fork 8
Sending domains endpoints #104
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
base: MT-21830-sandboxes-api
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) | ||
|
|
||
| # 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", ...> | ||
| 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 |
| 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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same question as before: shouldn’t it be upsert?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sometimes its
{endpoint}_apiand sometimes just{endpoint}name of the variable, maybe worth to have single style.