class GdsApi::EmailAlertApi

@api documented
@see github.com/alphagov/email-alert-api<br><br>Adapter for the Email Alert API

def change_subscriber(address:, new_address:)

Returns:
  • (Hash) - subscriber

Parameters:
  • string () -- Subscriber new_address
  • string () -- Subscriber address
def change_subscriber(address:, new_address:)
  patch_json(
    "#{endpoint}/subscribers/#{address}",
    new_address: new_address
  )
end

def change_subscription(id:, frequency:)

Returns:
  • (Hash) - subscription

Parameters:
  • string () -- Subscription frequency
  • string () -- Subscription id
def change_subscription(id:, frequency:)
  patch_json(
    "#{endpoint}/subscriptions/#{id}",
    frequency: frequency
  )
end

def create_subscriber_list(attributes)

Parameters:
  • attributes (Hash) -- document_type, links, tags used to search existing subscriber lists
def create_subscriber_list(attributes)
  post_json("#{endpoint}/subscriber-lists", attributes)
end

def find_or_create_subscriber_list(attributes)

Parameters:
  • attributes (Hash) -- document_type, links, tags used to search existing subscriber lists
def find_or_create_subscriber_list(attributes)
  find_subscriber_list(attributes)
rescue GdsApi::HTTPNotFound
  create_subscriber_list(attributes)
end

def find_subscriber_list(attributes)

Parameters:
  • attributes (Hash) -- document_type, links, tags used to search existing subscriber lists
def find_subscriber_list(attributes)
  tags = 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 tags && links
    message = "please provide either tags or links (or neither), but not both"
    raise ArgumentError, message
  end
  params = {}
  params[:tags] = tags if tags
  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

def get_subscribable(reference:)

Returns:
  • (Hash) - subscribable: {
def get_subscribable(reference:)
  get_json("#{endpoint}/subscribables/#{reference}")
end

def get_subscription(id)

Returns:
  • (Hash) - subscription: {
def get_subscription(id)
  get_json("#{endpoint}/subscriptions/#{id}")
end

def get_subscriptions(address:)

Returns:
  • (Hash) - subscriber, subscriptions

Parameters:
  • string () -- Subscriber address
def get_subscriptions(address:)
  get_json("#{endpoint}/subscribers/#{address}/subscriptions")
end

def nested_query_string(params)

def nested_query_string(params)
  Rack::Utils.build_nested_query(params)
end

def send_alert(publication, headers = {})

Parameters:
  • publication (Hash) -- Valid publication attributes
def send_alert(publication, headers = {})
  post_json("#{endpoint}/notifications", publication, headers)
end

def subscribe(subscribable_id:, address:, frequency: "immediately")

Returns:
  • (Hash) - subscription_id
def subscribe(subscribable_id:, address:, frequency: "immediately")
  post_json(
    "#{endpoint}/subscriptions",
    subscribable_id: subscribable_id,
    address: address,
    frequency: frequency,
  )
end

def topic_matches(attributes)

Returns:
  • (Hash) - topics, enabled, disabled

Parameters:
  • attributes (Hash) -- tags, links, document_type,
def topic_matches(attributes)
  query_string = nested_query_string(attributes)
  get_json("#{endpoint}/topic-matches.json?#{query_string}")
end

def unsubscribe(uuid)

Returns:
  • (Hash) - deleted

Parameters:
  • uuid () -- Subscription uuid
def unsubscribe(uuid)
  post_json("#{endpoint}/unsubscribe/#{uuid}")
end