mingle_events 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
data/lib/mingle_events/feed.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'feed', 'author'))
|
2
2
|
require File.expand_path(File.join(File.dirname(__FILE__), 'feed', 'category'))
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'feed', 'links'))
|
3
4
|
require File.expand_path(File.join(File.dirname(__FILE__), 'feed', 'entry'))
|
4
5
|
require File.expand_path(File.join(File.dirname(__FILE__), 'feed', 'page'))
|
5
6
|
require File.expand_path(File.join(File.dirname(__FILE__), 'feed', 'changes'))
|
@@ -82,6 +82,10 @@ module MingleEvents
|
|
82
82
|
raise "You cannot get card version data for an event that is not sourced by a card!" unless card?
|
83
83
|
@card_version_resource_uri ||= parse_card_version_resource_uri
|
84
84
|
end
|
85
|
+
|
86
|
+
def links
|
87
|
+
Links.new(@entry_element)
|
88
|
+
end
|
85
89
|
|
86
90
|
def to_s
|
87
91
|
"Entry[entry_id=#{entry_id}, updated=#{updated}]"
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module MingleEvents
|
2
|
+
module Feed
|
3
|
+
|
4
|
+
class Links
|
5
|
+
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
EVENT_SOURCE_REL = "http://www.thoughtworks-studios.com/ns/mingle#event-source"
|
9
|
+
VERSION_REL = "http://www.thoughtworks-studios.com/ns/mingle#version"
|
10
|
+
RELATED_REL = "http://www.thoughtworks-studios.com/ns/mingle#related"
|
11
|
+
|
12
|
+
def initialize(entry_element)
|
13
|
+
@links ||= entry_element.search("link").map do |category_element|
|
14
|
+
Link.new(category_element["href"], category_element["rel"], category_element["type"], category_element["title"])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def find_by_rel_and_type(rel, type)
|
19
|
+
@links.select{|l| l.rel == rel && l.type == type}
|
20
|
+
end
|
21
|
+
|
22
|
+
def each(&block)
|
23
|
+
@links.each{|l| yield l}
|
24
|
+
end
|
25
|
+
|
26
|
+
class Link
|
27
|
+
|
28
|
+
attr_reader :href, :rel, :type, :title
|
29
|
+
|
30
|
+
def initialize(href, rel, type, title)
|
31
|
+
@href = href
|
32
|
+
@rel = rel
|
33
|
+
@type = type
|
34
|
+
@title = title
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -149,6 +149,18 @@ module MingleEvents
|
|
149
149
|
assert entry_2 != entry_3
|
150
150
|
end
|
151
151
|
|
152
|
+
def test_construct_links
|
153
|
+
element_xml_text = %{
|
154
|
+
<entry>
|
155
|
+
<category term="card" scheme="http://www.thoughtworks-studios.com/ns/mingle#categories"/>
|
156
|
+
<link href="https://mingle.example.com/projects/atlas/cards/102" rel="http://www.thoughtworks-studios.com/ns/mingle#event-source" type="text/html" title="bug #103"/>
|
157
|
+
<link href="https://mingle.example.com/api/v2/projects/atlas/cards/104.xml?version=7" rel="http://www.thoughtworks-studios.com/ns/mingle#version" type="application/vnd.mingle+xml" title="bug #105 (v7)"/>
|
158
|
+
</entry>}
|
159
|
+
entry = Entry.from_snippet(element_xml_text)
|
160
|
+
links = entry.links.to_a
|
161
|
+
assert_equal 2, links.count
|
162
|
+
end
|
163
|
+
|
152
164
|
end
|
153
165
|
|
154
166
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
|
2
|
+
|
3
|
+
module MingleEvents
|
4
|
+
module Feed
|
5
|
+
|
6
|
+
class LinksTest < Test::Unit::TestCase
|
7
|
+
def test_parse_links
|
8
|
+
element_xml = %{
|
9
|
+
<entry>
|
10
|
+
<category term="card" scheme="http://www.thoughtworks-studios.com/ns/mingle#categories"/>
|
11
|
+
<link href="https://mingle.example.com/projects/atlas/cards/102" rel="http://www.thoughtworks-studios.com/ns/mingle#event-source" type="text/html" title="bug #103"/>
|
12
|
+
<link href="https://mingle.example.com/api/v2/projects/atlas/cards/104.xml?version=7" rel="http://www.thoughtworks-studios.com/ns/mingle#version" type="application/vnd.mingle+xml" title="bug #105 (v7)"/>
|
13
|
+
</entry>}
|
14
|
+
links = Links.new(Nokogiri::XML(element_xml).remove_namespaces!)
|
15
|
+
assert_equal 2, links.count
|
16
|
+
the_links = links.to_a
|
17
|
+
assert_equal "https://mingle.example.com/projects/atlas/cards/102", the_links.first.href
|
18
|
+
assert_equal "http://www.thoughtworks-studios.com/ns/mingle#event-source", the_links.first.rel
|
19
|
+
assert_equal "text/html", the_links.first.type
|
20
|
+
assert_equal "bug #103", the_links.first.title
|
21
|
+
assert_equal "https://mingle.example.com/api/v2/projects/atlas/cards/104.xml?version=7", the_links.last.href
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_find_by_rel_and_type
|
25
|
+
element_xml = %{
|
26
|
+
<entry>
|
27
|
+
<category term="card" scheme="http://www.thoughtworks-studios.com/ns/mingle#categories"/>
|
28
|
+
<link href="https://mingle.example.com/projects/atlas/cards/102" rel="http://www.thoughtworks-studios.com/ns/mingle#related" type="text/html" title="bug #102"/>
|
29
|
+
<link href="https://mingle.example.com/projects/atlas/cards/104" rel="http://www.thoughtworks-studios.com/ns/mingle#related" type="text/html" title="bug #104"/>
|
30
|
+
<link href="https://mingle.example.com/projects/atlas/cards/104.xml" rel="http://www.thoughtworks-studios.com/ns/mingle#related" type="text/xml" title="bug #104"/>
|
31
|
+
<link href="https://mingle.example.com/api/v2/projects/atlas/cards/104.xml?version=7" rel="http://www.thoughtworks-studios.com/ns/mingle#version" type="application/vnd.mingle+xml" title="bug #105 (v7)"/>
|
32
|
+
</entry>}
|
33
|
+
links = Links.new(Nokogiri::XML(element_xml).remove_namespaces!)
|
34
|
+
assert_equal ["bug #102", "bug #104"], links.find_by_rel_and_type(Links::RELATED_REL, "text/html").map(&:title)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mingle_events
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- David Rice
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- lib/mingle_events/feed/category.rb
|
62
62
|
- lib/mingle_events/feed/changes.rb
|
63
63
|
- lib/mingle_events/feed/entry.rb
|
64
|
+
- lib/mingle_events/feed/links.rb
|
64
65
|
- lib/mingle_events/feed/page.rb
|
65
66
|
- lib/mingle_events/feed.rb
|
66
67
|
- lib/mingle_events/http_error.rb
|
@@ -87,6 +88,7 @@ files:
|
|
87
88
|
- test/mingle_events/feed/category_test.rb
|
88
89
|
- test/mingle_events/feed/changes_test.rb
|
89
90
|
- test/mingle_events/feed/entry_test.rb
|
91
|
+
- test/mingle_events/feed/links_test.rb
|
90
92
|
- test/mingle_events/feed/page_test.rb
|
91
93
|
- test/mingle_events/poller_test.rb
|
92
94
|
- test/mingle_events/processors/author_filter_test.rb
|