Class: Notifications::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/notifications/client.rb,
lib/notifications/client/speaker.rb,
lib/notifications/client/version.rb,
lib/notifications/client/notification.rb,
lib/notifications/client/request_error.rb,
lib/notifications/client/template_preview.rb,
lib/notifications/client/response_template.rb,
lib/notifications/client/template_collection.rb,
lib/notifications/client/response_notification.rb,
lib/notifications/client/notifications_collection.rb

Defined Under Namespace

Classes: Notification, NotificationsCollection, RequestError, ResponseNotification, Speaker, Template, TemplateCollection, TemplatePreview

Constant Summary collapse

PRODUCTION_BASE_URL =
"https://api.notifications.service.gov.uk".freeze
VERSION =
"2.4.0".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Client

Returns a new instance of Client.



22
23
24
# File 'lib/notifications/client.rb', line 22

def initialize(*args)
  @speaker = Speaker.new(*args)
end

Instance Attribute Details

#speakerObject (readonly)

Returns the value of attribute speaker.



13
14
15
# File 'lib/notifications/client.rb', line 13

def speaker
  @speaker
end

Instance Method Details

#generate_template_preview(id, options = {}) ⇒ TemplatePreview

Parameters:

  • options (String) (defaults to: {})
  • personalisation (Hash)

    a customizable set of options

Returns:



118
119
120
121
122
123
# File 'lib/notifications/client.rb', line 118

def generate_template_preview(id, options = {})
  path = "/v2/template/" << id << "/preview"
  TemplatePreview.new(
    speaker.post_with_url(path, options)
  )
end

#get_all_templates(options = {}) ⇒ TemplateCollection

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :type (String)

    email, sms, letter

Returns:



107
108
109
110
111
112
# File 'lib/notifications/client.rb', line 107

def get_all_templates(options = {})
  path = "/v2/templates"
  TemplateCollection.new(
    speaker.get_with_url(path, options)
  )
end

#get_notification(id) ⇒ Notification

Parameters:

  • id (String)

Returns:

See Also:



57
58
59
60
61
# File 'lib/notifications/client.rb', line 57

def get_notification(id)
  Notification.new(
    speaker.get(id)
  )
end

#get_notifications(options = {}) ⇒ NotificationsCollection

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :template_type (String)

    sms or email

  • :status (String)

    sending, delivered, permanently failed, temporarily failed, or technical failure

  • :reference (String)

    your reference for the notification

  • :olderThanId (String)

    notification id to return notificaitons that are older than this id.

Returns:

See Also:



76
77
78
79
80
# File 'lib/notifications/client.rb', line 76

def get_notifications(options = {})
  NotificationsCollection.new(
    speaker.get(nil, options)
  )
end

#get_template_by_id(id, options = {}) ⇒ Template

Parameters:

  • id (String)

Returns:



85
86
87
88
89
90
# File 'lib/notifications/client.rb', line 85

def get_template_by_id(id, options = {})
  path = "/v2/template/" << id
  Template.new(
    speaker.get_with_url(path, options)
  )
end

#get_template_version(id, version, options = {}) ⇒ Template

Parameters:

  • id (String)
  • version (int)

Returns:



96
97
98
99
100
101
# File 'lib/notifications/client.rb', line 96

def get_template_version(id, version, options = {})
  path = "/v2/template/" << id << "/version/" << version.to_s
  Template.new(
    speaker.get_with_url(path, options)
  )
end

#send_email(args) ⇒ ResponseNotification

 @see Notifications::Client::Speaker#post



29
30
31
32
33
# File 'lib/notifications/client.rb', line 29

def send_email(args)
  ResponseNotification.new(
    speaker.post("email", args)
  )
end

#send_letter(args) ⇒ ResponseNotification



47
48
49
50
51
# File 'lib/notifications/client.rb', line 47

def send_letter(args)
  ResponseNotification.new(
    speaker.post("letter", args)
  )
end

#send_sms(args) ⇒ ResponseNotification



38
39
40
41
42
# File 'lib/notifications/client.rb', line 38

def send_sms(args)
  ResponseNotification.new(
    speaker.post("sms", args)
  )
end