class GdsApi::EmailAlertApi

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

def change_subscriber(id:, new_address:)

Returns:
  • (Hash) - subscriber

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

def change_subscription(id:, frequency:)

Returns:
  • (Hash) - subscription

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

def create_content_change(content_change, headers = {})

Parameters:
  • content_change (Hash) -- Valid content change attributes
def create_content_change(content_change, headers = {})
  post_json("#{endpoint}/content-changes", content_change, headers)
end

def create_message(message, headers = {})

Parameters:
  • message (Hash) -- Valid message attributes
def create_message(message, headers = {})
  post_json("#{endpoint}/messages", message, headers)
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"]
  combine_mode = attributes["combine_mode"]
  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[:combine_mode] = combine_mode if combine_mode
  query_string = nested_query_string(params)
  get_json("#{endpoint}/subscriber-lists?" + query_string)
end

def get_latest_matching_subscription(id)

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

def get_subscriber_list(slug:)

Returns:
  • (Hash) - subscriber_list: {
def get_subscriber_list(slug:)
  get_json("#{endpoint}/subscriber-lists/#{uri_encode(slug)}")
end

def get_subscription(id)

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

def get_subscriptions(id:, order: nil)

Returns:
  • (Hash) - subscriber, subscriptions

Parameters:
  • Subscription (string) -- order - title, created_at
  • Subscriber (integer) -- id
def get_subscriptions(id:, order: nil)
  if order
    get_json("#{endpoint}/subscribers/#{uri_encode(id)}/subscriptions?order=#{uri_encode(order)}")
  else
    get_json("#{endpoint}/subscribers/#{uri_encode(id)}/subscriptions")
  end
end

def nested_query_string(params)

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

def send_subscriber_verification_email(address:, destination:)

Returns:
  • (Hash) - subscriber

Parameters:
  • destination (string) -- Path on GOV.UK that subscriber will be emailed
  • address (string) -- Address to send verification email to
def send_subscriber_verification_email(address:, destination:)
  post_json(
    "#{endpoint}/subscribers/auth-token",
    address: address,
    destination: destination,
  )
end

def send_subscription_verification_email(address:, frequency:, topic_id:)

Parameters:
  • topic_id (string) -- The slugs/ID for the topic being subscribed to
  • frequency (string) -- How often the subscriber wishes to be notified of new items
  • address (string) -- Address to send verification email to
def send_subscription_verification_email(address:, frequency:, topic_id:)
  post_json(
    "#{endpoint}/subscriptions/auth-token",
    address: address,
    frequency: frequency,
    topic_id: topic_id,
  )
end

def send_unpublish_message(message)

Parameters:
  • message (Hash) -- content_id
def send_unpublish_message(message)
  post_json("#{endpoint}/unpublish-messages", message)
end

def subscribe(subscriber_list_id:, address:, frequency: "immediately", skip_confirmation_email: false)

Returns:
  • (Hash) - subscription_id
def subscribe(subscriber_list_id:, address:, frequency: "immediately", skip_confirmation_email: false)
  post_json(
    "#{endpoint}/subscriptions",
    subscriber_list_id: subscriber_list_id,
    address: address,
    frequency: frequency,
    skip_confirmation_email: skip_confirmation_email,
  )
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:
  • (nil) -

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

def unsubscribe_subscriber(id)

Returns:
  • (nil) -

Parameters:
  • Subscriber (integer) -- id
def unsubscribe_subscriber(id)
  delete_json("#{endpoint}/subscribers/#{uri_encode(id)}")
end