Class: Postal::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/postal/client.rb

Class Method Summary collapse

Instance Method Summary collapse

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

.instanceObject

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

#messagesObject

Provide a scope to access messages


28
29
30
# File 'lib/postal/client.rb', line 28

def messages
  MessageScope.new(self)
end

#moonropeObject

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 send_message(&block)
  message = SendMessage.new(self)
  block.call(message)
  message.send!
end

#send_raw_message(&block) ⇒ Object

Send a raw message


44
45
46
47
48
# File 'lib/postal/client.rb', line 44

def send_raw_message(&block)
  message = SendRawMessage.new(self)
  block.call(message)
  message.send!
end