Class: Postal::SendMessage
- Inherits:
-
Object
- Object
- Postal::SendMessage
- Defined in:
- lib/postal/send_message.rb
Instance Method Summary collapse
- #attach(filename, content_type, data) ⇒ Object
- #bcc(*addresses) ⇒ Object
- #cc(*addresses) ⇒ Object
- #from(address) ⇒ Object
- #header(key, value) ⇒ Object
- #html_body(content) ⇒ Object
-
#initialize(client) ⇒ SendMessage
constructor
A new instance of SendMessage.
- #plain_body(content) ⇒ Object
- #reply_to(reply_to) ⇒ Object
- #send! ⇒ Object
- #sender(address) ⇒ Object
- #subject(subject) ⇒ Object
- #tag(tag) ⇒ Object
- #to(*addresses) ⇒ Object
Constructor Details
#initialize(client) ⇒ SendMessage
Returns a new instance of SendMessage.
7 8 9 10 |
# File 'lib/postal/send_message.rb', line 7 def initialize(client) @client = client @attributes = {} end |
Instance Method Details
#attach(filename, content_type, data) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/postal/send_message.rb', line 71 def attach(filename, content_type, data) @attributes[:attachments] ||= [] @attributes[:attachments] << { :name => filename, :content_type => content_type, :data => Base64.encode64(data) } end |
#bcc(*addresses) ⇒ Object
41 42 43 44 |
# File 'lib/postal/send_message.rb', line 41 def bcc(*addresses) @attributes[:bcc] ||= [] @attributes[:bcc] += addresses end |
#cc(*addresses) ⇒ Object
36 37 38 39 |
# File 'lib/postal/send_message.rb', line 36 def cc(*addresses) @attributes[:cc] ||= [] @attributes[:cc] += addresses end |
#from(address) ⇒ Object
23 24 25 |
# File 'lib/postal/send_message.rb', line 23 def from(address) @attributes[:from] = address end |
#header(key, value) ⇒ Object
66 67 68 69 |
# File 'lib/postal/send_message.rb', line 66 def header(key, value) @attributes[:headers] ||= {} @attributes[:headers][key.to_s] = value end |
#html_body(content) ⇒ Object
62 63 64 |
# File 'lib/postal/send_message.rb', line 62 def html_body(content) @attributes[:html_body] = content end |
#plain_body(content) ⇒ Object
58 59 60 |
# File 'lib/postal/send_message.rb', line 58 def plain_body(content) @attributes[:plain_body] = content end |
#reply_to(reply_to) ⇒ Object
54 55 56 |
# File 'lib/postal/send_message.rb', line 54 def reply_to(reply_to) @attributes[:reply_to] = subject end |
#send! ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/postal/send_message.rb', line 12 def send! api = @client.moonrope.request(:send, :message, @attributes) if api.success? SendResult.new(@client, api.data) elsif api.status == 'error' raise SendError.new(api.data['code'], api.data['message']) else raise Error, "Couldn't send message" end end |
#sender(address) ⇒ Object
27 28 29 |
# File 'lib/postal/send_message.rb', line 27 def sender(address) @attributes[:sender] = address end |
#subject(subject) ⇒ Object
46 47 48 |
# File 'lib/postal/send_message.rb', line 46 def subject(subject) @attributes[:subject] = subject end |
#tag(tag) ⇒ Object
50 51 52 |
# File 'lib/postal/send_message.rb', line 50 def tag(tag) @attributes[:tag] = subject end |
#to(*addresses) ⇒ Object
31 32 33 34 |
# File 'lib/postal/send_message.rb', line 31 def to(*addresses) @attributes[:to] ||= [] @attributes[:to] += addresses end |