Class: AppMail::Client
- Inherits:
-
Object
- Object
- AppMail::Client
- Defined in:
- lib/app_mail/client.rb
Class Method Summary collapse
-
.instance ⇒ Object
Create and cache a global instance of client based on the environment variables which can be provided.
Instance Method Summary collapse
-
#initialize(host, server_key) ⇒ Client
constructor
Initialize a new client with the host and API key.
-
#messages ⇒ Object
Provide a scope to access messages.
-
#moonrope ⇒ Object
Return the backend moonrope instance for this client.
-
#send_message(&block) ⇒ Object
Send a message.
Constructor Details
#initialize(host, server_key) ⇒ Client
Initialize a new client with the host and API key
19 20 21 22 |
# File 'lib/app_mail/client.rb', line 19 def initialize(host, server_key) @host = host @server_key = server_key end |
Class Method Details
.instance ⇒ Object
Create and cache a global instance of client based on the environment variables which can be provided. In 90% of cases, AppMail will be accessed through this.
12 13 14 |
# File 'lib/app_mail/client.rb', line 12 def self.instance @instance ||= Client.new(AppMail.config.host, AppMail.config.server_key) end |
Instance Method Details
#messages ⇒ Object
Provide a scope to access messages
27 28 29 |
# File 'lib/app_mail/client.rb', line 27 def MessageScope.new(self) end |
#moonrope ⇒ Object
Return the backend moonrope instance for this client
43 44 45 46 47 48 |
# File 'lib/app_mail/client.rb', line 43 def moonrope @moonrope ||= begin headers= {'X-Server-API-Key' => @server_key} MoonropeClient::Connection.new(@host, :headers => headers, :ssl => true) end end |
#send_message(&block) ⇒ Object
Send a message
34 35 36 37 38 |
# File 'lib/app_mail/client.rb', line 34 def (&block) = SendMessage.new(self) block.call() .send! end |