Class: Mailosaur::Servers

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conn, handle_http_error) ⇒ Servers

Creates and initializes a new instance of the Servers class.

Parameters:

  • client

    connection.



7
8
9
10
# File 'lib/Mailosaur/servers.rb', line 7

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.



13
14
15
# File 'lib/Mailosaur/servers.rb', line 13

def conn
  @conn
end

Instance Method Details

#create(server_create_options) ⇒ Server

Create a server

Creates a new virtual SMTP server and returns it.

Parameters:

  • server_create_options (ServerCreateOptions)

Returns:

  • (Server)

    operation results.



39
40
41
42
43
44
# File 'lib/Mailosaur/servers.rb', line 39

def create(server_create_options)
  response = conn.post 'api/servers', server_create_options.to_json
  @handle_http_error.call(response) unless response.status == 200
  model = JSON.parse(response.body)
  Mailosaur::Models::Server.new(model)
end

#delete(id) ⇒ Object

Delete a server

Permanently deletes a server. This operation cannot be undone. Also deletes all messages and associated attachments within the server.

Parameters:

  • id (String)

    The identifier of the server to be deleted.



105
106
107
108
109
# File 'lib/Mailosaur/servers.rb', line 105

def delete(id)
  response = conn.delete "api/servers/#{id}"
  @handle_http_error.call(response) unless response.status == 204
  nil
end

#generate_email_address(server) ⇒ Object



111
112
113
114
# File 'lib/Mailosaur/servers.rb', line 111

def generate_email_address(server)
  host = ENV['MAILOSAUR_SMTP_HOST'] || 'mailosaur.net'
  format('%s@%s.%s', SecureRandom.hex(3), server, host)
end

#get(id) ⇒ Server

Retrieve a server

Retrieves the detail for a single server. Simply supply the unique identifier for the required server.

Parameters:

  • id (String)

    The identifier of the server to be retrieved.

Returns:

  • (Server)

    operation results.



56
57
58
59
60
61
# File 'lib/Mailosaur/servers.rb', line 56

def get(id)
  response = conn.get "api/servers/#{id}"
  @handle_http_error.call(response) unless response.status == 200
  model = JSON.parse(response.body)
  Mailosaur::Models::Server.new(model)
end

#get_password(id) ⇒ String

Retrieve server password

Retrieves the password for use with SMTP and POP3 for a single server. Simply supply the unique identifier for the required server.

Parameters:

  • id (String)

    The identifier of the server.

Returns:

  • (String)

    Server password.



73
74
75
76
77
78
# File 'lib/Mailosaur/servers.rb', line 73

def get_password(id)
  response = conn.get "api/servers/#{id}/password"
  @handle_http_error.call(response) unless response.status == 200
  model = JSON.parse(response.body)
  model['value']
end

#listServerListResult

List all servers

Returns a list of your virtual SMTP servers. Servers are returned sorted in alphabetical order.

Returns:

  • (ServerListResult)

    operation results.



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

def list
  response = conn.get 'api/servers'
  @handle_http_error.call(response) unless response.status == 200
  model = JSON.parse(response.body)
  Mailosaur::Models::ServerListResult.new(model)
end

#update(id, server) ⇒ Server

Update a server

Updats a single server and returns it.

Parameters:

  • id (String)

    The identifier of the server to be updated.

  • server (Server)

Returns:

  • (Server)

    operation results.



90
91
92
93
94
95
# File 'lib/Mailosaur/servers.rb', line 90

def update(id, server)
  response = conn.put "api/servers/#{id}", server.to_json
  @handle_http_error.call(response) unless response.status == 200
  model = JSON.parse(response.body)
  Mailosaur::Models::Server.new(model)
end