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/received_text.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,
lib/notifications/client/received_text_collection.rb,
lib/notifications/client/response_precompiled_letter.rb

Defined Under Namespace

Modules: ErrorHandling Classes: AuthError, BadRequestError, ClientError, NotFoundError, Notification, NotificationsCollection, RateLimitError, ReceivedText, ReceivedTextCollection, RequestError, ResponseNotification, ResponsePrecompiledLetter, ServerError, Speaker, Template, TemplateCollection, TemplatePreview

Constant Summary collapse

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

2MB limit on uploaded documents

2 * 1024 * 1024
VERSION =
"6.4.0".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Client

Returns a new instance of Client.



28
29
30
# File 'lib/notifications/client.rb', line 28

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

Instance Attribute Details

#speakerObject (readonly)

Returns the value of attribute speaker.



18
19
20
# File 'lib/notifications/client.rb', line 18

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:



144
145
146
147
148
149
# File 'lib/notifications/client.rb', line 144

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:



133
134
135
136
137
138
# File 'lib/notifications/client.rb', line 133

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:



83
84
85
86
87
# File 'lib/notifications/client.rb', line 83

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

  • :older_than (String)

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

Returns:

See Also:



102
103
104
105
106
# File 'lib/notifications/client.rb', line 102

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

#get_pdf_for_letter(id) ⇒ String

Parameters:

  • id (String)

Returns:

  • (String)

See Also:



75
76
77
# File 'lib/notifications/client.rb', line 75

def get_pdf_for_letter(id)
  speaker.get_pdf_for_letter(id)
end

#get_received_texts(options = {}) ⇒ ReceivedTextCollection

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :older_than (String)

    received text id to return received texts that are older than this id.

Returns:



155
156
157
158
159
160
# File 'lib/notifications/client.rb', line 155

def get_received_texts(options = {})
  path = "/v2/received-text-messages"
  ReceivedTextCollection.new(
    speaker.get_with_url(path, options)
  )
end

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

Parameters:

  • id (String)

Returns:



111
112
113
114
115
116
# File 'lib/notifications/client.rb', line 111

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:



122
123
124
125
126
127
# File 'lib/notifications/client.rb', line 122

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

Optional email-only keys are documented on Notifications::Client::Speaker#post.



36
37
38
39
40
# File 'lib/notifications/client.rb', line 36

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

#send_letter(args) ⇒ ResponseNotification



54
55
56
57
58
# File 'lib/notifications/client.rb', line 54

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

#send_precompiled_letter(reference, pdf_file, postage = nil) ⇒ ResponsePrecompiledLetter

Parameters:

  • reference (String)
  • pdf_file (File)

Returns:

See Also:



65
66
67
68
69
# File 'lib/notifications/client.rb', line 65

def send_precompiled_letter(reference, pdf_file, postage = nil)
  ResponsePrecompiledLetter.new(
    speaker.post_precompiled_letter(reference, pdf_file, postage)
  )
end

#send_sms(args) ⇒ ResponseNotification



45
46
47
48
49
# File 'lib/notifications/client.rb', line 45

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