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

#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
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gds_api/email_alert_api.rb', line 12

def find_or_create_subscriber_list(attributes)
  tags = attributes["tags"]
  links = attributes["links"]
  document_type = attributes["document_type"]

  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

  search_subscriber_list(params)
rescue GdsApi::HTTPNotFound
  create_subscriber_list(attributes)
end

#notification(id) ⇒ Hash

Get notification

Parameters:

  • id (String)

    GovDelivery bulletin id

Returns:

  • (Hash)

    notification



55
56
57
# File 'lib/gds_api/email_alert_api.rb', line 55

def notification(id)
  get_json!("#{endpoint}/notifications/#{id}")
end

#notifications(start_at = nil) ⇒ Hash

Get notifications

Parameters:

  • start_at (Hash) (defaults to: nil)

    a customizable set of options

Options Hash (start_at):

  • Optional (String)

    GovDelivery bulletin id to page back through notifications

Returns:

  • (Hash)

    notifications



44
45
46
47
48
# File 'lib/gds_api/email_alert_api.rb', line 44

def notifications(start_at=nil)
  url = "#{endpoint}/notifications"
  url += "?start_at=#{start_at}" if start_at
  get_json!(url)
end

#send_alert(publication) ⇒ Object

Post notification

Parameters:

  • publication (Hash)

    Valid publication attributes



35
36
37
# File 'lib/gds_api/email_alert_api.rb', line 35

def send_alert(publication)
  post_json!("#{endpoint}/notifications", publication)
end