class Mailosaur::Servers
Attributes
@return [Connection] the client connection.
Public Class Methods
Creates and initializes a new instance of the Servers
class. @param client connection.
# File lib/Mailosaur/servers.rb, line 7 def initialize(conn, handle_http_error) @conn = conn @handle_http_error = handle_http_error end
Public Instance Methods
Create a server
Creates a new virtual SMTP server and returns it.
@param server_create_options [ServerCreateOptions]
@return [Server] operation results.
# 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.load(response.body) Mailosaur::Models::Server.new(model) end
Delete a server
Permanently deletes a server. This operation cannot be undone. Also deletes all messages and associated attachments within the server.
@param id [String] The identifier of the server to be deleted.
# 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
# File lib/Mailosaur/servers.rb, line 111 def generate_email_address(server) host = ENV['MAILOSAUR_SMTP_HOST'] || 'mailosaur.net' '%s@%s.%s' % [SecureRandom.hex(3), server, host] end
Retrieve a server
Retrieves the detail for a single server. Simply supply the unique identifier for the required server.
@param id [String] The identifier of the server to be retrieved.
@return [Server] operation results.
# 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.load(response.body) Mailosaur::Models::Server.new(model) end
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.
@param id [String] The identifier of the server.
@return [String] Server password.
# 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.load(response.body) model['value'] end
List all servers
Returns a list of your virtual SMTP servers. Servers
are returned sorted in alphabetical order.
@return [ServerListResult] operation results.
# 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.load(response.body) Mailosaur::Models::ServerListResult.new(model) end
Update a server
Updats a single server and returns it.
@param id [String] The identifier of the server to be updated. @param server [Server]
@return [Server] operation results.
# 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.load(response.body) Mailosaur::Models::Server.new(model) end