Class: Anypost::Resources::Suppressions
- Defined in:
- lib/anypost/resources/suppressions.rb
Overview
Operations on the ‘/suppressions` endpoints. Entries key on `(email, topic)`.
Instance Method Summary collapse
-
#create(params) ⇒ Object
Add a manual suppression.
-
#delete(email, topic) ⇒ Object
Remove the single ‘(email, topic)` row.
-
#delete_for_email(email) ⇒ Object
Remove an address from the suppression list across every topic.
-
#get(email, topic) ⇒ Object
Retrieve the suppression for an ‘(email, topic)` pair.
-
#list(params = {}) ⇒ Object
List the team’s suppressions, newest-first.
-
#list_for_email(email) ⇒ Array<Response>
List every suppression on file for an address, across all topics.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Anypost::Resources::Base
Instance Method Details
#create(params) ⇒ Object
Add a manual suppression. Defaults to topic ‘*` (every topic). Raises validation_error if an active entry for the same `(email, topic)` exists.
22 23 24 |
# File 'lib/anypost/resources/suppressions.rb', line 22 def create(params) request_object(:post, "/suppressions", body: params) end |
#delete(email, topic) ⇒ Object
Remove the single ‘(email, topic)` row. Other topics are untouched.
33 34 35 36 |
# File 'lib/anypost/resources/suppressions.rb', line 33 def delete(email, topic) @http.request(:delete, "/suppressions/#{encode(email)}/#{encode(topic)}") nil end |
#delete_for_email(email) ⇒ Object
Remove an address from the suppression list across every topic.
49 50 51 52 |
# File 'lib/anypost/resources/suppressions.rb', line 49 def delete_for_email(email) @http.request(:delete, "/suppressions/#{encode(email)}") nil end |
#get(email, topic) ⇒ Object
Retrieve the suppression for an ‘(email, topic)` pair. Use `*` as the topic for the global row. Raises not_found if the pair isn’t suppressed.
28 29 30 |
# File 'lib/anypost/resources/suppressions.rb', line 28 def get(email, topic) request_object(:get, "/suppressions/#{encode(email)}/#{encode(topic)}") end |
#list(params = {}) ⇒ Object
List the team’s suppressions, newest-first. Expired rows are filtered out. Filter with ‘email_contains`, `topic`, `reason`, and `origin`.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/anypost/resources/suppressions.rb', line 9 def list(params = {}) paginate("/suppressions", { limit: params[:limit], after: params[:after], email_contains: params[:email_contains], topic: params[:topic], reason: params[:reason], origin: params[:origin] }) end |
#list_for_email(email) ⇒ Array<Response>
List every suppression on file for an address, across all topics. Raises not_found if the address has no active suppressions.
42 43 44 45 46 |
# File 'lib/anypost/resources/suppressions.rb', line 42 def list_for_email(email) decoded = @http.request(:get, "/suppressions/#{encode(email)}") data = decoded.is_a?(Hash) ? decoded["data"] : nil Array(data).map { |row| Response.wrap(row) } end |