-
Couldn't load subscription status.
- Fork 14
Suppression list Insert and Delete #40
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
Changes from all commits
1689a98
fc0c4cc
9035124
d8efa11
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 |
|---|---|---|
| @@ -1,17 +1,68 @@ | ||
| defmodule SparkPost.SuppressionList do | ||
| @moduledoc """ | ||
| The SparkPost Suppression List API for working with suppression lists. | ||
| Use `SparkPost.SuppressionList.search/1` to search through your account's suppression list. | ||
| Use `SparkPost.SuppressionList.delete/1` to delete a single entry from a list, | ||
| `SparkPost.SuppressionList.upsert_one/3` to insert or update a single list entry, | ||
| or `SparkPost.SuppressionList.search/1` to search through your account's suppression list. | ||
|
|
||
| Check out the documentation for each function | ||
| or use the [SparkPost API reference](https://developers.sparkpost.com/api/suppression_list.html) for details. | ||
|
|
||
| Returned by `SparkPost.SuppressionList.delete/1`: | ||
| - {:ok, ""} | ||
|
|
||
| Returned by `SparkPost.SuppressionList.upsert_one/3`: | ||
| - {:ok, message} (A success message string) | ||
|
|
||
| Returned by `SparkPost.SuppressionList.search/1`. | ||
| - %SparkPost.SuppressionList.SearchResult{} | ||
| """ | ||
|
|
||
| alias SparkPost.Endpoint | ||
|
|
||
| @doc """ | ||
| Insert or update a single entry in the suppression list. | ||
| Returns a single string with the success message if the entry | ||
| was updated or inserted. Returns a %SparkPost.Endpoint.Error{} with a 400 | ||
| if there was an issue with the request format. | ||
|
|
||
| Parameters: | ||
| - recipient: the email to insert or update in the suppression list | ||
| - type: one of "transactional" or "non_transactional" | ||
| - description (optional): optional description of this entry in the suppression list | ||
| """ | ||
| def upsert_one(recipient, type, description \\ nil) do | ||
| body = if description == nil do | ||
| %{type: type} | ||
| else | ||
| %{type: type, description: description} | ||
| end | ||
| response = Endpoint.request(:put, "suppression-list/#{recipient}", body) | ||
|
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 wonder if we should adopt the usual 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'd like to adopt this. Unfortunately I'm not sure I have enough time to go through and update the library everywhere to make sure everything still works. Might make sense to have this in a different PR? 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. Yup. I wasn't suggesting you retrofit the whole library with this. These are the first endpoints with simple good/bad responses though so I thought we'd start here. |
||
| case response do | ||
| %SparkPost.Endpoint.Response{status_code: 200, results: results} -> | ||
| {:ok, Map.get(results, :message, "")} | ||
| _ -> {:error, response} | ||
| end | ||
| end | ||
|
|
||
| @doc """ | ||
| Deletes a specific entry from the list. Returns an empty string if | ||
| the deletion was successful. Returns a %SparkPost.Endpoint.Error{} with a 404 | ||
| if the specified entry is not in the list. Returns a %SparkPost.Endpoint.Error{} | ||
| with a 403 if the entry could not be removed for any reason (such as Compliance). | ||
|
|
||
| Parameters: | ||
| recipient: the entry to delete from the suppression list. | ||
| """ | ||
| def delete(recipient) do | ||
|
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. The same comment about idiomatic |
||
| response = Endpoint.request(:delete, "suppression-list/#{recipient}", %{}, %{}, [], false) | ||
| case response do | ||
| %SparkPost.Endpoint.Response{status_code: 204} -> | ||
| {:ok, ""} | ||
| _ -> {:error, response} | ||
| end | ||
| end | ||
|
|
||
| @doc """ | ||
| Execute a search of the suppression list based on the provided | ||
| parameters. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "errors": [ | ||
| { | ||
| "message": "Recipient could not be found" | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "results": { | ||
| "message": "Test response message" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "errors": [ | ||
| { | ||
| "message": "Type must be one of: 'transactional', 'non_transactional'" | ||
| } | ||
| ] | ||
| } |
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.
👍
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.
Will have to check which other modules either make assumptions about the status code or pass it on to client code. This could produce a (good) breaking change in those cases.
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.
didn't see anything on a cursory glance. Let me know if I missed anything though.