Class: Postful::Base
Overview
– TODO: address validations and SimpleValidation ++
Defined Under Namespace
Classes: DomesticAddress, InternationalAddress
Instance Attribute Summary collapse
-
#return_address ⇒ Object
Returns the value of attribute return_address.
-
#sections ⇒ Object
Returns the value of attribute sections.
-
#tag1 ⇒ Object
Returns the value of attribute tag1.
-
#tag2 ⇒ Object
Returns the value of attribute tag2.
-
#tag3 ⇒ Object
Returns the value of attribute tag3.
Instance Method Summary collapse
-
#add_address(attributes = {}) ⇒ Object
Add a domestic recipient to a mailing.
-
#add_document(name, options = {}, &block) ⇒ Object
(also: #document)
Adds a new document to the request that should be customized by setting section properties.
-
#add_international_address(lines, country) ⇒ Object
Add an international recipient to a mailing.
- #errors ⇒ Object
-
#initialize(email, password) ⇒ Base
constructor
A new instance of Base.
- #mail! ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(email, password) ⇒ Base
Returns a new instance of Base.
25 26 27 28 29 30 31 |
# File 'lib/postful/base.rb', line 25 def initialize(email, password) @email = email @password = password @documents = [] @addressees = [] @sections = [] end |
Instance Attribute Details
#return_address ⇒ Object
Returns the value of attribute return_address.
20 21 22 |
# File 'lib/postful/base.rb', line 20 def return_address @return_address end |
#sections ⇒ Object
Returns the value of attribute sections.
21 22 23 |
# File 'lib/postful/base.rb', line 21 def sections @sections end |
#tag1 ⇒ Object
Returns the value of attribute tag1.
17 18 19 |
# File 'lib/postful/base.rb', line 17 def tag1 @tag1 end |
#tag2 ⇒ Object
Returns the value of attribute tag2.
18 19 20 |
# File 'lib/postful/base.rb', line 18 def tag2 @tag2 end |
#tag3 ⇒ Object
Returns the value of attribute tag3.
19 20 21 |
# File 'lib/postful/base.rb', line 19 def tag3 @tag3 end |
Instance Method Details
#add_address(attributes = {}) ⇒ Object
Add a domestic recipient to a mailing
44 45 46 47 48 49 50 51 |
# File 'lib/postful/base.rb', line 44 def add_address(attributes = {}) returning DomesticAddress.new do |address| [:name, :company, :address, :address2, :city, :state, :postal_code].each do |field| address.send("#{field}=", attributes[field] || attributes[field.to_s]) end @addressees << address end end |
#add_document(name, options = {}, &block) ⇒ Object Also known as: document
Adds a new document to the request that should be customized by setting section properties
34 35 36 37 38 39 40 |
# File 'lib/postful/base.rb', line 34 def add_document(name, = {}, &block) returning TemplateDocument.new(name, @email, @password) do |document| document.instance_exec(&block) if block document.source = [:source] if [:source] @documents << document end end |
#add_international_address(lines, country) ⇒ Object
Add an international recipient to a mailing
54 55 56 57 58 59 60 |
# File 'lib/postful/base.rb', line 54 def add_international_address(lines, country) returning InternationalAddress.new do |address| address.lines = lines address.country = country @addressees << address end end |
#errors ⇒ Object
76 77 78 |
# File 'lib/postful/base.rb', line 76 def errors @errors ||= [] end |
#mail! ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/postful/base.rb', line 62 def mail! if !valid? raise errors.join("\n") else mail_without_validation! end end |
#valid? ⇒ Boolean
70 71 72 73 74 |
# File 'lib/postful/base.rb', line 70 def valid? errors.clear validate errors.empty? end |