@@ -2,20 +2,49 @@ defmodule SparkPost.SuppressionList do
22 @ moduledoc """
33 The SparkPost Suppression List API for working with suppression lists.
44 Use `SparkPost.SuppressionList.delete/1` to delete a single entry from a list,
5- `SparkPost.SuppressionList.search/1` to search through your account's suppression list.
5+ `SparkPost.SuppressionList.update_one/3` to insert or update a single list entry,
6+ or `SparkPost.SuppressionList.search/1` to search through your account's suppression list.
67
78 Check out the documentation for each function
89 or use the [SparkPost API reference](https://developers.sparkpost.com/api/suppression_list.html) for details.
910
1011 Returned by `SparkPost.SuppressionList.delete/1`:
1112 - nothing (empty body)
1213
14+ Returned by `SparkPost.SuppressionList.update_one/3`:
15+ - message (A success message string)
16+
1317 Returned by `SparkPost.SuppressionList.search/1`.
1418 - %SparkPost.SuppressionList.SearchResult{}
1519 """
1620
1721 alias SparkPost.Endpoint
1822
23+ @ doc """
24+ Insert or update a single entry in the suppression list.
25+ Returns a single string with the success message if the entry
26+ was updated or inserted. Returns a %SparkPost.Endpoint.Error{} with a 400
27+ if the type is invalid.
28+
29+ Parameters:
30+ - recipient: the email to insert or update in the suppression list
31+ - type: one of "transactional" or "non_transactional"
32+ - description (optional): optional description of this entry in the suppression list
33+ """
34+ def update_one ( recipient , type , description \\ nil ) do
35+ body = if description == nil do
36+ % { type: type }
37+ else
38+ % { type: type , description: description }
39+ end
40+ response = Endpoint . request ( :put , "suppression-list/#{ recipient } " , body )
41+ case response do
42+ % SparkPost.Endpoint.Response { status_code: 200 , results: results } ->
43+ Map . get ( results , :message , "" )
44+ _ -> response
45+ end
46+ end
47+
1948 @ doc """
2049 Deletes a specific entry from the list. Returns an empty string if
2150 the deletion was successful. Returns a %SparkPost.Endpoint.Error{} with a 404
0 commit comments