discodactyl 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby -w
2
+ libdir = File.expand_path('../../lib', __FILE__)
3
+ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
4
+
5
+ require "test/unit"
6
+ require "discodactyl/uri_template"
7
+
8
+ class TestURITemplate < Test::Unit::TestCase
9
+ def test_render_encode_uri
10
+ t = Discodactyl::URITemplate.new('http://example.org?q={uri}')
11
+ assert_equal('http://example.org?q=http%3A%2F%2Fexample.com%2Fr%3Ff%3D1', t.to_uri('uri' => URI.parse('http://example.com/r?f=1')))
12
+ end
13
+ # from http://tools.ietf.org/html/draft-hammer-hostmeta-05#section-3.2.1
14
+ def test_render_encode
15
+ t = Discodactyl::URITemplate.new('http://example.org?q={uri}')
16
+ assert_equal('http://example.org?q=http%3A%2F%2Fexample.com%2Fr%3Ff%3D1', t.to_uri('uri' => 'http://example.com/r?f=1'))
17
+ end
18
+ def test_render_single
19
+ t = Discodactyl::URITemplate.new('http://host.example/{%id}')
20
+ assert_equal('http://host.example/test', t.to_uri('id' => 'test'))
21
+ end
22
+
23
+ def test_render_many
24
+ t = Discodactyl::URITemplate.new('http://host.example/{%id}/{%name}')
25
+ assert_equal('http://host.example/test/bob', t.to_uri('id' => 'test', 'name' => 'bob'))
26
+ end
27
+
28
+ def test_equivalence
29
+ pattern = 'http://host.example/{%id}'
30
+ assert_equal(Discodactyl::URITemplate.new(pattern), Discodactyl::URITemplate.new(pattern))
31
+ end
32
+ end
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env ruby -w
2
+ libdir = File.expand_path('../../lib', __FILE__)
3
+ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
4
+ testdir = File.expand_path('../../test', __FILE__)
5
+ $LOAD_PATH.unshift(testdir) unless $LOAD_PATH.include?(testdir)
6
+
7
+ require 'test_helper'
8
+ require 'discodactyl/xrd/document'
9
+
10
+ module Discodactyl
11
+ class XRDTestCase < ::Test::Unit::TestCase #:nodoc:
12
+ # Placeholder so test/unit ignores test cases without any tests.
13
+ def default_test
14
+ end
15
+ def setup
16
+ @full_xrd_string =<<eos
17
+ <?xml version=\"1.0\"?>
18
+ <XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
19
+ <Subject>http://host.example/</Subject>
20
+ <Link rel="webfinger" href="http://host.example/endpoint"/>
21
+ <Link rel="describedby" href="http://host.example/endpoint"/>
22
+ <Link rel="feed" template="http://host.example/descriptor?q={%id}"/>
23
+ <Link rel="describedby" template="http://host.example/descriptor?q={%id}"/>
24
+ </XRD>
25
+ eos
26
+
27
+ @xrd = Discodactyl::XRD::Document.parse(@full_xrd_string)
28
+ end
29
+ end
30
+ end
31
+
32
+ class TestXRDAppendWithId < Discodactyl::XRDTestCase
33
+ def setup
34
+ super
35
+ @raw_link = '<Link xml:id="foo" rel="http://oexchange.org/spec/0.8/rel/user-target" type="application/xrd+xml" href="http://www.example.com/linkeater/oexchange.xrd"/>'
36
+ @link = @xrd.append(@raw_link)
37
+ end
38
+
39
+ def test_append_with_id_does_not_overwrite
40
+ assert_equal @raw_link, @link.to_s
41
+ end
42
+
43
+ def test_append_generates_id_on_duplicate
44
+ second = @xrd.append(@raw_link)
45
+ assert_not_equal @link.id, second.id
46
+ end
47
+ end
48
+
49
+ class TestXRDAppendWithoutID < Discodactyl::XRDTestCase
50
+ def setup
51
+ super
52
+ @raw_link = '<Link rel="http://oexchange.org/spec/0.8/rel/user-target" type="application/xrd+xml" href="http://www.example.com/linkeater/oexchange.xrd"/>'
53
+ @link = @xrd.append(@raw_link)
54
+ end
55
+
56
+ def test_inserts_link_in_raw
57
+ assert_include? @link.raw, @xrd.raw.search('//xrd:Link', Discodactyl::XRD::XMLNS)
58
+ end
59
+
60
+ def test_append_preserves_rel
61
+ assert_equal 'http://oexchange.org/spec/0.8/rel/user-target', @link.rel
62
+ end
63
+
64
+ def test_append_preserves_attributes
65
+ assert_equal 'http://oexchange.org/spec/0.8/rel/user-target', @link.rel
66
+ assert_equal 'application/xrd+xml', @link.type
67
+ assert_equal 'http://www.example.com/linkeater/oexchange.xrd', @link.href
68
+ end
69
+
70
+ def test_append_preserves_attributes
71
+ assert_equal 'http://oexchange.org/spec/0.8/rel/user-target', @link.rel
72
+ assert_equal 'application/xrd+xml', @link.type
73
+ assert_equal 'http://www.example.com/linkeater/oexchange.xrd', @link.href
74
+ end
75
+
76
+ def test_inserts_link
77
+ assert_include? @link, @xrd.links
78
+ end
79
+
80
+ def test_generates_id
81
+ assert_not_nil @link.id
82
+ assert !@link.id.empty?
83
+ end
84
+
85
+ def test_can_find_appended_link_by_returned_link_id
86
+ actual = @xrd.find_link_by_id(@link.id)
87
+
88
+ assert_equal 'http://oexchange.org/spec/0.8/rel/user-target', actual.rel
89
+ assert_equal 'application/xrd+xml', actual.type
90
+ assert_equal 'http://www.example.com/linkeater/oexchange.xrd', actual.href
91
+ end
92
+ end
93
+
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env ruby -w
2
+ libdir = File.expand_path('../../lib', __FILE__)
3
+ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
4
+
5
+ require "test/unit"
6
+ require "discodactyl/xrd"
7
+ require "discodactyl/uri_template"
8
+
9
+ class TestXRDLinkParsing < Test::Unit::TestCase
10
+ def test_parse_all
11
+ raw = '<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link rel="lrdd" type="text/html" href="http://host.example" template="http://www.google.com/s2/webfinger/?q={%id}"/></XRD>'
12
+ elem = Nokogiri(raw).xpath('/xrd:XRD/xrd:Link', Discodactyl::XRD::XMLNS).first
13
+
14
+ link = Discodactyl::XRD::Link.parse(elem)
15
+
16
+ assert_equal 'lrdd', link.rel
17
+ assert_equal 'text/html', link.type
18
+ assert_equal 'http://host.example', link.href
19
+ assert_nil link.template
20
+ end
21
+
22
+ def test_parse_empty
23
+ raw = '<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link></Link></XRD>'
24
+ elem = Nokogiri(raw).xpath('/xrd:XRD/xrd:Link', Discodactyl::XRD::XMLNS).first
25
+
26
+ link = Discodactyl::XRD::Link.parse(elem)
27
+
28
+ assert_not_nil(link)
29
+ end
30
+
31
+ def test_parse_rel
32
+ raw = '<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link rel="lrdd"/></XRD>'
33
+ elem = Nokogiri(raw).xpath('/xrd:XRD/xrd:Link', Discodactyl::XRD::XMLNS).first
34
+
35
+ link = Discodactyl::XRD::Link.parse(elem)
36
+
37
+ assert_equal 'lrdd', link.rel
38
+ end
39
+
40
+ def test_parse_type
41
+ raw = '<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link type="text/html"/></XRD>'
42
+ elem = Nokogiri(raw).xpath('/xrd:XRD/xrd:Link', Discodactyl::XRD::XMLNS).first
43
+
44
+ link = Discodactyl::XRD::Link.parse(elem)
45
+
46
+ assert_equal 'text/html', link.type
47
+ end
48
+
49
+ def test_parse_href
50
+ raw = '<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link href="http://host.example"/></XRD>'
51
+ elem = Nokogiri(raw).xpath('/xrd:XRD/xrd:Link', Discodactyl::XRD::XMLNS).first
52
+
53
+ link = Discodactyl::XRD::Link.parse(elem)
54
+
55
+ assert_equal 'http://host.example', link.href
56
+ end
57
+
58
+ def test_parse_template
59
+ raw = '<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link template="http://www.google.com/s2/webfinger/?q={%id}"/></XRD>'
60
+ elem = Nokogiri(raw).xpath('/xrd:XRD/xrd:Link', Discodactyl::XRD::XMLNS).first
61
+
62
+ link = Discodactyl::XRD::Link.parse(elem)
63
+
64
+ assert_equal Discodactyl::URITemplate.new('http://www.google.com/s2/webfinger/?q={%id}'), link.template
65
+ assert_nil link.href
66
+ end
67
+
68
+ def test_ignores_template_when_href_exists
69
+ raw = '<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link rel="lrdd" type="text/html" href="http://host.example" template="http://www.google.com/s2/webfinger/?q={%id}"/></XRD>'
70
+ elem = Nokogiri(raw).xpath('/xrd:XRD/xrd:Link', Discodactyl::XRD::XMLNS).first
71
+
72
+ link = Discodactyl::XRD::Link.parse(elem)
73
+
74
+ assert_equal 'http://host.example', link.href
75
+ assert_nil link.template
76
+ end
77
+
78
+ def test_to_uris_for_plain_uri
79
+ raw = '<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link href="http://host.example"/></XRD>'
80
+ elem = Nokogiri(raw).xpath('/xrd:XRD/xrd:Link', Discodactyl::XRD::XMLNS).first
81
+ link = Discodactyl::XRD::Link.parse(elem)
82
+
83
+ uri = link.to_uri
84
+
85
+ assert_equal 'http://host.example', uri
86
+ end
87
+
88
+ def test_to_uris_for_uri_template
89
+ raw = '<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link template="http://www.google.com/s2/webfinger/?q={%id}"/></XRD>'
90
+ elem = Nokogiri(raw).xpath('/xrd:XRD/xrd:Link', Discodactyl::XRD::XMLNS).first
91
+ link = Discodactyl::XRD::Link.parse(elem)
92
+
93
+ uri = link.to_uri 'id' => 'bob@gmail.com'
94
+
95
+ assert_equal 'http://www.google.com/s2/webfinger/?q=bob@gmail.com', uri
96
+ end
97
+ end
@@ -0,0 +1,146 @@
1
+ #!/usr/bin/env ruby -w
2
+ libdir = File.expand_path('../../lib', __FILE__)
3
+ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
4
+ testdir = File.expand_path('../../test', __FILE__)
5
+ $LOAD_PATH.unshift(testdir) unless $LOAD_PATH.include?(testdir)
6
+
7
+ require 'test_helper'
8
+ require 'discodactyl/xrd/document'
9
+
10
+ class TestXRDParsing < Test::Unit::TestCase
11
+ def setup
12
+ @minimal_xrd_string =<<eos
13
+ <?xml version=\"1.0\"?>
14
+ <XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
15
+ <Subject>http://host.example/</Subject>
16
+ </XRD>
17
+ eos
18
+
19
+ @full_xrd_string =<<eos
20
+ <?xml version=\"1.0\"?>
21
+ <XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
22
+ <Subject>http://host.example/</Subject>
23
+ <Link rel="webfinger" href="http://host.example/endpoint"/>
24
+ <Link rel="describedby" href="http://host.example/endpoint"/>
25
+ <Link rel="feed" template="http://host.example/descriptor?q={%id}"/>
26
+ <Link rel="describedby" template="http://host.example/descriptor?q={%id}"/>
27
+ </XRD>
28
+ eos
29
+
30
+ @raw_link_without_id = '<Link rel="http://oexchange.org/spec/0.8/rel/user-target" type="application/xrd+xml" href="http://www.example.com/linkeater/oexchange.xrd"/>'
31
+ @raw_link_with_id = '<Link xml:id="foo" rel="http://oexchange.org/spec/0.8/rel/user-target" type="application/xrd+xml" href="http://www.example.com/linkeater/oexchange.xrd"/>'
32
+
33
+ @xrd = Discodactyl::XRD::Document.parse(@full_xrd_string)
34
+ end
35
+ def test_parse
36
+ doc = Discodactyl::XRD::Document.parse(@full_xrd_string)
37
+ assert_not_nil(doc)
38
+ end
39
+ def test_parse_links
40
+ assert_equal(4, @xrd.links.length)
41
+ end
42
+
43
+ def test_linkelems_by_rel
44
+ link_elems = @xrd.linkelems_by_rel 'describedby'
45
+
46
+ assert_length(2, link_elems)
47
+
48
+ assert_equal 'http://host.example/endpoint', link_elems[0]['href']
49
+ assert_equal 'http://host.example/descriptor?q={%id}', link_elems[1]['template']
50
+ end
51
+
52
+ def test_linkelems_by_rel_with_multiple_rels
53
+ link_elems = @xrd.linkelems_by_rel 'describedby'
54
+
55
+ assert_length(2, link_elems)
56
+
57
+ assert_equal 'http://host.example/endpoint', link_elems[0]['href']
58
+ assert_equal 'http://host.example/descriptor?q={%id}', link_elems[1]['template']
59
+ end
60
+
61
+ def test_uris_by_rel
62
+ uris = @xrd.uris_by_rel 'describedby', 'id' => 'bradfitz@gmail.com'
63
+
64
+ assert_length(2, uris)
65
+
66
+ assert_equal 'http://host.example/endpoint', uris[0]
67
+ assert_equal 'http://host.example/descriptor?q=bradfitz@gmail.com', uris[1]
68
+ end
69
+
70
+ def test_to_s
71
+ assert_equal @full_xrd_string, @xrd.to_s
72
+ end
73
+
74
+ def test_links_by_rel
75
+ links = @xrd.links_by_rel('feed')
76
+
77
+ assert_length(1, links)
78
+ expected = Discodactyl::URITemplate.new('http://host.example/descriptor?q={%id}')
79
+ assert_equal(expected, links[0].template)
80
+ end
81
+
82
+ def test_uris_by_rel
83
+ links = @xrd.uris_by_rel('feed', 'id' => 'dclinton@gmail.com')
84
+
85
+ assert_length(1, links)
86
+ assert_include?('http://host.example/descriptor?q=dclinton@gmail.com', links)
87
+ end
88
+
89
+ # def test_update
90
+ # xrd_str =<<eos
91
+ # <?xml version=\"1.0\"?>
92
+ # <XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
93
+ # <Subject>http://host.example/</Subject>
94
+ # <Link rel="webfinger" href="http://host.example/endpoint"/>
95
+ # <Link rel="describedby" href="http://host.example/endpoint"/>
96
+ # <Link rel="feed" template="http://host.example/descriptor?q={%id}"/>
97
+ # <Link rel="describedby" template="http://host.example/descriptor?q={%id}"/>
98
+ # <Link href="http://www.example.com/linkeater/oexchange.xrd" rel="http://oexchange.org/spec/0.8/rel/user-target" type="application/xrd+xml"/>
99
+ # </XRD>
100
+ # eos
101
+ # doc = Discodactyl::XRD::Document.parse xrd_str
102
+ #
103
+ # link = "<Link rel='http://oexchange.org/spec/0.8/rel/user-target' type='application/xrd+xml' href='updated' />"
104
+ #
105
+ # doc.raw.xpath('//xrd:Link',Discodactyl::XRD::XMLNS).after(link)
106
+ #
107
+ # expected =<<eos
108
+ # <?xml version=\"1.0\"?>
109
+ # <XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
110
+ # <Subject>http://host.example/</Subject>
111
+ # <Link rel="webfinger" href="http://host.example/endpoint"/>
112
+ # <Link rel="describedby" href="http://host.example/endpoint"/>
113
+ # <Link rel="feed" template="http://host.example/descriptor?q={%id}"/>
114
+ # <Link rel="describedby" template="http://host.example/descriptor?q={%id}"/>
115
+ # <Link href="updated" rel="http://oexchange.org/spec/0.8/rel/user-target" type="application/xrd+xml"/>
116
+ # </XRD>
117
+ # eos
118
+ #
119
+ # assert_equal expected, doc.to_s
120
+ # end
121
+
122
+ # def test_delete
123
+ # xrd_str =<<eos
124
+ # <?xml version=\"1.0\"?>
125
+ # <XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
126
+ # <Subject>http://host.example/</Subject>
127
+ # <Link xml:id='1' href="http://example.com/" rel="user-target" type="application/xrd+xml"/>
128
+ # </XRD>
129
+ # eos
130
+ # doc = Discodactyl::XRD::Document.parse xrd_str
131
+ #
132
+ # link = "<Link rel='http://oexchange.org/spec/0.8/rel/user-target' type='application/xrd+xml' href='updated' />"
133
+ #
134
+ # doc.raw.xpath('//xrd:Link',Discodactyl::XRD::XMLNS).after(link)
135
+ #
136
+ # expected =<<eos
137
+ # <?xml version=\"1.0\"?>
138
+ # <XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
139
+ # <Subject>http://host.example/</Subject>
140
+ # </XRD>
141
+ # eos
142
+ #
143
+ # assert_equal expected, doc.to_s
144
+ # assert !doc.include?(link)
145
+ # end
146
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: discodactyl
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
+ platform: ruby
11
+ authors:
12
+ - Joseph Anthony Pasquale Holsten
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-08 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: nokogiri
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 4
30
+ - 0
31
+ version: 1.4.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: actionpack
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 2
43
+ - 3
44
+ - 0
45
+ version: 2.3.0
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: feedzirra
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ - 0
58
+ - 23
59
+ version: 0.0.23
60
+ type: :runtime
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: mofo
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ - 2
72
+ - 0
73
+ version: 0.2.0
74
+ type: :runtime
75
+ version_requirements: *id004
76
+ description: "Discodactyl is an experimental toolkit for XRD service discovery documents and related protocols. It includes implementations of XRD URITemplate Link-Patterns, basic site-meta support, HTTP Link header parsing, acct: URIs and a webfinger poking stick."
77
+ email: joseph@josephholsten.com
78
+ executables:
79
+ - webfinger
80
+ extensions: []
81
+
82
+ extra_rdoc_files:
83
+ - AUTHORS
84
+ - CHANGELOG
85
+ - COPYING
86
+ - INSTALL
87
+ - NEWS
88
+ - README
89
+ - TODO
90
+ files:
91
+ - AUTHORS
92
+ - CHANGELOG
93
+ - COPYING
94
+ - Gemfile
95
+ - INSTALL
96
+ - MANIFEST
97
+ - NEWS
98
+ - README
99
+ - Rakefile
100
+ - TODO
101
+ - bin/webfinger
102
+ - discodactyl.gemspec
103
+ - lib/discodactyl.rb
104
+ - lib/discodactyl/acct_uri.rb
105
+ - lib/discodactyl/host_meta.rb
106
+ - lib/discodactyl/link_header.rb
107
+ - lib/discodactyl/resource_discovery.rb
108
+ - lib/discodactyl/uri_template.rb
109
+ - lib/discodactyl/xrd.rb
110
+ - lib/discodactyl/xrd/document.rb
111
+ - lib/discodactyl/xrd/link.rb
112
+ - test/test_acct_uri.rb
113
+ - test/test_helper.rb
114
+ - test/test_host_meta.rb
115
+ - test/test_link_header.rb
116
+ - test/test_resource_discovery.rb
117
+ - test/test_uri_template.rb
118
+ - test/test_xrd_append.rb
119
+ - test/test_xrd_link_parse.rb
120
+ - test/test_xrd_parse.rb
121
+ has_rdoc: true
122
+ homepage: http://dactylo.us
123
+ licenses: []
124
+
125
+ post_install_message:
126
+ rdoc_options:
127
+ - --charset=UTF-8
128
+ - --title
129
+ - Discodactyl Documentation
130
+ - --main
131
+ - README
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ segments:
139
+ - 0
140
+ version: "0"
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ segments:
146
+ - 0
147
+ version: "0"
148
+ requirements: []
149
+
150
+ rubyforge_project:
151
+ rubygems_version: 1.3.6
152
+ signing_key:
153
+ specification_version: 3
154
+ summary: Discodactyl is an experimental toolkit for XRD service discovery documents and related protocols
155
+ test_files:
156
+ - test/test_acct_uri.rb
157
+ - test/test_helper.rb
158
+ - test/test_host_meta.rb
159
+ - test/test_link_header.rb
160
+ - test/test_resource_discovery.rb
161
+ - test/test_uri_template.rb
162
+ - test/test_xrd_append.rb
163
+ - test/test_xrd_link_parse.rb
164
+ - test/test_xrd_parse.rb