Class: Mailosaur::Previews

Inherits:
Object
  • Object
show all
Defined in:
lib/Mailosaur/previews.rb

Overview

Operations for discovering the email clients available for generating email previews (screenshots of an email rendered in real clients). Accessed via client.previews.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conn, handle_http_error) ⇒ Previews

Creates and initializes a new instance of the Previews class.

Parameters:

  • conn (Faraday::Connection)

    The client connection.

  • handle_http_error (Method)

    Callback used to convert HTTP error responses into errors.



10
11
12
13
# File 'lib/Mailosaur/previews.rb', line 10

def initialize(conn, handle_http_error)
  @conn = conn
  @handle_http_error = handle_http_error
end

Instance Attribute Details

#connConnection (readonly)

Returns the client connection.

Returns:

  • (Connection)

    the client connection.



16
17
18
# File 'lib/Mailosaur/previews.rb', line 16

def conn
  @conn
end

Instance Method Details

#list_email_clientsMailosaur::Models::EmailClientListResult

List all email clients that can be used to generate email previews.

Returns:



23
24
25
26
27
28
# File 'lib/Mailosaur/previews.rb', line 23

def list_email_clients
  response = conn.get 'api/screenshots/clients'
  @handle_http_error.call(response) unless response.status == 200
  model = JSON.parse(response.body)
  Mailosaur::Models::EmailClientListResult.new(model)
end