Class: Postful::TemplateDocument

Inherits:
Document
  • Object
show all
Defined in:
lib/postful/template_document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, email, password) ⇒ TemplateDocument

Returns a new instance of TemplateDocument.



28
29
30
31
32
33
34
# File 'lib/postful/template_document.rb', line 28

def initialize(name, email, password)
  super(email, password)
  @name = name
  @source = 'gallery'      
  @sections = []
  @properties = {}
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



37
38
39
# File 'lib/postful/template_document.rb', line 37

def name
  @name
end

#propertiesObject (readonly)

Returns the value of attribute properties.



39
40
41
# File 'lib/postful/template_document.rb', line 39

def properties
  @properties
end

#sectionsObject (readonly)

Returns the value of attribute sections.



38
39
40
# File 'lib/postful/template_document.rb', line 38

def sections
  @sections
end

#sourceObject

Returns the value of attribute source.



36
37
38
# File 'lib/postful/template_document.rb', line 36

def source
  @source
end

Instance Method Details

#add_property(key, value) ⇒ Object Also known as: property



41
42
43
# File 'lib/postful/template_document.rb', line 41

def add_property(key, value)
  @properties[key] = value
end

#add_section(name, &block) ⇒ Object Also known as: section



47
48
49
50
51
52
# File 'lib/postful/template_document.rb', line 47

def add_section(name, &block)
  returning Section.new(name, @email, @password) do |section|
    section.instance_exec(&block) if block
    sections << section
  end
end

#build_request(builder) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/postful/template_document.rb', line 6

def build_request(builder)
  builder.document do
    builder.template do 
      builder.source source
      builder.name name
    end
    builder.sections do 
      sections.each do |section|
        section.build_request(builder)
      end
    end if sections.any?
    builder.properties do 
      properties.each_pair do |key, value|
        builder.property do
          builder.key key
          builder.value value
        end
      end
    end if properties.keys.any?
  end
end

#do_uploadObject



60
61
62
63
64
# File 'lib/postful/template_document.rb', line 60

def do_upload
  sections.each do |section|
    section.do_upload if section.requires_upload?
  end
end

#requires_upload?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/postful/template_document.rb', line 56

def requires_upload?
  !(sections.find { |section| section.requires_upload? }).nil?
end