Class: Mailflow::SendMessage
- Inherits:
-
Object
- Object
- Mailflow::SendMessage
- Defined in:
- lib/mailflow/send_message.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #attach(filename, content_type, data) ⇒ Object
- #header(key, value) ⇒ Object
-
#initialize(client) ⇒ SendMessage
constructor
A new instance of SendMessage.
- #send! ⇒ Object
Constructor Details
#initialize(client) ⇒ SendMessage
Returns a new instance of SendMessage.
9 10 11 12 |
# File 'lib/mailflow/send_message.rb', line 9 def initialize(client) @client = client initialize_attributes end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
7 8 9 |
# File 'lib/mailflow/send_message.rb', line 7 def attributes @attributes end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/mailflow/send_message.rb', line 6 def client @client end |
Instance Method Details
#attach(filename, content_type, data) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/mailflow/send_message.rb', line 39 def attach(filename, content_type, data) attributes[:attachments] << { name: filename, content_type: content_type, data: Base64.encode64(data) } end |
#header(key, value) ⇒ Object
35 36 37 |
# File 'lib/mailflow/send_message.rb', line 35 def header(key, value) attributes[:headers][key.to_s] = value end |
#send! ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/mailflow/send_message.rb', line 14 def send! api = client.moonrope.request(:send, :message, attributes) return SendResult.new(client, api.data) if api.success? raise SendError.new(api.data['code'], api.data['message']) if api.status == 'error' raise Error, "API response unsuccessful: #{api.data}" end |