Class: Postal::Client
- Inherits:
-
Object
- Object
- Postal::Client
- Defined in:
- lib/postal/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.
-
#send_raw_message(&block) ⇒ Object
Send a raw message.
Constructor Details
#initialize(host, server_key) ⇒ Client
Initialize a new client with the host and API key
20 21 22 23 |
# File 'lib/postal/client.rb', line 20 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, Postal will be accessed through this.
13 14 15 |
# File 'lib/postal/client.rb', line 13 def self.instance @instance ||= Client.new(Postal.config.host, Postal.config.server_key) end |
Instance Method Details
#messages ⇒ Object
Provide a scope to access messages
28 29 30 |
# File 'lib/postal/client.rb', line 28 def MessageScope.new(self) end |
#moonrope ⇒ Object
Return the backend moonrope instance for this client
53 54 55 56 57 58 |
# File 'lib/postal/client.rb', line 53 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
35 36 37 38 39 |
# File 'lib/postal/client.rb', line 35 def (&block) = SendMessage.new(self) block.call() .send! end |
#send_raw_message(&block) ⇒ Object
Send a raw message
44 45 46 47 48 |
# File 'lib/postal/client.rb', line 44 def (&block) = SendRawMessage.new(self) block.call() .send! end |