em-redfinger 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -0
- data/LICENSE +20 -0
- data/README.md +83 -0
- data/Rakefile +31 -0
- data/VERSION +1 -0
- data/em-redfinger.gemspec +63 -0
- data/lib/em-redfinger.rb +26 -0
- data/lib/em-redfinger/client.rb +82 -0
- data/lib/em-redfinger/finger.rb +26 -0
- data/lib/em-redfinger/link.rb +22 -0
- data/lib/em-redfinger/link_helpers.rb +33 -0
- data/redfinger.gemspec +65 -0
- data/spec/redfinger/client_spec.rb +85 -0
- data/spec/redfinger_spec.rb +10 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +48 -0
- metadata +107 -0
data/.rspec
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Intridea, Inc. and Michael Bleigh
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
EM-Redfinger
|
2
|
+
============
|
3
|
+
|
4
|
+
This library is an exeperimental EventMachine version of the simple
|
5
|
+
[redfinger](https://github.com/intridea/redfinger) ruby lib. The logic
|
6
|
+
is *exactly* the same as I've just changed HTTP calls to no use
|
7
|
+
rest-client, and hooked a bunch of callback here and there.
|
8
|
+
|
9
|
+
EM::Redfinger is a simple Ruby library built to consume the Webfinger
|
10
|
+
protocol using EventMachine. It's simple!
|
11
|
+
|
12
|
+
For more information about Webfinger, see:
|
13
|
+
|
14
|
+
* http://hueniverse.com/2009/08/introducing-webfinger/
|
15
|
+
* http://code.google.com/p/webfinger/
|
16
|
+
|
17
|
+
Installation
|
18
|
+
------------
|
19
|
+
|
20
|
+
EM-Redfinger is a gem:
|
21
|
+
|
22
|
+
gem install em-redfinger
|
23
|
+
|
24
|
+
Usage
|
25
|
+
-----
|
26
|
+
|
27
|
+
Just call it with an e-mail address of a domain that provides the Webfinger protocol:
|
28
|
+
|
29
|
+
~~~~~ ruby
|
30
|
+
require 'em-redfinger'
|
31
|
+
|
32
|
+
EM::Redfinger.finger('youraccount@joindiaspora.com') do |finger|
|
33
|
+
# ...
|
34
|
+
end
|
35
|
+
~~~~~
|
36
|
+
|
37
|
+
From there, you have access to the links provided in the response as
|
38
|
+
well as some shortcuts for common uses:
|
39
|
+
|
40
|
+
~~~~~ ruby
|
41
|
+
Redfinger.finger('youraccount@joindiaspora.com') do |finger|
|
42
|
+
finger.hcard.first.to_s # => "https://joindiaspora.com/hcard/users/you"
|
43
|
+
end
|
44
|
+
~~~~~
|
45
|
+
|
46
|
+
Links are simple hash based objects that store the 'rel' URI (such as
|
47
|
+
that for hCard, OpenID, etc.), the 'href' (the actual destination URI),
|
48
|
+
and the content type if specified. Note you can also just use `#to_s` on
|
49
|
+
a link to get the destination URI.
|
50
|
+
|
51
|
+
So how can you use Webfinger to your advantage? Let's take the example
|
52
|
+
of hCard. If you install the `mofo` library you can do this:
|
53
|
+
|
54
|
+
~~~~~ ruby
|
55
|
+
require 'mofo'
|
56
|
+
require 'em-redfinger'
|
57
|
+
|
58
|
+
EM::Redfinger.finger('example@joindiaspora.com') do |finger|
|
59
|
+
hcard_uri = finger.hcard.first.to_s
|
60
|
+
hcard = hCard.find(hcard_uri)
|
61
|
+
hcard.fn # => "Example Guy"
|
62
|
+
hcard.title # => "Title guy gave himself on Google profile"
|
63
|
+
end
|
64
|
+
~~~~~
|
65
|
+
|
66
|
+
Note that the Webfinger protocol is still in its alpha/infancy and there
|
67
|
+
will likely be many changes as time progresses. This library will do
|
68
|
+
its best to stay up-to-date and current with these changes over time.
|
69
|
+
|
70
|
+
Note on Patches/Pull Requests
|
71
|
+
-----------------------------
|
72
|
+
|
73
|
+
* Fork the project.
|
74
|
+
* Make your feature addition or bug fix.
|
75
|
+
* Add tests for it. This is important so I don't break it in a
|
76
|
+
future version unintentionally.
|
77
|
+
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
78
|
+
* Send me a pull request. Bonus points for topic branches.
|
79
|
+
|
80
|
+
Copyright
|
81
|
+
---------
|
82
|
+
|
83
|
+
Copyright (c) 2011 Intridea, Inc. and Michael Bleigh. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "em-redfinger"
|
8
|
+
gem.summary = %Q{A Ruby WebFinger client.}
|
9
|
+
gem.description = %Q{A Ruby Webfinger client}
|
10
|
+
gem.email = "oz@cyprio.net"
|
11
|
+
gem.homepage = "http://github.com/oz/em-redfinger"
|
12
|
+
gem.authors = ["Michael Bleigh", "Arnaud Berthomier"]
|
13
|
+
gem.add_dependency(%q<em-http-request>, ">= 1.0.0")
|
14
|
+
gem.add_dependency(%q<em-http-request>, ">= 1.0.0")
|
15
|
+
gem.add_dependency "nokogiri", ">= 1.4.0"
|
16
|
+
gem.add_dependency "hashie"
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rspec/core/rake_task'
|
24
|
+
RSpec::Core::RakeTask.new(:spec)
|
25
|
+
|
26
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
27
|
+
spec.rcov = true
|
28
|
+
end
|
29
|
+
|
30
|
+
task :spec => :check_dependencies
|
31
|
+
task :default => :spec
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "em-redfinger"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Michael Bleigh", "Arnaud Berthomier"]
|
12
|
+
s.date = "2011-11-10"
|
13
|
+
s.description = "A Ruby Webfinger client"
|
14
|
+
s.email = "oz@cyprio.net"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".rspec",
|
21
|
+
"LICENSE",
|
22
|
+
"README.md",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"em-redfinger.gemspec",
|
26
|
+
"lib/em-redfinger.rb",
|
27
|
+
"lib/em-redfinger/client.rb",
|
28
|
+
"lib/em-redfinger/finger.rb",
|
29
|
+
"lib/em-redfinger/link.rb",
|
30
|
+
"lib/em-redfinger/link_helpers.rb",
|
31
|
+
"redfinger.gemspec",
|
32
|
+
"spec/redfinger/client_spec.rb",
|
33
|
+
"spec/redfinger_spec.rb",
|
34
|
+
"spec/spec.opts",
|
35
|
+
"spec/spec_helper.rb"
|
36
|
+
]
|
37
|
+
s.homepage = "http://github.com/oz/em-redfinger"
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = "1.8.10"
|
40
|
+
s.summary = "A Ruby WebFinger client."
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_runtime_dependency(%q<em-http-request>, [">= 1.0.0"])
|
47
|
+
s.add_runtime_dependency(%q<em-http-request>, [">= 1.0.0"])
|
48
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.0"])
|
49
|
+
s.add_runtime_dependency(%q<hashie>, [">= 0"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<em-http-request>, [">= 1.0.0"])
|
52
|
+
s.add_dependency(%q<em-http-request>, [">= 1.0.0"])
|
53
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.0"])
|
54
|
+
s.add_dependency(%q<hashie>, [">= 0"])
|
55
|
+
end
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<em-http-request>, [">= 1.0.0"])
|
58
|
+
s.add_dependency(%q<em-http-request>, [">= 1.0.0"])
|
59
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.0"])
|
60
|
+
s.add_dependency(%q<hashie>, [">= 0"])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
data/lib/em-redfinger.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'eventmachine'
|
2
|
+
require 'em-http'
|
3
|
+
|
4
|
+
require 'em-redfinger/link_helpers'
|
5
|
+
require 'em-redfinger/link'
|
6
|
+
require 'em-redfinger/finger'
|
7
|
+
require 'em-redfinger/client'
|
8
|
+
|
9
|
+
module EventMachine
|
10
|
+
module Redfinger
|
11
|
+
class ResourceNotFound < StandardError; end
|
12
|
+
# A SecurityException occurs when something in the
|
13
|
+
# webfinger process does not appear safe, such as
|
14
|
+
# mismatched domains or an unverified XRD signature.
|
15
|
+
class SecurityException < StandardError; end
|
16
|
+
|
17
|
+
# There's no LRDD template attribute available in the requested
|
18
|
+
# account.
|
19
|
+
class NoLRDDTemplate < StandardError; end
|
20
|
+
|
21
|
+
# Finger the provided e-mail address.
|
22
|
+
def self.finger(email)
|
23
|
+
EM::Redfinger::Client.new(email).finger { |finger| yield finger }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'em-http-request'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module EM
|
6
|
+
module Redfinger
|
7
|
+
class Client
|
8
|
+
attr_accessor :account, :domain, :uri_template, :xrd_timeout, :xrd_open_timeout
|
9
|
+
|
10
|
+
def initialize(email, uri_template = nil)
|
11
|
+
self.account = normalize(email)
|
12
|
+
self.domain = account.split('@').last
|
13
|
+
self.xrd_timeout = 10
|
14
|
+
self.xrd_open_timeout = 5
|
15
|
+
end
|
16
|
+
|
17
|
+
def finger
|
18
|
+
retrieve_template_from_xrd do
|
19
|
+
url = swizzle
|
20
|
+
tries = 0
|
21
|
+
begin
|
22
|
+
tries += 1
|
23
|
+
http = EM::HttpRequest.new(url).get
|
24
|
+
http.callback {
|
25
|
+
raise Redfinger::ResourceNotFound if http.response_header.status == 404
|
26
|
+
yield Finger.new self.account, http.response
|
27
|
+
}
|
28
|
+
rescue Redfinger::ResourceNotFound
|
29
|
+
url = swizzle(account_with_scheme)
|
30
|
+
retry if tries < 2
|
31
|
+
raise Redfinger::ResourceNotFound
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def xrd_url(ssl = true)
|
37
|
+
"http#{ 's' if ssl }://#{ domain }/.well-known/host-meta"
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def swizzle(account = nil)
|
43
|
+
retrieve_template_from_xrd { |uri_template|
|
44
|
+
account ||= self.account
|
45
|
+
uri_template.gsub '{uri}', URI.escape(self.account)
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def retrieve_template_from_xrd(ssl = true, &block)
|
50
|
+
return yield(self.uri_template) if self.uri_template
|
51
|
+
|
52
|
+
http = EM::HttpRequest.new(xrd_url(ssl),
|
53
|
+
:connect_timeout => self.xrd_open_timeout,
|
54
|
+
:inactivity_timeout => self.xrd_timeout
|
55
|
+
).get
|
56
|
+
http.callback {
|
57
|
+
if http.response_header.status != 200
|
58
|
+
raise Redfinger::ResourceNotFound, 'Unable to find the host XRD file.'
|
59
|
+
end
|
60
|
+
doc = Nokogiri::XML::Document.parse(http.response)
|
61
|
+
lrdd = doc.at('Link[rel=lrdd]')
|
62
|
+
raise Redfinger::NoLRDDTemplate if lrdd.nil?
|
63
|
+
|
64
|
+
self.uri_template = lrdd.attribute('template').value
|
65
|
+
yield self.uri_template
|
66
|
+
}
|
67
|
+
http.errback {
|
68
|
+
raise Redfinger::ResourceNotFound, 'Unable to find the host XRD file.'
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
def normalize(email)
|
73
|
+
email.sub! /^acct:/, ''
|
74
|
+
email.downcase
|
75
|
+
end
|
76
|
+
|
77
|
+
def account_with_scheme
|
78
|
+
'acct:' + account
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module EM
|
4
|
+
module Redfinger
|
5
|
+
# The result of a Webfinger. For more information about
|
6
|
+
# special helpers that are availale to pull specific types
|
7
|
+
# of URLs, see Redfinger::LinkHelpers
|
8
|
+
class Finger
|
9
|
+
def initialize(subject, xml) # :nodoc:
|
10
|
+
@doc = Nokogiri::XML::Document.parse(xml)
|
11
|
+
@subject = subject
|
12
|
+
end
|
13
|
+
|
14
|
+
# All of the links provided by the Webfinger response.
|
15
|
+
def links
|
16
|
+
@links ||= @doc.css('Link').map{|l| Link.from_xml(l)}
|
17
|
+
end
|
18
|
+
|
19
|
+
def inspect # :nodoc:
|
20
|
+
"<#Redfinger::Finger subject=\"#{@subject}\">"
|
21
|
+
end
|
22
|
+
|
23
|
+
include Redfinger::LinkHelpers
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'hashie'
|
3
|
+
|
4
|
+
module EM
|
5
|
+
module Redfinger
|
6
|
+
class Link < Hashie::Mash
|
7
|
+
def self.from_xml(xml_link)
|
8
|
+
new_link = Link.new
|
9
|
+
new_link[:rel] = xml_link['rel']
|
10
|
+
new_link[:href] = xml_link['href']
|
11
|
+
new_link[:type] = xml_link['type']
|
12
|
+
new_link
|
13
|
+
end
|
14
|
+
|
15
|
+
# Outputs the URL of the link, useful for using
|
16
|
+
# a Link directly in other libraries.
|
17
|
+
def to_s
|
18
|
+
self.href
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module EM
|
4
|
+
module Redfinger
|
5
|
+
module LinkHelpers
|
6
|
+
# An array of links with hCard information about this e-mail address.
|
7
|
+
def hcard
|
8
|
+
relmap('http://microformats.org/profile/hcard')
|
9
|
+
end
|
10
|
+
|
11
|
+
# An array of links of OpenID providers for this e-mail address.
|
12
|
+
def open_id
|
13
|
+
relmap('http://specs.openid.net/auth/', true)
|
14
|
+
end
|
15
|
+
|
16
|
+
# An array of links to profile pages belonging to this e-mail address.
|
17
|
+
def profile_page
|
18
|
+
relmap('http://webfinger.net/rel/profile-page')
|
19
|
+
end
|
20
|
+
|
21
|
+
# An array of links to XFN compatible URLs for this e-mail address.
|
22
|
+
def xfn
|
23
|
+
relmap('http://gmpg.org/xfn/', true)
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def relmap(uri, substring=false)
|
29
|
+
@doc.css("Link[rel#{'^' if substring}=\"#{uri}\"]").map{|e| Link.from_xml(e)}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/redfinger.gemspec
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "redfinger"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Michael Bleigh"]
|
12
|
+
s.date = "2011-11-10"
|
13
|
+
s.description = "A Ruby Webfinger client"
|
14
|
+
s.email = "michael@intridea.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".rspec",
|
21
|
+
"LICENSE",
|
22
|
+
"README.md",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"em-redfinger.gemspec",
|
26
|
+
"lib/em-redfinger.rb",
|
27
|
+
"lib/em-redfinger/client.rb",
|
28
|
+
"lib/em-redfinger/finger.rb",
|
29
|
+
"lib/em-redfinger/link.rb",
|
30
|
+
"lib/em-redfinger/link_helpers.rb",
|
31
|
+
"spec/redfinger/client_spec.rb",
|
32
|
+
"spec/redfinger_spec.rb",
|
33
|
+
"spec/spec.opts",
|
34
|
+
"spec/spec_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = "http://github.com/mbleigh/redfinger"
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = "1.8.10"
|
39
|
+
s.summary = "A Ruby WebFinger client."
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_runtime_dependency(%q<rest-client>, [">= 1.5.0"])
|
46
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.0"])
|
47
|
+
s.add_runtime_dependency(%q<hashie>, [">= 0"])
|
48
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
49
|
+
s.add_development_dependency(%q<webmock>, [">= 0"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<rest-client>, [">= 1.5.0"])
|
52
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.0"])
|
53
|
+
s.add_dependency(%q<hashie>, [">= 0"])
|
54
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
55
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
56
|
+
end
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<rest-client>, [">= 1.5.0"])
|
59
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.0"])
|
60
|
+
s.add_dependency(%q<hashie>, [">= 0"])
|
61
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
62
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
class HaltSuccessError < StandardError; end
|
4
|
+
|
5
|
+
describe Redfinger::Client do
|
6
|
+
describe '#new' do
|
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'
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should set the domain to whatevers after the @ sign' do
|
12
|
+
Redfinger::Client.new('abc@example.com').domain.should == 'example.com'
|
13
|
+
Redfinger::Client.new('abc@frog.co.uk').domain.should == 'frog.co.uk'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#retrieve_template_from_xrd' do
|
18
|
+
it 'should make an SSL request to get the host XRD document' do
|
19
|
+
stub_request(:get, 'https://example.com/.well-known/host-meta').to_raise(HaltSuccessError)
|
20
|
+
lambda{Redfinger::Client.new('acct:abc@example.com').send(:retrieve_template_from_xrd)}.should raise_error(HaltSuccessError)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should make an HTTP request if HTTPS cannot connect' do
|
24
|
+
stub_request(:get, 'https://example.com/.well-known/host-meta').to_raise(Errno::ECONNREFUSED)
|
25
|
+
stub_request(:get, 'http://example.com/.well-known/host-meta').to_raise(HaltSuccessError)
|
26
|
+
lambda{Redfinger::Client.new('acct:abc@example.com').send(:retrieve_template_from_xrd)}.should raise_error(HaltSuccessError)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should make an HTTP request if the HTTPS request times out in Net::HTTP' do
|
30
|
+
stub_request(:get, 'https://example.com/.well-known/host-meta').to_raise(Errno::ETIMEDOUT)
|
31
|
+
stub_request(:get, 'http://example.com/.well-known/host-meta').to_raise(HaltSuccessError)
|
32
|
+
lambda{Redfinger::Client.new('acct:abc@example.com').send(:retrieve_template_from_xrd)}.should raise_error(HaltSuccessError)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should make an HTTP request if the HTTPS request times out in RestClient' do
|
36
|
+
stub_request(:get, 'https://example.com/.well-known/host-meta').to_raise(RestClient::RequestTimeout)
|
37
|
+
stub_request(:get, 'http://example.com/.well-known/host-meta').to_raise(HaltSuccessError)
|
38
|
+
lambda{Redfinger::Client.new('acct:abc@example.com').send(:retrieve_template_from_xrd)}.should raise_error(HaltSuccessError)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should make an HTTP request if the server throws a 403 forbidden on the HTTPS request' do
|
42
|
+
stub_request(:get, 'https://example.com/.well-known/host-meta').to_return(:status => [403, "Forbidden"])
|
43
|
+
stub_request(:get, 'http://example.com/.well-known/host-meta').to_raise(HaltSuccessError)
|
44
|
+
lambda{Redfinger::Client.new('acct:abc@example.com').send(:retrieve_template_from_xrd)}.should raise_error(HaltSuccessError)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should raise Redfinger::ResourceNotFound if HTTP fails as well' do
|
48
|
+
stub_request(:get, 'https://example.com/.well-known/host-meta').to_raise(Errno::ECONNREFUSED)
|
49
|
+
stub_request(:get, 'http://example.com/.well-known/host-meta').to_raise(Errno::ECONNREFUSED)
|
50
|
+
lambda{Redfinger::Client.new('acct:abc@example.com').send(:retrieve_template_from_xrd)}.should raise_error(Redfinger::ResourceNotFound)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should raise Redfinger::ResourceNotFound on 404 as well as HTTP fail' do
|
54
|
+
stub_request(:get, /.well-known\/host-meta/).to_return(:status => 404, :body => '404 Not Found')
|
55
|
+
lambda{Redfinger::Client.new('acct:abc@example.com').send(:retrieve_template_from_xrd)}.should raise_error(Redfinger::ResourceNotFound)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should return the template' do
|
59
|
+
stub_request(:get, 'https://example.com/.well-known/host-meta').to_return(:status => 200, :body => host_xrd)
|
60
|
+
Redfinger::Client.new('acct:abc@example.com').send(:retrieve_template_from_xrd).should == 'http://example.com/webfinger/?q={uri}'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#finger' do
|
65
|
+
it 'should fetch the URI template if is not set' do
|
66
|
+
stub_success
|
67
|
+
@client = Redfinger::Client.new('abc@example.com')
|
68
|
+
@client.should_receive(:retrieve_template_from_xrd).and_raise(HaltSuccessError)
|
69
|
+
lambda{@client.finger}.should raise_error(HaltSuccessError)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should NOT fetch the URI template if it is already set' do
|
73
|
+
stub_success
|
74
|
+
@client = Redfinger::Client.new('abc@example.com')
|
75
|
+
@client.should_not_receive(:retrieve_template_from_xrd)
|
76
|
+
@client.uri_template = 'http://example.com/webfinger/?q={uri}'
|
77
|
+
@client.finger
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should return a Finger' do
|
81
|
+
stub_success
|
82
|
+
Redfinger::Client.new('abc@example.com').finger.should be_kind_of(Redfinger::Finger)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Redfinger do
|
4
|
+
describe '#finger' do
|
5
|
+
it 'should initialize a new client' do
|
6
|
+
Redfinger::Client.should_receive(:new).with('abc@example.com').and_return(mock("Redfinger::Client", :finger => nil))
|
7
|
+
Redfinger.finger('abc@example.com')
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'redfinger'
|
6
|
+
require 'rspec'
|
7
|
+
require 'rspec/autorun'
|
8
|
+
require 'webmock/rspec'
|
9
|
+
|
10
|
+
include WebMock::API
|
11
|
+
|
12
|
+
def host_xrd
|
13
|
+
<<-XML
|
14
|
+
<?xml version='1.0' encoding='UTF-8'?>
|
15
|
+
<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>
|
16
|
+
<Link rel='lrdd'
|
17
|
+
template='http://example.com/webfinger/?q={uri}'>
|
18
|
+
<Title>Resource Descriptor</Title>
|
19
|
+
</Link>
|
20
|
+
</XRD>
|
21
|
+
XML
|
22
|
+
end
|
23
|
+
|
24
|
+
def finger_xrd
|
25
|
+
<<-XML
|
26
|
+
<?xml version='1.0'?>
|
27
|
+
<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>
|
28
|
+
<Alias>http://www.google.com/profiles/abc</Alias>
|
29
|
+
<Link rel='http://portablecontacts.net/spec/1.0' href='http://www-opensocial.googleusercontent.com/api/people/'/>
|
30
|
+
<Link rel='http://webfinger.net/rel/profile-page' href='http://www.google.com/profiles/abc' type='text/html'/>
|
31
|
+
<Link rel='http://microformats.org/profile/hcard' href='http://www.google.com/profiles/abc' type='text/html'/>
|
32
|
+
<Link rel='http://gmpg.org/xfn/11' href='http://www.google.com/profiles/abc' type='text/html'/>
|
33
|
+
<Link rel='http://specs.openid.net/auth/2.0/provider' href='http://www.google.com/profiles/abc'/>
|
34
|
+
<Link rel='describedby' href='http://www.google.com/profiles/abc' type='text/html'/>
|
35
|
+
<Link rel='describedby' href='http://s2.googleusercontent.com/webfinger/?q=acct%3Aabc%example.com&fmt=foaf' type='application/rdf+xml'/>
|
36
|
+
<Link rel='http://schemas.google.com/g/2010#updates-from' href='http://buzz.googleapis.com/feeds/100660544095714416357/public/posted' type='application/atom+xml'/>
|
37
|
+
</XRD>
|
38
|
+
XML
|
39
|
+
end
|
40
|
+
|
41
|
+
def stub_success(address = 'abc@example.com')
|
42
|
+
stub_request(:get, 'https://example.com/.well-known/host-meta').to_return(:status => 200, :body => host_xrd)
|
43
|
+
stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 200, :body => finger_xrd)
|
44
|
+
end
|
45
|
+
|
46
|
+
RSpec.configure do |config|
|
47
|
+
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: em-redfinger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michael Bleigh
|
9
|
+
- Arnaud Berthomier
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2011-11-10 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: em-http-request
|
17
|
+
requirement: &10819880 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *10819880
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: em-http-request
|
28
|
+
requirement: &10819120 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *10819120
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: nokogiri
|
39
|
+
requirement: &10818540 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.4.0
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *10818540
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: hashie
|
50
|
+
requirement: &10817940 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :runtime
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *10817940
|
59
|
+
description: A Ruby Webfinger client
|
60
|
+
email: oz@cyprio.net
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files:
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
files:
|
67
|
+
- .rspec
|
68
|
+
- LICENSE
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- VERSION
|
72
|
+
- em-redfinger.gemspec
|
73
|
+
- lib/em-redfinger.rb
|
74
|
+
- lib/em-redfinger/client.rb
|
75
|
+
- lib/em-redfinger/finger.rb
|
76
|
+
- lib/em-redfinger/link.rb
|
77
|
+
- lib/em-redfinger/link_helpers.rb
|
78
|
+
- redfinger.gemspec
|
79
|
+
- spec/redfinger/client_spec.rb
|
80
|
+
- spec/redfinger_spec.rb
|
81
|
+
- spec/spec.opts
|
82
|
+
- spec/spec_helper.rb
|
83
|
+
homepage: http://github.com/oz/em-redfinger
|
84
|
+
licenses: []
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.8.10
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: A Ruby WebFinger client.
|
107
|
+
test_files: []
|