redfinger 0.0.5 → 0.0.6
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.
- data/VERSION +1 -1
- data/lib/redfinger/client.rb +16 -10
- data/lib/redfinger/finger.rb +2 -2
- data/redfinger.gemspec +4 -4
- data/spec/redfinger/client_spec.rb +2 -11
- data/spec/spec_helper.rb +3 -8
- metadata +19 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/lib/redfinger/client.rb
CHANGED
@@ -7,13 +7,17 @@ module Redfinger
|
|
7
7
|
attr_accessor :account, :domain, :uri_template
|
8
8
|
|
9
9
|
def initialize(email, uri_template = nil)
|
10
|
-
self.account =
|
10
|
+
self.account = normalize(email)
|
11
11
|
self.domain = account.split('@').last
|
12
12
|
end
|
13
13
|
|
14
14
|
def finger
|
15
15
|
self.uri_template ||= retrieve_template_from_xrd
|
16
|
-
|
16
|
+
begin
|
17
|
+
return Finger.new self.account, RestClient.get(swizzle).body
|
18
|
+
rescue RestClient::ResourceNotFound
|
19
|
+
return Finger.new self.account, RestClient.get(swizzle(account_with_scheme)).body
|
20
|
+
end
|
17
21
|
end
|
18
22
|
|
19
23
|
def xrd_url(ssl = true)
|
@@ -22,21 +26,19 @@ module Redfinger
|
|
22
26
|
|
23
27
|
private
|
24
28
|
|
25
|
-
def swizzle
|
29
|
+
def swizzle(account = nil)
|
30
|
+
account ||= self.account
|
26
31
|
uri_template.gsub '{uri}', URI.escape(self.account)
|
27
32
|
end
|
28
33
|
|
29
34
|
def retrieve_template_from_xrd(ssl = true)
|
30
35
|
doc = Nokogiri::XML::Document.parse(RestClient.get(xrd_url(ssl)).body)
|
31
|
-
if doc.namespaces["xmlns
|
36
|
+
if doc.namespaces["xmlns"] != "http://docs.oasis-open.org/ns/xri/xrd-1.0"
|
32
37
|
# it's probably not finger, let's try without ssl
|
33
38
|
# http://code.google.com/p/webfinger/wiki/WebFingerProtocol
|
34
39
|
# says first ssl should be tried then without ssl, should fix issue #2
|
35
40
|
doc = Nokogiri::XML::Document.parse(RestClient.get(xrd_url(false)).body)
|
36
41
|
end
|
37
|
-
unless doc.at_xpath('.//hm:Host').content == self.domain
|
38
|
-
raise Redfinger::SecurityException, "The XRD document's host did not match the account's host."
|
39
|
-
end
|
40
42
|
|
41
43
|
doc.at('Link[rel=lrdd]').attribute('template').value
|
42
44
|
rescue Errno::ECONNREFUSED, RestClient::ResourceNotFound
|
@@ -47,9 +49,13 @@ module Redfinger
|
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
50
|
-
def
|
51
|
-
email
|
52
|
-
email
|
52
|
+
def normalize(email)
|
53
|
+
email.sub! /^acct:/, ''
|
54
|
+
email.downcase
|
55
|
+
end
|
56
|
+
|
57
|
+
def account_with_scheme
|
58
|
+
"acct:" + account
|
53
59
|
end
|
54
60
|
end
|
55
61
|
end
|
data/lib/redfinger/finger.rb
CHANGED
@@ -5,9 +5,9 @@ module Redfinger
|
|
5
5
|
# special helpers that are availale to pull specific types
|
6
6
|
# of URLs, see Redfinger::LinkHelpers
|
7
7
|
class Finger
|
8
|
-
def initialize(xml) # :nodoc:
|
8
|
+
def initialize(subject, xml) # :nodoc:
|
9
9
|
@doc = Nokogiri::XML::Document.parse(xml)
|
10
|
-
@subject =
|
10
|
+
@subject = subject
|
11
11
|
end
|
12
12
|
|
13
13
|
# All of the links provided by the Webfinger response.
|
data/redfinger.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{redfinger}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Bleigh"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-08-10}
|
13
13
|
s.description = %q{A Ruby Webfinger client}
|
14
14
|
s.email = %q{michael@intridea.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -37,7 +37,7 @@ Gem::Specification.new do |s|
|
|
37
37
|
s.homepage = %q{http://github.com/mbleigh/redfinger}
|
38
38
|
s.rdoc_options = ["--charset=UTF-8"]
|
39
39
|
s.require_paths = ["lib"]
|
40
|
-
s.rubygems_version = %q{1.3.
|
40
|
+
s.rubygems_version = %q{1.3.7}
|
41
41
|
s.summary = %q{A Ruby WebFinger client.}
|
42
42
|
s.test_files = [
|
43
43
|
"spec/redfinger/client_spec.rb",
|
@@ -49,7 +49,7 @@ Gem::Specification.new do |s|
|
|
49
49
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
50
50
|
s.specification_version = 3
|
51
51
|
|
52
|
-
if Gem::Version.new(Gem::
|
52
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
53
53
|
s.add_runtime_dependency(%q<rest-client>, [">= 1.5.0"])
|
54
54
|
s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.0"])
|
55
55
|
s.add_runtime_dependency(%q<hashie>, [">= 0"])
|
@@ -4,12 +4,8 @@ class HaltSuccessError < StandardError; end
|
|
4
4
|
|
5
5
|
describe Redfinger::Client do
|
6
6
|
describe '#new' do
|
7
|
-
it 'should
|
8
|
-
Redfinger::Client.new('abc@example.com').account.should == '
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'should not add acct: if it is already in URI form' do
|
12
|
-
Redfinger::Client.new('acct:abc@example.com').account.should == 'acct:abc@example.com'
|
7
|
+
it 'should remove acct: if it is already in URI form' do
|
8
|
+
Redfinger::Client.new('acct:abc@example.com').account.should == 'abc@example.com'
|
13
9
|
end
|
14
10
|
|
15
11
|
it 'should set the domain to whatevers after the @ sign' do
|
@@ -45,11 +41,6 @@ describe Redfinger::Client do
|
|
45
41
|
stub_request(:get, 'https://example.com/.well-known/host-meta').to_return(:status => 200, :body => host_xrd)
|
46
42
|
Redfinger::Client.new('acct:abc@example.com').send(:retrieve_template_from_xrd).should == 'http://example.com/webfinger/?q={uri}'
|
47
43
|
end
|
48
|
-
|
49
|
-
it 'should raise a SecurityException if there is a host mismatch' do
|
50
|
-
stub_request(:get, 'https://franklin.com/.well-known/host-meta').to_return(:status => 200, :body => host_xrd)
|
51
|
-
lambda{Redfinger::Client.new('acct:abc@franklin.com').send(:retrieve_template_from_xrd)}.should raise_error(Redfinger::SecurityException)
|
52
|
-
end
|
53
44
|
end
|
54
45
|
|
55
46
|
describe '#finger' do
|
data/spec/spec_helper.rb
CHANGED
@@ -12,11 +12,7 @@ include WebMock
|
|
12
12
|
def host_xrd
|
13
13
|
<<-XML
|
14
14
|
<?xml version='1.0' encoding='UTF-8'?>
|
15
|
-
|
16
|
-
<!-- Please follow the list at http://groups.google.com/group/webfinger -->
|
17
|
-
<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'
|
18
|
-
xmlns:hm='http://host-meta.net/xrd/1.0'>
|
19
|
-
<hm:Host xmlns='http://host-meta.net/xrd/1.0'>example.com</hm:Host>
|
15
|
+
<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>
|
20
16
|
<Link rel='lrdd'
|
21
17
|
template='http://example.com/webfinger/?q={uri}'>
|
22
18
|
<Title>Resource Descriptor</Title>
|
@@ -29,7 +25,6 @@ def finger_xrd
|
|
29
25
|
<<-XML
|
30
26
|
<?xml version='1.0'?>
|
31
27
|
<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>
|
32
|
-
<Subject>acct:abc@example.com</Subject>
|
33
28
|
<Alias>http://www.google.com/profiles/abc</Alias>
|
34
29
|
<Link rel='http://portablecontacts.net/spec/1.0' href='http://www-opensocial.googleusercontent.com/api/people/'/>
|
35
30
|
<Link rel='http://webfinger.net/rel/profile-page' href='http://www.google.com/profiles/abc' type='text/html'/>
|
@@ -43,9 +38,9 @@ def finger_xrd
|
|
43
38
|
XML
|
44
39
|
end
|
45
40
|
|
46
|
-
def stub_success
|
41
|
+
def stub_success(address = 'abc@example.com')
|
47
42
|
stub_request(:get, 'https://example.com/.well-known/host-meta').to_return(:status => 200, :body => host_xrd)
|
48
|
-
stub_request(:get, /webfinger\/\?q
|
43
|
+
stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 200, :body => finger_xrd)
|
49
44
|
end
|
50
45
|
|
51
46
|
Spec::Runner.configure do |config|
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redfinger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Michael Bleigh
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-08-10 00:00:00 -05:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: rest-client
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
27
30
|
segments:
|
28
31
|
- 1
|
29
32
|
- 5
|
@@ -35,9 +38,11 @@ dependencies:
|
|
35
38
|
name: nokogiri
|
36
39
|
prerelease: false
|
37
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
38
42
|
requirements:
|
39
43
|
- - ">="
|
40
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 7
|
41
46
|
segments:
|
42
47
|
- 1
|
43
48
|
- 4
|
@@ -49,9 +54,11 @@ dependencies:
|
|
49
54
|
name: hashie
|
50
55
|
prerelease: false
|
51
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
52
58
|
requirements:
|
53
59
|
- - ">="
|
54
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
55
62
|
segments:
|
56
63
|
- 0
|
57
64
|
version: "0"
|
@@ -61,9 +68,11 @@ dependencies:
|
|
61
68
|
name: rspec
|
62
69
|
prerelease: false
|
63
70
|
requirement: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
64
72
|
requirements:
|
65
73
|
- - ">="
|
66
74
|
- !ruby/object:Gem::Version
|
75
|
+
hash: 13
|
67
76
|
segments:
|
68
77
|
- 1
|
69
78
|
- 2
|
@@ -75,9 +84,11 @@ dependencies:
|
|
75
84
|
name: webmock
|
76
85
|
prerelease: false
|
77
86
|
requirement: &id005 !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
78
88
|
requirements:
|
79
89
|
- - ">="
|
80
90
|
- !ruby/object:Gem::Version
|
91
|
+
hash: 3
|
81
92
|
segments:
|
82
93
|
- 0
|
83
94
|
version: "0"
|
@@ -119,23 +130,27 @@ rdoc_options:
|
|
119
130
|
require_paths:
|
120
131
|
- lib
|
121
132
|
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
122
134
|
requirements:
|
123
135
|
- - ">="
|
124
136
|
- !ruby/object:Gem::Version
|
137
|
+
hash: 3
|
125
138
|
segments:
|
126
139
|
- 0
|
127
140
|
version: "0"
|
128
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
none: false
|
129
143
|
requirements:
|
130
144
|
- - ">="
|
131
145
|
- !ruby/object:Gem::Version
|
146
|
+
hash: 3
|
132
147
|
segments:
|
133
148
|
- 0
|
134
149
|
version: "0"
|
135
150
|
requirements: []
|
136
151
|
|
137
152
|
rubyforge_project:
|
138
|
-
rubygems_version: 1.3.
|
153
|
+
rubygems_version: 1.3.7
|
139
154
|
signing_key:
|
140
155
|
specification_version: 3
|
141
156
|
summary: A Ruby WebFinger client.
|