-
Notifications
You must be signed in to change notification settings - Fork 8
Add contact enpoints #105
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
Merged
Merged
Add contact enpoints #105
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| require 'mailtrap' | ||
|
|
||
| account_id = 3229 | ||
| client = Mailtrap::Client.new(api_key: 'your-api-key') | ||
| contact_events = Mailtrap::ContactEventsAPI.new(account_id, client) | ||
|
|
||
| # Submit a custom event for a contact (identifier can be UUID or email) | ||
| contact_events.create( | ||
| 'john.smith@example.com', | ||
| name: 'UserLogin', | ||
| params: { | ||
| user_id: 101, | ||
| user_name: 'John Smith', | ||
| is_active: true, | ||
| last_seen: nil | ||
| } | ||
| ) | ||
| # => #<struct Mailtrap::ContactEvent contact_id="018dd5e3-f6d2-7c00-8f9b-e5c3f2d8a132", | ||
| # contact_email="john.smith@example.com", | ||
| # name="UserLogin", | ||
| # params={"user_id"=>101, ...}> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| require 'mailtrap' | ||
|
|
||
| account_id = 3229 | ||
| client = Mailtrap::Client.new(api_key: 'your-api-key') | ||
| contact_exports = Mailtrap::ContactExportsAPI.new(account_id, client) | ||
|
|
||
| # Create a contact export filtered by list IDs | ||
| contact_exports.create( | ||
| filters: [ | ||
| { name: 'list_id', operator: 'equal', value: [1, 2] } | ||
| ] | ||
| ) | ||
| # => #<struct Mailtrap::ContactExport id=1, status="started", created_at="...", updated_at="...", url=nil> | ||
|
|
||
| # Create a contact export filtered by subscription status | ||
| contact_exports.create( | ||
| filters: [ | ||
| { name: 'subscription_status', operator: 'equal', value: 'subscribed' } | ||
| ] | ||
| ) | ||
| # => #<struct Mailtrap::ContactExport id=2, status="started", ..., url=nil> | ||
|
|
||
| # Get a contact export by ID — once status is "finished", `url` is the file location | ||
| contact_exports.get(1) | ||
| # => #<struct Mailtrap::ContactExport id=1, status="finished", ..., url="https://..."> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Mailtrap | ||
| # Data Transfer Object for Contact Event | ||
| # @attr_reader contact_id [String] The contact ID (UUID) | ||
| # @attr_reader contact_email [String] The contact email | ||
| # @attr_reader name [String] The event name | ||
| # @attr_reader params [Hash] The event parameters (string keys, scalar values) | ||
| ContactEvent = Struct.new( | ||
| :contact_id, | ||
| :contact_email, | ||
| :name, | ||
| :params, | ||
| keyword_init: true | ||
| ) | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative 'base_api' | ||
| require_relative 'contact_event' | ||
|
|
||
| module Mailtrap | ||
| class ContactEventsAPI | ||
| include BaseAPI | ||
|
|
||
| self.supported_options = %i[name params].freeze | ||
|
|
||
| self.response_class = ContactEvent | ||
|
|
||
| # Creates a contact event | ||
| # @param contact_identifier [String] The contact UUID or email address | ||
| # @param [Hash] options The event parameters | ||
| # @option options [String] :name The event name (max 255 characters) | ||
| # @option options [Hash] :params A hash of string keys and scalar values | ||
| # @return [ContactEvent] Created contact event object | ||
| # @!macro api_errors | ||
| # @raise [ArgumentError] If invalid options are provided | ||
| def create(contact_identifier, options) | ||
| validate_options!(options, supported_options) | ||
| response = client.post(base_path(contact_identifier), options) | ||
| build_entity(response, ContactEvent) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def base_path(contact_identifier) | ||
| "/api/accounts/#{account_id}/contacts/#{contact_identifier}/events" | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Mailtrap | ||
| # Data Transfer Object for Contact Export | ||
| # @attr_reader id [Integer] The contact export ID | ||
| # @attr_reader status [String] The export status (created, started, finished) | ||
| # @attr_reader created_at [String] When the export was created | ||
| # @attr_reader updated_at [String] When the export was last updated | ||
| # @attr_reader url [String, nil] URL of the exported file (only when status is "finished") | ||
| ContactExport = Struct.new( | ||
| :id, | ||
| :status, | ||
| :created_at, | ||
| :updated_at, | ||
| :url, | ||
| keyword_init: true | ||
| ) | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative 'base_api' | ||
| require_relative 'contact_export' | ||
|
|
||
| module Mailtrap | ||
| class ContactExportsAPI | ||
| include BaseAPI | ||
|
|
||
| self.supported_options = %i[filters].freeze | ||
|
|
||
| self.response_class = ContactExport | ||
|
|
||
| # Retrieves a specific contact export | ||
| # @param export_id [Integer] The contact export ID | ||
| # @return [ContactExport] Contact export object | ||
| # @!macro api_errors | ||
| def get(export_id) | ||
| base_get(export_id) | ||
| end | ||
|
|
||
| # Creates a new contact export | ||
| # @param [Hash] options The export parameters | ||
| # @option options [Array<Hash>] :filters Filters to apply to the export | ||
| # - `{ name: 'list_id', operator: 'equal', value: [Integer, ...] }` | ||
| # - `{ name: 'subscription_status', operator: 'equal', value: 'subscribed' | 'unsubscribed' }` | ||
| # @return [ContactExport] Created contact export object | ||
| # @!macro api_errors | ||
| # @raise [ArgumentError] If invalid options are provided | ||
| def create(options) | ||
| base_create(options) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def base_path | ||
| "/api/accounts/#{account_id}/contacts/exports" | ||
| end | ||
| end | ||
| end |
73 changes: 73 additions & 0 deletions
73
...cassettes/Mailtrap_ContactEventsAPI/_create/maps_response_data_to_ContactEvent_object.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
71 changes: 71 additions & 0 deletions
71
.../Mailtrap_ContactEventsAPI/_create/when_contact_does_not_exist/raises_not_found_error.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
71 changes: 71 additions & 0 deletions
71
...settes/Mailtrap_ContactEventsAPI/_create/when_name_is_missing/raises_a_Mailtrap_Error.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
base_createis not enough here?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.
different base_path