Class: Mailflow::SendMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/mailflow/send_message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attributesObject

Returns the value of attribute attributes.



7
8
9
# File 'lib/mailflow/send_message.rb', line 7

def attributes
  @attributes
end

#clientObject (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

Raises:



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