Class: GdsApi::EmailAlertApi
- Defined in:
- lib/gds_api/email_alert_api.rb
Overview
Adapter for the Email Alert API
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#change_subscriber(id:, new_address:) ⇒ Hash
Patch a Subscriber.
-
#change_subscription(id:, frequency:) ⇒ Hash
Patch a Subscription.
-
#create_auth_token(address:, destination:, redirect: nil) ⇒ Hash
Create an authentication token for a subscriber.
-
#create_subscriber_list(attributes) ⇒ Object
Post a subscriber list.
-
#find_or_create_subscriber_list(attributes) ⇒ Object
Get or Post subscriber list.
-
#find_subscriber_list(attributes) ⇒ Object
Get a subscriber list.
-
#get_latest_matching_subscription(id) ⇒ Hash
Get the latest Subscription that has the same subscriber_list and email as the Subscription associated with the ‘id` passed.
-
#get_subscriber_list(slug:) ⇒ Hash
Get a Subscriber List.
-
#get_subscription(id) ⇒ Hash
Get a Subscription.
-
#get_subscriptions(id:) ⇒ Hash
Get Subscriptions for a Subscriber.
-
#send_alert(publication, headers = {}) ⇒ Object
Post notification.
-
#send_unpublish_message(message) ⇒ Object
Unpublishing alert.
-
#subscribe(subscriber_list_id:, address:, frequency: "immediately") ⇒ Hash
Subscribe.
-
#topic_matches(attributes) ⇒ Hash
Get topic matches.
-
#unsubscribe(uuid) ⇒ nil
Unsubscribe subscriber from subscription.
-
#unsubscribe_subscriber(id) ⇒ nil
Unsubscribe subscriber from everything.
Methods inherited from Base
#client, #create_client, #get_list, #initialize, #url_for_slug
Constructor Details
This class inherits a constructor from GdsApi::Base
Instance Method Details
#change_subscriber(id:, new_address:) ⇒ Hash
Patch a Subscriber
184 185 186 187 188 189 |
# File 'lib/gds_api/email_alert_api.rb', line 184 def change_subscriber(id:, new_address:) patch_json( "#{endpoint}/subscribers/#{id}", new_address: new_address ) end |
#change_subscription(id:, frequency:) ⇒ Hash
Patch a Subscription
197 198 199 200 201 202 |
# File 'lib/gds_api/email_alert_api.rb', line 197 def change_subscription(id:, frequency:) patch_json( "#{endpoint}/subscriptions/#{id}", frequency: frequency ) end |
#create_auth_token(address:, destination:, redirect: nil) ⇒ Hash
Create an authentication token for a subscriber
212 213 214 215 216 217 218 219 |
# File 'lib/gds_api/email_alert_api.rb', line 212 def create_auth_token(address:, destination:, redirect: nil) post_json( "#{endpoint}/subscribers/auth-token", address: address, destination: destination, redirect: redirect, ) end |
#create_subscriber_list(attributes) ⇒ Object
Post a subscriber list
51 52 53 |
# File 'lib/gds_api/email_alert_api.rb', line 51 def create_subscriber_list(attributes) post_json("#{endpoint}/subscriber-lists", attributes) end |
#find_or_create_subscriber_list(attributes) ⇒ Object
Get or Post subscriber list
12 13 14 15 16 |
# File 'lib/gds_api/email_alert_api.rb', line 12 def find_or_create_subscriber_list(attributes) find_subscriber_list(attributes) rescue GdsApi::HTTPNotFound create_subscriber_list(attributes) end |
#find_subscriber_list(attributes) ⇒ Object
Get a subscriber list
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gds_api/email_alert_api.rb', line 21 def find_subscriber_list(attributes) = attributes["tags"] links = attributes["links"] document_type = attributes["document_type"] email_document_supertype = attributes["email_document_supertype"] government_document_supertype = attributes["government_document_supertype"] gov_delivery_id = attributes["gov_delivery_id"] combine_mode = attributes["combine_mode"] if && links = "please provide either tags or links (or neither), but not both" raise ArgumentError, end params = {} params[:tags] = if params[:links] = links if links params[:document_type] = document_type if document_type params[:email_document_supertype] = email_document_supertype if email_document_supertype params[:government_document_supertype] = government_document_supertype if government_document_supertype params[:gov_delivery_id] = gov_delivery_id if gov_delivery_id params[:combine_mode] = combine_mode if combine_mode query_string = nested_query_string(params) get_json("#{endpoint}/subscriber-lists?" + query_string) end |
#get_latest_matching_subscription(id) ⇒ Hash
Get the latest Subscription that has the same subscriber_list and email as the Subscription associated with the ‘id` passed. This may or may not be the same Subscription.
}
165 166 167 |
# File 'lib/gds_api/email_alert_api.rb', line 165 def get_latest_matching_subscription(id) get_json("#{endpoint}/subscriptions/#{id}/latest") end |
#get_subscriber_list(slug:) ⇒ Hash
Get a Subscriber List
}
129 130 131 |
# File 'lib/gds_api/email_alert_api.rb', line 129 def get_subscriber_list(slug:) get_json("#{endpoint}/subscriber-lists/#{slug}") end |
#get_subscription(id) ⇒ Hash
Get a Subscription
}
146 147 148 |
# File 'lib/gds_api/email_alert_api.rb', line 146 def get_subscription(id) get_json("#{endpoint}/subscriptions/#{id}") end |
#get_subscriptions(id:) ⇒ Hash
Get Subscriptions for a Subscriber
174 175 176 |
# File 'lib/gds_api/email_alert_api.rb', line 174 def get_subscriptions(id:) get_json("#{endpoint}/subscribers/#{id}/subscriptions") end |
#send_alert(publication, headers = {}) ⇒ Object
Post notification
58 59 60 |
# File 'lib/gds_api/email_alert_api.rb', line 58 def send_alert(publication, headers = {}) post_json("#{endpoint}/notifications", publication, headers) end |
#send_unpublish_message(message) ⇒ Object
Unpublishing alert
Used by email-alert-service to send a message to email-alert-api when an unpublishing message is put on the Rabbitmq queue by publishing-api
69 70 71 |
# File 'lib/gds_api/email_alert_api.rb', line 69 def () post_json("#{endpoint}/unpublish-messages", ) end |
#subscribe(subscriber_list_id:, address:, frequency: "immediately") ⇒ Hash
Subscribe
105 106 107 108 109 110 111 112 |
# File 'lib/gds_api/email_alert_api.rb', line 105 def subscribe(subscriber_list_id:, address:, frequency: "immediately") post_json( "#{endpoint}/subscriptions", subscriber_list_id: subscriber_list_id, address: address, frequency: frequency, ) end |
#topic_matches(attributes) ⇒ Hash
Get topic matches
email_document_supertype, government_document_supertype
79 80 81 82 |
# File 'lib/gds_api/email_alert_api.rb', line 79 def topic_matches(attributes) query_string = nested_query_string(attributes) get_json("#{endpoint}/topic-matches.json?#{query_string}") end |
#unsubscribe(uuid) ⇒ nil
Unsubscribe subscriber from subscription
89 90 91 |
# File 'lib/gds_api/email_alert_api.rb', line 89 def unsubscribe(uuid) post_json("#{endpoint}/unsubscribe/#{uuid}") end |
#unsubscribe_subscriber(id) ⇒ nil
Unsubscribe subscriber from everything
98 99 100 |
# File 'lib/gds_api/email_alert_api.rb', line 98 def unsubscribe_subscriber(id) delete_json("#{endpoint}/subscribers/#{id}") end |