Class: GdsApi::EmailAlertApi

Inherits:
Base
  • Object
show all
Defined in:
lib/gds_api/email_alert_api.rb

Overview

Adapter for the Email Alert API

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

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

Parameters:

  • Subscriber (integer)

    id

  • Subscriber (string)

    new_address

Returns:

  • (Hash)

    subscriber



159
160
161
162
163
164
# File 'lib/gds_api/email_alert_api.rb', line 159

def change_subscriber(id:, new_address:)
  patch_json(
    "#{endpoint}/subscribers/#{uri_encode(id)}",
    new_address: new_address,
  )
end

#change_subscription(id:, frequency:) ⇒ Hash

Patch a Subscription

Parameters:

  • Subscription (string)

    id

  • Subscription (string)

    frequency

Returns:

  • (Hash)

    subscription



172
173
174
175
176
177
# File 'lib/gds_api/email_alert_api.rb', line 172

def change_subscription(id:, frequency:)
  patch_json(
    "#{endpoint}/subscriptions/#{uri_encode(id)}",
    frequency: frequency,
  )
end

#create_content_change(content_change, headers = {}) ⇒ Object

Post a content change

Parameters:

  • content_change (Hash)

    Valid content change attributes



32
33
34
# File 'lib/gds_api/email_alert_api.rb', line 32

def create_content_change(content_change, headers = {})
  post_json("#{endpoint}/content-changes", content_change, headers)
end

#create_message(message, headers = {}) ⇒ Object

Post a message

Parameters:

  • message (Hash)

    Valid message attributes



39
40
41
# File 'lib/gds_api/email_alert_api.rb', line 39

def create_message(message, headers = {})
  post_json("#{endpoint}/messages", message, headers)
end

#find_or_create_subscriber_list(attributes) ⇒ Object

Get or Post subscriber list

Parameters:

  • attributes (Hash)

    document_type, links, tags used to search existing subscriber lists



12
13
14
15
16
17
18
19
# File 'lib/gds_api/email_alert_api.rb', line 12

def find_or_create_subscriber_list(attributes)
  if attributes["tags"] && attributes["links"]
    message = "please provide either tags or links (or neither), but not both"
    raise ArgumentError, message
  end

  post_json("#{endpoint}/subscriber-lists", attributes)
end

#find_subscriber_list(attributes) ⇒ Object

Get a subscriber list

Parameters:

  • attributes (Hash)

    document_type, links, tags used to search existing subscriber lists



24
25
26
27
# File 'lib/gds_api/email_alert_api.rb', line 24

def find_subscriber_list(attributes)
  query_string = nested_query_string(attributes)
  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.

}

Returns:

  • (Hash)

    subscription: { id subscriber_list subscriber created_at updated_at ended_at ended_reason frequency source



135
136
137
# File 'lib/gds_api/email_alert_api.rb', line 135

def get_latest_matching_subscription(id)
  get_json("#{endpoint}/subscriptions/#{uri_encode(id)}/latest")
end

#get_subscriber_list(slug:) ⇒ Hash

Get a Subscriber List

}

Returns:

  • (Hash)

    subscriber_list: { id title created_at updated_at document_type tags links email_document_supertype government_document_supertype subscriber_count



99
100
101
# File 'lib/gds_api/email_alert_api.rb', line 99

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

#get_subscription(id) ⇒ Hash

Get a Subscription

}

Returns:

  • (Hash)

    subscription: { id subscriber_list subscriber created_at updated_at ended_at ended_reason frequency source



116
117
118
# File 'lib/gds_api/email_alert_api.rb', line 116

def get_subscription(id)
  get_json("#{endpoint}/subscriptions/#{uri_encode(id)}")
end

#get_subscriptions(id:, order: nil) ⇒ Hash

Get Subscriptions for a Subscriber

Parameters:

  • Subscriber (integer)

    id

  • Subscription (string)

    order - title, created_at

Returns:

  • (Hash)

    subscriber, subscriptions



145
146
147
148
149
150
151
# File 'lib/gds_api/email_alert_api.rb', line 145

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

#send_subscriber_verification_email(address:, destination:) ⇒ Hash

Verify a subscriber has control of a provided email

Parameters:

  • address (string)

    Address to send verification email to

  • destination (string)

    Path on GOV.UK that subscriber will be emailed

Returns:

  • (Hash)

    subscriber



186
187
188
189
190
191
192
# File 'lib/gds_api/email_alert_api.rb', line 186

def send_subscriber_verification_email(address:, destination:)
  post_json(
    "#{endpoint}/subscribers/auth-token",
    address: address,
    destination: destination,
  )
end

#send_subscription_verification_email(address:, frequency:, topic_id:) ⇒ Object

Verify a subscriber intends to be added to a subscription

return [Hash] subscription

Parameters:

  • address (string)

    Address to send verification email to

  • frequency (string)

    How often the subscriber wishes to be notified of new items

  • topic_id (string)

    The slugs/ID for the topic being subscribed to



202
203
204
205
206
207
208
209
# File 'lib/gds_api/email_alert_api.rb', line 202

def send_subscription_verification_email(address:, frequency:, topic_id:)
  post_json(
    "#{endpoint}/subscriptions/auth-token",
    address: address,
    frequency: frequency,
    topic_id: topic_id,
  )
end

#subscribe(subscriber_list_id:, address:, frequency: "immediately", skip_confirmation_email: false) ⇒ Hash

Subscribe

Returns:

  • (Hash)

    subscription_id



75
76
77
78
79
80
81
82
83
# File 'lib/gds_api/email_alert_api.rb', line 75

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

#topic_matches(attributes) ⇒ Hash

Get topic matches

email_document_supertype, government_document_supertype

Parameters:

  • attributes (Hash)

    tags, links, document_type,

Returns:

  • (Hash)

    topics, enabled, disabled



49
50
51
52
# File 'lib/gds_api/email_alert_api.rb', line 49

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

Parameters:

  • Subscription (string)

    uuid

Returns:

  • (nil)


59
60
61
# File 'lib/gds_api/email_alert_api.rb', line 59

def unsubscribe(uuid)
  post_json("#{endpoint}/unsubscribe/#{uri_encode(uuid)}")
end

#unsubscribe_subscriber(id) ⇒ nil

Unsubscribe subscriber from everything

Parameters:

  • Subscriber (integer)

    id

Returns:

  • (nil)


68
69
70
# File 'lib/gds_api/email_alert_api.rb', line 68

def unsubscribe_subscriber(id)
  delete_json("#{endpoint}/subscribers/#{uri_encode(id)}")
end