Class: Courier::Resources::Previews

Inherits:
Object
  • Object
show all
Defined in:
lib/courier/resources/previews.rb,
sig/courier/resources/previews.rbs

Overview

Render a template's email content on real email clients and read back the screenshots, so you can check how it looks before you send it.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Previews

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Previews.

Parameters:



148
149
150
# File 'lib/courier/resources/previews.rb', line 148

def initialize(client:)
  @client = client
end

Instance Method Details

#archive_device_set(device_set_id, request_options: {}) ⇒ Courier::Models::DeviceSet

Archive a device set. This is a soft delete — the archived set is returned and no longer appears in list results. Runs already created against it keep their own copy of the device list and are unaffected. The Courier-provided default set cannot be archived and returns 409.

Parameters:

  • device_set_id (String) —

    The preview set to archive.

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



22
23
24
25
26
27
28
29
# File 'lib/courier/resources/previews.rb', line 22

def archive_device_set(device_set_id, params = {})
  @client.request(
    method: :delete,
    path: ["previews/device-sets/%1$s", device_set_id],
    model: Courier::DeviceSet,
    options: params[:request_options]
  )
end

#create_device_set(device_ids:, name:, request_options: {}) ⇒ Courier::Models::DeviceSet

Create a named, reusable set of preview devices. Every id must be one listed by GET /previews/devices; any other is a 422.

Parameters:

  • device_ids (Array<String>) —

    The devices the set contains, by PreviewDevice.id. At least one is required.

  • name (String) —

    Human-readable name.

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



45
46
47
48
49
50
51
52
53
54
# File 'lib/courier/resources/previews.rb', line 45

def create_device_set(params)
  parsed, options = Courier::PreviewCreateDeviceSetParams.dump_request(params)
  @client.request(
    method: :post,
    path: "previews/device-sets",
    body: parsed,
    model: Courier::DeviceSet,
    options: options
  )
end

#list_device_sets(request_options: {}) ⇒ Courier::Models::DeviceSetListResponse

List the workspace's preview sets. Archived sets are not returned.

Parameters:

Returns:

See Also:



65
66
67
68
69
70
71
72
# File 'lib/courier/resources/previews.rb', line 65

def list_device_sets(params = {})
  @client.request(
    method: :get,
    path: "previews/device-sets",
    model: Courier::DeviceSetListResponse,
    options: params[:request_options]
  )
end

#list_devices(request_options: {}) ⇒ Courier::Models::PreviewDeviceListResponse

List the devices a preview can be rendered on. Reference data, identical for every workspace — these ids are what a device set is built from and what a run reports results for.

Parameters:

Returns:

See Also:



85
86
87
88
89
90
91
92
# File 'lib/courier/resources/previews.rb', line 85

def list_devices(params = {})
  @client.request(
    method: :get,
    path: "previews/devices",
    model: Courier::PreviewDeviceListResponse,
    options: params[:request_options]
  )
end

#retrieve_device_set(device_set_id, request_options: {}) ⇒ Courier::Models::DeviceSet

Some parameter documentations has been truncated, see Models::PreviewRetrieveDeviceSetParams for more details.

Retrieve a preview set by ID. Archived sets return 404.

Parameters:

  • device_set_id (String) —

    The preview set to retrieve, identified by the id returned when it was created

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



108
109
110
111
112
113
114
115
# File 'lib/courier/resources/previews.rb', line 108

def retrieve_device_set(device_set_id, params = {})
  @client.request(
    method: :get,
    path: ["previews/device-sets/%1$s", device_set_id],
    model: Courier::DeviceSet,
    options: params[:request_options]
  )
end

#update_device_set(device_set_id, device_ids:, name:, request_options: {}) ⇒ Courier::Models::DeviceSet

Replace a device set. This is a full replace, not a patch — both the name and the device list are always written. The Courier-provided default set cannot be changed and returns 409.

Parameters:

  • device_set_id (String) —

    The preview set to replace.

  • device_ids (Array<String>) —

    The devices the set contains, by PreviewDevice.id. At least one is required.

  • name (String) —

    Human-readable name.

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



134
135
136
137
138
139
140
141
142
143
# File 'lib/courier/resources/previews.rb', line 134

def update_device_set(device_set_id, params)
  parsed, options = Courier::PreviewUpdateDeviceSetParams.dump_request(params)
  @client.request(
    method: :put,
    path: ["previews/device-sets/%1$s", device_set_id],
    body: parsed,
    model: Courier::DeviceSet,
    options: options
  )
end