Class: Postful::Base

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/postful/base.rb

Overview

– TODO: address validations and SimpleValidation ++

Direct Known Subclasses

Letter, Postcard

Defined Under Namespace

Classes: DomesticAddress, InternationalAddress

Instance Attribute Summary collapse

Instance Method Summary collapse

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_addressObject

Returns the value of attribute return_address.



20
21
22
# File 'lib/postful/base.rb', line 20

def return_address
  @return_address
end

#sectionsObject

Returns the value of attribute sections.



21
22
23
# File 'lib/postful/base.rb', line 21

def sections
  @sections
end

#tag1Object

Returns the value of attribute tag1.



17
18
19
# File 'lib/postful/base.rb', line 17

def tag1
  @tag1
end

#tag2Object

Returns the value of attribute tag2.



18
19
20
# File 'lib/postful/base.rb', line 18

def tag2
  @tag2
end

#tag3Object

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, options = {}, &block)
  returning TemplateDocument.new(name, @email, @password) do |document|
    document.instance_exec(&block) if block
    document.source = options[:source] if options[: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

#errorsObject



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

Returns:

  • (Boolean)


70
71
72
73
74
# File 'lib/postful/base.rb', line 70

def valid?
  errors.clear
  validate
  errors.empty?
end