-
Notifications
You must be signed in to change notification settings - Fork 1
Add tracking opt-outs and create suppression #14
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
11787b4
Align suppressions list with what the API returns and accepts
mklocek 21517c5
Add create suppression and tracking opt-out commands
mklocek 1b04b0e
Document suppressions and tracking opt-outs in the CLI skill
mklocek a22c9ca
Document the email-logs list filters in the CLI skill
mklocek 114d5da
Document domains update and company-info in the CLI skill
mklocek 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
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,78 @@ | ||
| package suppressions | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/mailtrap/mailtrap-cli/internal/client" | ||
| "github.com/mailtrap/mailtrap-cli/internal/cmdutil" | ||
| "github.com/mailtrap/mailtrap-cli/internal/config" | ||
| "github.com/mailtrap/mailtrap-cli/internal/output" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| type suppressionResponse struct { | ||
| Data Suppression `json:"data"` | ||
| } | ||
|
|
||
| func NewCmdCreate(f *cmdutil.Factory) *cobra.Command { | ||
| var ( | ||
| email string | ||
| domainID int64 | ||
| sendingStream string | ||
| suppressType string | ||
| ) | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "create", | ||
| Short: "Add an email address to the suppression list", | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| if err := cmdutil.RequireFlag("email", email); err != nil { | ||
| return err | ||
| } | ||
| if !cmd.Flags().Changed("domain-id") { | ||
| return fmt.Errorf("--domain-id is required") | ||
| } | ||
| if domainID <= 0 { | ||
| return fmt.Errorf("--domain-id must be greater than 0") | ||
| } | ||
| if err := cmdutil.RequireFlag("sending-stream", sendingStream); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| c, err := f.NewClient() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| _, err = config.RequireAccountID() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| body := map[string]interface{}{ | ||
| "email": email, | ||
| "domain_id": domainID, | ||
| "sending_stream": sendingStream, | ||
| } | ||
| if cmd.Flags().Changed("type") { | ||
| body["type"] = suppressType | ||
| } | ||
|
|
||
| var resp suppressionResponse | ||
| if err := c.Post(context.Background(), client.BaseGeneral, cmdutil.AccountPath("suppressions"), body, &resp); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| format := cmdutil.GetOutputFormat() | ||
| return output.Print(f.IOStreams.Out, format, resp.Data, suppressionColumns) | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().StringVar(&email, "email", "", "Email address to suppress (required)") | ||
| cmd.Flags().Int64Var(&domainID, "domain-id", 0, "ID of the sending domain the suppression applies to (required)") | ||
| cmd.Flags().StringVar(&sendingStream, "sending-stream", "", "Sending stream to suppress for: transactional, bulk (required)") | ||
| cmd.Flags().StringVar(&suppressType, "type", "", "Suppression reason: hard bounce, spam complaint, unsubscription, manual import") | ||
|
|
||
| return cmd | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.