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
-
#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_subscribable(reference:) ⇒ Hash
Get a Subscribable.
-
#notification(id) ⇒ Hash
Get notification.
-
#notifications(start_at = nil) ⇒ Hash
Get notifications.
-
#send_alert(publication, headers = {}) ⇒ Object
Post notification.
-
#subscribe(subscribable_id:, address:) ⇒ Hash
Subscribe.
-
#topic_matches(attributes) ⇒ Hash
Get topic matches.
-
#unsubscribe(uuid) ⇒ Hash
Unsubscribe #.
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
#create_subscriber_list(attributes) ⇒ Object
Post a subscriber list
49 50 51 |
# File 'lib/gds_api/email_alert_api.rb', line 49 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 |
# 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"] 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 query_string = nested_query_string(params) get_json("#{endpoint}/subscriber-lists?" + query_string) end |
#get_subscribable(reference:) ⇒ Hash
Get a Subscribable
}
126 127 128 129 130 |
# File 'lib/gds_api/email_alert_api.rb', line 126 def get_subscribable(reference:) get_json( "#{endpoint}/subscribables/#{reference}" ) end |
#notification(id) ⇒ Hash
Get notification
76 77 78 |
# File 'lib/gds_api/email_alert_api.rb', line 76 def notification(id) get_json("#{endpoint}/notifications/#{id}") end |
#notifications(start_at = nil) ⇒ Hash
Get notifications
65 66 67 68 69 |
# File 'lib/gds_api/email_alert_api.rb', line 65 def notifications(start_at = nil) url = "#{endpoint}/notifications" url += "?start_at=#{start_at}" if start_at get_json(url) end |
#send_alert(publication, headers = {}) ⇒ Object
Post notification
56 57 58 |
# File 'lib/gds_api/email_alert_api.rb', line 56 def send_alert(publication, headers = {}) post_json("#{endpoint}/notifications", publication, headers) end |
#subscribe(subscribable_id:, address:) ⇒ Hash
Subscribe
103 104 105 106 107 108 109 |
# File 'lib/gds_api/email_alert_api.rb', line 103 def subscribe(subscribable_id:, address:) post_json( "#{endpoint}/subscriptions", subscribable_id: subscribable_id, address: address, ) end |
#topic_matches(attributes) ⇒ Hash
Get topic matches
email_document_supertype, government_document_supertype
86 87 88 89 |
# File 'lib/gds_api/email_alert_api.rb', line 86 def topic_matches(attributes) query_string = nested_query_string(attributes) get_json("#{endpoint}/topic-matches.json?#{query_string}") end |
#unsubscribe(uuid) ⇒ Hash
Unsubscribe #
96 97 98 |
# File 'lib/gds_api/email_alert_api.rb', line 96 def unsubscribe(uuid) post_json("#{endpoint}/unsubscribe/#{uuid}") end |