Module: Diaspora::Exporters::XML

Defined in:
lib/diaspora/exporter.rb

Instance Method Summary collapse

Instance Method Details

#execute(user) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/diaspora/exporter.rb', line 15

def execute(user)
  builder = Nokogiri::XML::Builder.new do |xml|
    user_person_id = user.person_id
    xml.export {
      xml.user {
        xml.username user.username
        xml.serialized_private_key user.serialized_private_key

        xml.parent << user.person.to_xml
      }



      xml.aspects {
        user.aspects.each do |aspect|
          xml.aspect {
            xml.name aspect.name

#                  xml.person_ids {
              #aspect.person_ids.each do |id|
                #xml.person_id id
              #end
            #}

            xml.post_ids {
              aspect.posts.find_all_by_author_id(user_person_id).each do |post|
                xml.post_id post.id
              end
            }
          }
        end
      }

      xml.contacts {
        user.contacts.each do |contact|
        xml.contact {
          xml.user_id contact.user_id
          xml.person_id contact.person_id
          xml.person_guid contact.person_guid

          xml.aspects {
            contact.aspects.each do |aspect|
              xml.aspect {
                xml.name aspect.name
              }
            end
          }
        }
        end
      }

      xml.posts {
        user.visible_shareables(Post).find_all_by_author_id(user_person_id).each do |post|
          #post.comments.each do |comment|
          #  post_doc << comment.to_xml
          #end

          xml.parent << post.to_xml
        end
      }

      xml.people {
        user.contacts.each do |contact|
          person = contact.person
          xml.parent << person.to_xml

        end
      }
    }
  end

  builder.to_xml.to_s
end