Class: Lotus::Atom::Entry

Inherits:
Atom::Entry
  • Object
show all
Includes:
Atom::SimpleExtensions
Defined in:
lib/lotus/atom/entry.rb

Constant Summary collapse

THREAD_NAMESPACE =

The XML namespace that identifies the conforming specification of ‘thr’ elements.

"http://purl.org/syndication/thread/1.0"
ACTIVITY_NAMESPACE =

The XML namespace that identifies the conforming specification.

'http://activitystrea.ms/spec/1.0/'
SCHEMA_ROOT =

The XML schema that identifies the conforming schema for objects.

'http://activitystrea.ms/schema/1.0/'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_canonical(obj) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/lotus/atom/entry.rb', line 74

def self.from_canonical(obj)
  entry_hash = obj.to_hash

  # Ensure that the content type is encoded.
  node = XML::Node.new("content")
  node['type'] = entry_hash[:content_type] if entry_hash[:content_type]
  node << entry_hash[:content]

  xml = XML::Reader.string(node.to_s)
  xml.read
  entry_hash[:content] = ::Atom::Content.parse(xml)
  entry_hash.delete :content_type

  if entry_hash[:source]
    entry_hash[:source] = Lotus::Atom::Source.from_canonical(entry_hash[:source])
  end

  if entry_hash[:actor]
    entry_hash[:author] = Lotus::Atom::Author.from_canonical(entry_hash[:actor])
  end
  entry_hash.delete :actor

  # Encode in-reply-to fields
  entry_hash[:thr_in_reply_to] = entry_hash[:in_reply_to].map do |t|
    Lotus::Atom::Thread.new(:href => t.url,
                              :ref  => t.id)
  end
  entry_hash.delete :in_reply_to

  entry_hash[:links] ||= []

  if entry_hash[:url]
    entry_hash[:links] << ::Atom::Link.new(:rel => "self", :href => entry_hash[:url])
  end
  entry_hash.delete :url

  object_type = entry_hash[:type]
  if object_type
    entry_hash[:activity_object_type] = SCHEMA_ROOT + object_type.to_s
  end
  entry_hash[:activity_object] = entry_hash[:object] if entry_hash[:object]
  if entry_hash[:verb]
    entry_hash[:activity_verb] = SCHEMA_ROOT + entry_hash[:verb].to_s
  end
  entry_hash[:activity_target] = entry_hash[:target] if entry_hash[:target]

  entry_hash.delete :object
  entry_hash.delete :verb
  entry_hash.delete :target
  entry_hash.delete :type

  self.new(entry_hash)
end

Instance Method Details



66
67
68
# File 'lib/lotus/atom/entry.rb', line 66

def link
  links.group_by { |l| l.rel.intern if l.rel }
end

#link=(options) ⇒ Object



70
71
72
# File 'lib/lotus/atom/entry.rb', line 70

def link= options
  links.clear << ::Atom::Link.new(options)
end

#to_canonicalObject



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/lotus/atom/entry.rb', line 128

def to_canonical
  # Reform the activity type
  # TODO: Add new Base schema verbs
  object_type = self.activity_object_type
  if object_type && object_type.start_with?(SCHEMA_ROOT)
    object_type.gsub!(/^#{Regexp.escape(SCHEMA_ROOT)}/, "")
  end

  object = nil
  object = self.activity_object.to_canonical if self.activity_object

  source = self.source
  source = source.to_canonical if source
  Lotus::Activity.new(:actor        => self.author ? self.author.to_canonical : nil,
                      :id           => self.id,
                      :url          => self.url,
                      :title        => self.title,
                      :source       => source,
                      :in_reply_to  => self.thr_in_reply_to.map(&:to_canonical),
                      :content      => self.content.to_s,
                      :content_type => self.content.type,
                      :link         => self.link,
                      :object       => object,
                      :type         => object_type,
                      :verb         => self.activity_verb,
                      :target       => self.activity_target,
                      :published    => self.published,
                      :updated      => self.updated)
end

#urlObject



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/lotus/atom/entry.rb', line 54

def url
  if links.alternate
    links.alternate.href
  elsif links.self
    links.self.href
  else
    links.map.each do |l|
      l.href
    end.compact.first
  end
end