redfinger 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format nested
data/Rakefile CHANGED
@@ -22,15 +22,10 @@ rescue LoadError
22
22
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
23
23
  end
24
24
 
25
- require 'spec/rake/spectask'
26
- Spec::Rake::SpecTask.new(:spec) do |spec|
27
- spec.libs << 'lib' << 'spec'
28
- spec.spec_files = FileList['spec/**/*_spec.rb']
29
- end
25
+ require 'rspec/core/rake_task'
26
+ RSpec::Core::RakeTask.new(:spec)
30
27
 
31
- Spec::Rake::SpecTask.new(:rcov) do |spec|
32
- spec.libs << 'lib' << 'spec'
33
- spec.pattern = 'spec/**/*_spec.rb'
28
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
34
29
  spec.rcov = true
35
30
  end
36
31
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.1.0
@@ -4,11 +4,14 @@ require 'uri'
4
4
 
5
5
  module Redfinger
6
6
  class Client
7
- attr_accessor :account, :domain, :uri_template
7
+ attr_accessor :account, :domain, :uri_template, :xrd_timeout, :xrd_open_timeout
8
8
 
9
9
  def initialize(email, uri_template = nil)
10
10
  self.account = normalize(email)
11
11
  self.domain = account.split('@').last
12
+
13
+ self.xrd_timeout = 10
14
+ self.xrd_open_timeout = 5
12
15
  end
13
16
 
14
17
  def finger
@@ -32,7 +35,12 @@ module Redfinger
32
35
  end
33
36
 
34
37
  def retrieve_template_from_xrd(ssl = true)
35
- doc = Nokogiri::XML::Document.parse(RestClient.get(xrd_url(ssl)).body)
38
+ xrd_client = RestClient::Resource.new(xrd_url(ssl),
39
+ :timeout => self.xrd_timeout,
40
+ :open_timeout => self.xrd_open_timeout
41
+ )
42
+
43
+ doc = Nokogiri::XML::Document.parse(xrd_client.get.body)
36
44
  if doc.namespaces["xmlns"] != "http://docs.oasis-open.org/ns/xri/xrd-1.0"
37
45
  # it's probably not finger, let's try without ssl
38
46
  # http://code.google.com/p/webfinger/wiki/WebFingerProtocol
@@ -41,7 +49,8 @@ module Redfinger
41
49
  end
42
50
 
43
51
  doc.at('Link[rel=lrdd]').attribute('template').value
44
- rescue Errno::ECONNREFUSED, RestClient::ResourceNotFound
52
+ rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT,
53
+ RestClient::RequestTimeout, RestClient::ResourceNotFound, RestClient::Forbidden
45
54
  if ssl
46
55
  retrieve_template_from_xrd(false)
47
56
  else
@@ -12,7 +12,7 @@ module Redfinger
12
12
 
13
13
  # All of the links provided by the Webfinger response.
14
14
  def links
15
- @links ||= @doc.css('Link').map{|l| Link.new(l)}
15
+ @links ||= @doc.css('Link').map{|l| Link.from_xml(l)}
16
16
  end
17
17
 
18
18
  def inspect # :nodoc:
@@ -3,10 +3,12 @@ require 'hashie'
3
3
 
4
4
  module Redfinger
5
5
  class Link < Hashie::Mash
6
- def initialize(xml_link)
7
- self[:rel] = xml_link['rel']
8
- self[:href] = xml_link['href']
9
- self[:type] = xml_link['type']
6
+ def self.from_xml(xml_link)
7
+ new_link = Link.new
8
+ new_link[:rel] = xml_link['rel']
9
+ new_link[:href] = xml_link['href']
10
+ new_link[:type] = xml_link['type']
11
+ new_link
10
12
  end
11
13
 
12
14
  # Outputs the URL of the link, useful for using
@@ -25,7 +25,7 @@ module Redfinger
25
25
  protected
26
26
 
27
27
  def relmap(uri, substring=false)
28
- @doc.css("Link[rel#{'^' if substring}=\"#{uri}\"]").map{|e| Link.new(e)}
28
+ @doc.css("Link[rel#{'^' if substring}=\"#{uri}\"]").map{|e| Link.from_xml(e)}
29
29
  end
30
30
  end
31
31
  end
@@ -1,52 +1,50 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{redfinger}
8
- s.version = "0.0.6"
8
+ s.version = "0.1.0"
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-08-10}
12
+ s.date = %q{2011-02-07}
13
13
  s.description = %q{A Ruby Webfinger client}
14
14
  s.email = %q{michael@intridea.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "lib/redfinger.rb",
27
- "lib/redfinger/client.rb",
28
- "lib/redfinger/finger.rb",
29
- "lib/redfinger/link.rb",
30
- "lib/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"
21
+ ".rspec",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/redfinger.rb",
27
+ "lib/redfinger/client.rb",
28
+ "lib/redfinger/finger.rb",
29
+ "lib/redfinger/link.rb",
30
+ "lib/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
36
  ]
37
37
  s.homepage = %q{http://github.com/mbleigh/redfinger}
38
- s.rdoc_options = ["--charset=UTF-8"]
39
38
  s.require_paths = ["lib"]
40
- s.rubygems_version = %q{1.3.7}
39
+ s.rubygems_version = %q{1.5.0}
41
40
  s.summary = %q{A Ruby WebFinger client.}
42
41
  s.test_files = [
43
42
  "spec/redfinger/client_spec.rb",
44
- "spec/redfinger_spec.rb",
45
- "spec/spec_helper.rb"
43
+ "spec/redfinger_spec.rb",
44
+ "spec/spec_helper.rb"
46
45
  ]
47
46
 
48
47
  if s.respond_to? :specification_version then
49
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
48
  s.specification_version = 3
51
49
 
52
50
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -25,6 +25,24 @@ describe Redfinger::Client do
25
25
  stub_request(:get, 'http://example.com/.well-known/host-meta').to_raise(HaltSuccessError)
26
26
  lambda{Redfinger::Client.new('acct:abc@example.com').send(:retrieve_template_from_xrd)}.should raise_error(HaltSuccessError)
27
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
28
46
 
29
47
  it 'should raise Redfinger::ResourceNotFound if HTTP fails as well' do
30
48
  stub_request(:get, 'https://example.com/.well-known/host-meta').to_raise(Errno::ECONNREFUSED)
@@ -3,11 +3,11 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
 
4
4
  require 'rubygems'
5
5
  require 'redfinger'
6
- require 'spec'
7
- require 'spec/autorun'
6
+ require 'rspec'
7
+ require 'rspec/autorun'
8
8
  require 'webmock/rspec'
9
9
 
10
- include WebMock
10
+ include WebMock::API
11
11
 
12
12
  def host_xrd
13
13
  <<-XML
@@ -43,6 +43,6 @@ def stub_success(address = 'abc@example.com')
43
43
  stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 200, :body => finger_xrd)
44
44
  end
45
45
 
46
- Spec::Runner.configure do |config|
46
+ RSpec.configure do |config|
47
47
 
48
48
  end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redfinger
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 0
9
- - 6
10
- version: 0.0.6
4
+ prerelease:
5
+ version: 0.1.0
11
6
  platform: ruby
12
7
  authors:
13
8
  - Michael Bleigh
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2010-08-10 00:00:00 -05:00
13
+ date: 2011-02-07 00:00:00 -06:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
@@ -26,11 +21,6 @@ dependencies:
26
21
  requirements:
27
22
  - - ">="
28
23
  - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 1
32
- - 5
33
- - 0
34
24
  version: 1.5.0
35
25
  type: :runtime
36
26
  version_requirements: *id001
@@ -42,11 +32,6 @@ dependencies:
42
32
  requirements:
43
33
  - - ">="
44
34
  - !ruby/object:Gem::Version
45
- hash: 7
46
- segments:
47
- - 1
48
- - 4
49
- - 0
50
35
  version: 1.4.0
51
36
  type: :runtime
52
37
  version_requirements: *id002
@@ -58,9 +43,6 @@ dependencies:
58
43
  requirements:
59
44
  - - ">="
60
45
  - !ruby/object:Gem::Version
61
- hash: 3
62
- segments:
63
- - 0
64
46
  version: "0"
65
47
  type: :runtime
66
48
  version_requirements: *id003
@@ -72,11 +54,6 @@ dependencies:
72
54
  requirements:
73
55
  - - ">="
74
56
  - !ruby/object:Gem::Version
75
- hash: 13
76
- segments:
77
- - 1
78
- - 2
79
- - 9
80
57
  version: 1.2.9
81
58
  type: :development
82
59
  version_requirements: *id004
@@ -88,9 +65,6 @@ dependencies:
88
65
  requirements:
89
66
  - - ">="
90
67
  - !ruby/object:Gem::Version
91
- hash: 3
92
- segments:
93
- - 0
94
68
  version: "0"
95
69
  type: :development
96
70
  version_requirements: *id005
@@ -105,7 +79,7 @@ extra_rdoc_files:
105
79
  - README.rdoc
106
80
  files:
107
81
  - .document
108
- - .gitignore
82
+ - .rspec
109
83
  - LICENSE
110
84
  - README.rdoc
111
85
  - Rakefile
@@ -125,8 +99,8 @@ homepage: http://github.com/mbleigh/redfinger
125
99
  licenses: []
126
100
 
127
101
  post_install_message:
128
- rdoc_options:
129
- - --charset=UTF-8
102
+ rdoc_options: []
103
+
130
104
  require_paths:
131
105
  - lib
132
106
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -134,23 +108,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
134
108
  requirements:
135
109
  - - ">="
136
110
  - !ruby/object:Gem::Version
137
- hash: 3
138
- segments:
139
- - 0
140
111
  version: "0"
141
112
  required_rubygems_version: !ruby/object:Gem::Requirement
142
113
  none: false
143
114
  requirements:
144
115
  - - ">="
145
116
  - !ruby/object:Gem::Version
146
- hash: 3
147
- segments:
148
- - 0
149
117
  version: "0"
150
118
  requirements: []
151
119
 
152
120
  rubyforge_project:
153
- rubygems_version: 1.3.7
121
+ rubygems_version: 1.5.0
154
122
  signing_key:
155
123
  specification_version: 3
156
124
  summary: A Ruby WebFinger client.
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC