Class: MingleEvents::Feed::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/mingle_events/feed/entry.rb

Overview

A Ruby wrapper around an Atom entry, particularly an Atom entry representing an event in Mingle.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry_element) ⇒ Entry

Construct with the wrapped Xml Elem for the entry



9
10
11
# File 'lib/mingle_events/feed/entry.rb', line 9

def initialize(entry_element)
  @entry_element = entry_element
end

Class Method Details

.from_snippet(entry_xml) ⇒ Object



13
14
15
# File 'lib/mingle_events/feed/entry.rb', line 13

def self.from_snippet(entry_xml)
  self.new(Xml.parse(entry_xml, ATOM_AND_MINGLE_NS).select('/atom:entry'))
end

Instance Method Details

#==(object) ⇒ Object



104
105
106
# File 'lib/mingle_events/feed/entry.rb', line 104

def ==(object)
  eql?(object)
end

#authorObject

The user who created the entry (triggered the event), i.e., changed project data in Mingle



40
41
42
# File 'lib/mingle_events/feed/entry.rb', line 40

def author
  @author ||= Author.new(@entry_element.select("./atom:author"))
end

#card?Boolean

Whether the entry/event was sourced by a Mingle card

Returns:

  • (Boolean)


62
63
64
# File 'lib/mingle_events/feed/entry.rb', line 62

def card?
  categories.any?{|c| c == Category::CARD}
end

#card_numberObject

The number of the card that sourced this entry/event. If the entry is not a card event an error will be thrown. The source of this data is perhaps not so robust and we’ll need to revisit this in the next release of Mingle.



69
70
71
72
# File 'lib/mingle_events/feed/entry.rb', line 69

def card_number
  raise "You cannot get the card number for an event that is not sourced by a card!" unless card?
  @card_number ||= parse_card_number
end

#card_version_resource_uriObject

The resource URI for the card version that was created by this event. Throws error if not card event.



81
82
83
84
# File 'lib/mingle_events/feed/entry.rb', line 81

def card_version_resource_uri
  raise "You cannot get card version data for an event that is not sourced by a card!" unless card?      
  @card_version_resource_uri ||= parse_card_version_resource_uri
end

#categoriesObject

The set of Atom categoies describing the entry



45
46
47
48
49
# File 'lib/mingle_events/feed/entry.rb', line 45

def categories
  @categories ||= @entry_element.select_all("./atom:category").map do |category_element|
    Category.new(category_element.attr("term"), category_element.attr("scheme"))
  end
end

#changesObject

The array of changes for this entry. Each change is a hash with redundant :type and :category entries specifying the category to which the change maps.

Change detail is contained in nested hashes with keys mapping exactly to the XML as described in www.thoughtworks-studios.com/mingle/3.3/help/mingle_api_events.html. The data in the change hashes reflect only what is in the XML as encriching them would require potentially many calls to the Mingle server resulting in very slow processing.



57
58
59
# File 'lib/mingle_events/feed/entry.rb', line 57

def changes
  @changes ||= Changes.new(@entry_element.select("./atom:content/mingle:changes"))
end

#entry_idObject Also known as: event_id

The Atom entry’s id value. This is the one true identifier for the entry, and therefore the event.



24
25
26
# File 'lib/mingle_events/feed/entry.rb', line 24

def entry_id
  @entry_id ||= @entry_element.inner_text("./atom:id")
end

#eql?(object) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
97
98
99
100
101
102
# File 'lib/mingle_events/feed/entry.rb', line 94

def eql?(object)
  if object.equal?(self)
   return true
  elsif !self.class.equal?(object.class)
   return false
  end

  return object.entry_id == entry_id
end


86
87
88
# File 'lib/mingle_events/feed/entry.rb', line 86

def links
  Links.new(@entry_element)
end

#raw_xmlObject

The raw entry XML from the Atom feed



18
19
20
# File 'lib/mingle_events/feed/entry.rb', line 18

def raw_xml
  @raw_xml ||= @entry_element.raw_xml
end

#titleObject

The Atom entry’s title



30
31
32
# File 'lib/mingle_events/feed/entry.rb', line 30

def title
  @title ||= @entry_element.inner_text('./atom:title')
end

#to_sObject



90
91
92
# File 'lib/mingle_events/feed/entry.rb', line 90

def to_s
  "Entry[entry_id=#{entry_id}, updated=#{updated}]"
end

#updatedObject

The time at which entry was created, i.e., the event was triggered



35
36
37
# File 'lib/mingle_events/feed/entry.rb', line 35

def updated
  @updated ||= Time.parse(@entry_element.inner_text("./atom:updated"))
end

#versionObject

The version number of the card or page that was created by this event. (For now, only working with cards.)



76
77
78
# File 'lib/mingle_events/feed/entry.rb', line 76

def version
  @version ||= CGI.parse(URI.parse(card_version_resource_uri).query)["version"].first.to_i
end