class MingleEvents::Feed::Entry

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

Public Class Methods

from_snippet(entry_xml) click to toggle source
   # File lib/mingle_events/feed/entry.rb
13 def self.from_snippet(entry_xml)
14   self.new(Xml.parse(entry_xml, ATOM_AND_MINGLE_NS).select('/atom:entry'))
15 end
new(entry_element) click to toggle source

Construct with the wrapped Xml Elem for the entry

   # File lib/mingle_events/feed/entry.rb
 9 def initialize(entry_element)
10   @entry_element = entry_element
11 end

Public Instance Methods

==(object) click to toggle source
    # File lib/mingle_events/feed/entry.rb
104 def ==(object)
105   eql?(object)
106 end
author() click to toggle source

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

   # File lib/mingle_events/feed/entry.rb
40 def author
41   @author ||= Author.new(@entry_element.select("./atom:author"))
42 end
card?() click to toggle source

Whether the entry/event was sourced by a Mingle card

   # File lib/mingle_events/feed/entry.rb
62 def card?
63   categories.any?{|c| c == Category::CARD}
64 end
card_number() click to toggle source

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.

   # File lib/mingle_events/feed/entry.rb
69 def card_number
70   raise "You cannot get the card number for an event that is not sourced by a card!" unless card?
71   @card_number ||= parse_card_number
72 end
card_version_resource_uri() click to toggle source

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

   # File lib/mingle_events/feed/entry.rb
81 def card_version_resource_uri
82   raise "You cannot get card version data for an event that is not sourced by a card!" unless card?      
83   @card_version_resource_uri ||= parse_card_version_resource_uri
84 end
categories() click to toggle source

The set of Atom categoies describing the entry

   # File lib/mingle_events/feed/entry.rb
45 def categories
46   @categories ||= @entry_element.select_all("./atom:category").map do |category_element|
47     Category.new(category_element.attr("term"), category_element.attr("scheme"))
48   end
49 end
changes() click to toggle source

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.

   # File lib/mingle_events/feed/entry.rb
57 def changes
58   @changes ||= Changes.new(@entry_element.select("./atom:content/mingle:changes"))
59 end
entry_id() click to toggle source

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

   # File lib/mingle_events/feed/entry.rb
24 def entry_id
25   @entry_id ||= @entry_element.inner_text("./atom:id")
26 end
Also aliased as: event_id
eql?(object) click to toggle source
    # File lib/mingle_events/feed/entry.rb
 94 def eql?(object)
 95   if object.equal?(self)
 96    return true
 97   elsif !self.class.equal?(object.class)
 98    return false
 99   end
100 
101   return object.entry_id == entry_id
102 end
event_id()
Alias for: entry_id
raw_xml() click to toggle source

The raw entry XML from the Atom feed

   # File lib/mingle_events/feed/entry.rb
18 def raw_xml
19   @raw_xml ||= @entry_element.raw_xml
20 end
title() click to toggle source

The Atom entry’s title

   # File lib/mingle_events/feed/entry.rb
30 def title
31   @title ||= @entry_element.inner_text('./atom:title')
32 end
to_s() click to toggle source
   # File lib/mingle_events/feed/entry.rb
90 def to_s
91   "Entry[entry_id=#{entry_id}, updated=#{updated}]"
92 end
updated() click to toggle source

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

   # File lib/mingle_events/feed/entry.rb
35 def updated
36   @updated ||= Time.parse(@entry_element.inner_text("./atom:updated"))
37 end
version() click to toggle source

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

   # File lib/mingle_events/feed/entry.rb
76 def version
77   @version ||= CGI.parse(URI.parse(card_version_resource_uri).query)["version"].first.to_i
78 end

Private Instance Methods

parse_card_number() click to toggle source
    # File lib/mingle_events/feed/entry.rb
110 def parse_card_number
111   card_number_element = @entry_element.select("./atom:link[@rel='http://www.thoughtworks-studios.com/ns/mingle#event-source'][@type='application/vnd.mingle+xml']")
112   # TODO: improve this bit of parsing :)
113   card_number_element.attr("href").split('/').last.split('.')[0..-2].join.to_i
114 end
parse_card_version_resource_uri() click to toggle source
    # File lib/mingle_events/feed/entry.rb
116 def parse_card_version_resource_uri
117   card_number_element = @entry_element.select("./atom:link[@rel='http://www.thoughtworks-studios.com/ns/mingle#version'][@type='application/vnd.mingle+xml']")
118   card_number_element.attr("href")
119 end