Class: Mailosaur::Servers
- Inherits:
-
Object
- Object
- Mailosaur::Servers
- Defined in:
- lib/Mailosaur/servers.rb
Instance Attribute Summary collapse
-
#conn ⇒ Connection
readonly
The client connection.
Instance Method Summary collapse
-
#create(server_create_options) ⇒ Server
Create a server.
-
#delete(id) ⇒ Object
Delete a server.
- #generate_email_address(server) ⇒ Object
-
#get(id) ⇒ Server
Retrieve a server.
-
#get_password(id) ⇒ String
Retrieve server password.
-
#initialize(conn, handle_http_error) ⇒ Servers
constructor
Creates and initializes a new instance of the Servers class.
-
#list ⇒ ServerListResult
List all servers.
-
#update(id, server) ⇒ Server
Update a server.
Constructor Details
#initialize(conn, handle_http_error) ⇒ Servers
Creates and initializes a new instance of the Servers class.
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
#conn ⇒ Connection (readonly)
Returns 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.
39 40 41 42 43 44 |
# File 'lib/Mailosaur/servers.rb', line 39 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) ⇒ Object
Delete a server
Permanently deletes a server. This operation cannot be undone. Also deletes all messages and associated attachments within the server.
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.
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.
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 |
#list ⇒ ServerListResult
List all servers
Returns a list of your virtual SMTP servers. Servers are returned sorted in alphabetical order.
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.
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 |