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
-
#find_or_create_subscriber_list(attributes) ⇒ Object
Get or Post subscriber list.
-
#notification(id) ⇒ Hash
Get notification.
-
#notifications(start_at = nil) ⇒ Hash
Get notifications.
-
#send_alert(publication, headers = {}) ⇒ Object
Post notification.
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
#find_or_create_subscriber_list(attributes) ⇒ Object
Get or Post subscriber list
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gds_api/email_alert_api.rb', line 12 def find_or_create_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 search_subscriber_list(params) rescue GdsApi::HTTPNotFound create_subscriber_list(attributes) end |
#notification(id) ⇒ Hash
Get notification
61 62 63 |
# File 'lib/gds_api/email_alert_api.rb', line 61 def notification(id) get_json("#{endpoint}/notifications/#{id}") end |
#notifications(start_at = nil) ⇒ Hash
Get notifications
50 51 52 53 54 |
# File 'lib/gds_api/email_alert_api.rb', line 50 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
41 42 43 |
# File 'lib/gds_api/email_alert_api.rb', line 41 def send_alert(publication, headers = {}) post_json("#{endpoint}/notifications", publication, headers) end |