Class: Mailosaur::Servers
- Inherits:
-
Object
- Object
- Mailosaur::Servers
- Defined in:
- lib/Mailosaur/servers.rb
Overview
Operations for creating and managing your Mailosaur inboxes (servers) — they group your tests together, each with its own domain and SMTP/POP3/IMAP credentials. Accessed via client.servers.
Instance Attribute Summary collapse
-
#conn ⇒ Connection
readonly
The client connection.
Instance Method Summary collapse
-
#create(server_create_options) ⇒ Mailosaur::Models::Server
Creates a new inbox (server).
-
#delete(id) ⇒ nil
Permanently delete an inbox (server).
-
#generate_email_address(server) ⇒ String
Generates a random email address by appending a random string in front of the domain name of the inbox (server).
-
#get(id) ⇒ Mailosaur::Models::Server
Retrieves the detail for a single inbox (server).
-
#get_password(id) ⇒ String
Retrieves the password for an inbox (server).
-
#initialize(conn, handle_http_error) ⇒ Servers
constructor
Creates and initializes a new instance of the Servers class.
-
#list ⇒ Mailosaur::Models::ServerListResult
Returns a list of your inboxes (servers).
-
#update(id, server) ⇒ Mailosaur::Models::Server
Updates the attributes of an inbox (server).
Constructor Details
#initialize(conn, handle_http_error) ⇒ Servers
Creates and initializes a new instance of the Servers class.
11 12 13 14 |
# File 'lib/Mailosaur/servers.rb', line 11 def initialize(conn, handle_http_error) @conn = conn @handle_http_error = handle_http_error end |
Instance Attribute Details
#conn ⇒ Connection (readonly)
Returns the client connection.
17 18 19 |
# File 'lib/Mailosaur/servers.rb', line 17 def conn @conn end |
Instance Method Details
#create(server_create_options) ⇒ Mailosaur::Models::Server
Creates a new inbox (server).
40 41 42 43 44 45 |
# File 'lib/Mailosaur/servers.rb', line 40 def create() response = conn.post 'api/servers', .to_json @handle_http_error.call(response) unless response.status == 200 model = JSON.parse(response.body) Mailosaur::Models::Server.new(model) end |
#delete(id) ⇒ nil
Permanently delete an inbox (server). This will also delete all messages, associated attachments, etc. within the inbox (server). This operation cannot be undone.
99 100 101 102 103 |
# File 'lib/Mailosaur/servers.rb', line 99 def delete(id) response = conn.delete "api/servers/#{id}" @handle_http_error.call(response) unless response.status == 204 nil end |
#generate_email_address(server) ⇒ String
Generates a random email address by appending a random string in front of the domain name of the inbox (server).
113 114 115 116 |
# File 'lib/Mailosaur/servers.rb', line 113 def generate_email_address(server) host = ENV['MAILOSAUR_SMTP_HOST'] || 'mailosaur.net' format('%s@%s.%s', SecureRandom.hex(3), server, host) end |
#get(id) ⇒ Mailosaur::Models::Server
Retrieves the detail for a single inbox (server).
54 55 56 57 58 59 |
# File 'lib/Mailosaur/servers.rb', line 54 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
Retrieves the password for an inbox (server). This password can be used for SMTP, POP3, and IMAP connectivity.
69 70 71 72 73 74 |
# File 'lib/Mailosaur/servers.rb', line 69 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 |
#list ⇒ Mailosaur::Models::ServerListResult
Returns a list of your inboxes (servers). Inboxes (servers) are returned sorted in alphabetical order.
25 26 27 28 29 30 |
# File 'lib/Mailosaur/servers.rb', line 25 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) ⇒ Mailosaur::Models::Server
Updates the attributes of an inbox (server).
84 85 86 87 88 89 |
# File 'lib/Mailosaur/servers.rb', line 84 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 |