diff --git a/Gemfile b/Gemfile
index 89f0b91..9f10e6f 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,5 +1,7 @@
source "https://rubygems.org"
+gem 'pry'
+
group :test do
gem 'rspec', '>= 3.0'
gem 'nyan-cat-formatter'
diff --git a/Gemfile.lock b/Gemfile.lock
index 2ef2144..64489ce 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -10,6 +10,7 @@ GEM
remote: https://rubygems.org/
specs:
addressable (2.4.0)
+ coderay (1.1.0)
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.2.5)
@@ -25,11 +26,16 @@ GEM
domain_name (~> 0.5)
http-form_data (1.0.1)
http_parser.rb (0.6.0)
+ method_source (0.8.2)
mini_portile2 (2.0.0)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
nyan-cat-formatter (0.11)
rspec (>= 2.99, >= 2.14.2, < 4)
+ pry (0.10.1)
+ coderay (~> 1.1.0)
+ method_source (~> 0.8.1)
+ slop (~> 3.4)
rspec (3.4.0)
rspec-core (~> 3.4.0)
rspec-expectations (~> 3.4.0)
@@ -44,6 +50,7 @@ GEM
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
safe_yaml (1.0.4)
+ slop (3.6.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.2)
@@ -59,5 +66,6 @@ DEPENDENCIES
bundler (~> 1.3)
goldfinger!
nyan-cat-formatter
+ pry
rspec (>= 3.0)
webmock
diff --git a/lib/goldfinger/result.rb b/lib/goldfinger/result.rb
index 610bc40..c4065ef 100644
--- a/lib/goldfinger/result.rb
+++ b/lib/goldfinger/result.rb
@@ -29,12 +29,13 @@ module Goldfinger
def parse_json
json = JSON.parse(@body)
- json['links'].each { |link| @links[link['rel']] = link['href'] }
+ json['links'].each { |link| @links[link['rel']] = Hash[link.keys.map { |key| [key.to_sym, link[key]] }] }
end
def parse_xml
xml = Nokogiri::XML(@body)
- xml.xpath('//xmlns:Link', xmlns: 'http://docs.oasis-open.org/ns/xri/xrd-1.0').each { |link| @links[link.attribute('rel').value] = link.attribute('href').value }
+ links = xml.xpath('//xmlns:Link', xmlns: 'http://docs.oasis-open.org/ns/xri/xrd-1.0')
+ links.each { |link| @links[link.attribute('rel').value] = Hash[link.attributes.keys.map { |key| [key.to_sym, link.attribute(key).value] }] }
end
end
end
diff --git a/spec/fixtures/quitter.no_.well-known_host-meta b/spec/fixtures/quitter.no_.well-known_host-meta
new file mode 100644
index 0000000..7da3feb
--- /dev/null
+++ b/spec/fixtures/quitter.no_.well-known_host-meta
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
diff --git a/spec/fixtures/quitter.no_.well-known_webfinger.json b/spec/fixtures/quitter.no_.well-known_webfinger.json
new file mode 100644
index 0000000..c2aa46c
--- /dev/null
+++ b/spec/fixtures/quitter.no_.well-known_webfinger.json
@@ -0,0 +1 @@
+{"subject":"acct:gargron@quitter.no","aliases":["https:\/\/quitter.no\/user\/7477","https:\/\/quitter.no\/gargron"],"links":[{"rel":"http:\/\/webfinger.net\/rel\/profile-page","type":"text\/html","href":"https:\/\/quitter.no\/gargron"},{"rel":"http:\/\/gmpg.org\/xfn\/11","type":"text\/html","href":"https:\/\/quitter.no\/gargron"},{"rel":"describedby","type":"application\/rdf+xml","href":"https:\/\/quitter.no\/gargron\/foaf"},{"rel":"http:\/\/apinamespace.org\/atom","type":"application\/atomsvc+xml","href":"https:\/\/quitter.no\/api\/statusnet\/app\/service\/gargron.xml"},{"rel":"http:\/\/apinamespace.org\/twitter","href":"https:\/\/quitter.no\/api\/"},{"rel":"http:\/\/specs.openid.net\/auth\/2.0\/provider","href":"https:\/\/quitter.no\/gargron"},{"rel":"http:\/\/schemas.google.com\/g\/2010#updates-from","type":"application\/atom+xml","href":"https:\/\/quitter.no\/api\/statuses\/user_timeline\/7477.atom"},{"rel":"magic-public-key","href":"data:application\/magic-public-key,RSA.1ZBkHTavLvxH3FzlKv4O6WtlILKRFfNami3_Rcu8EuogtXSYiS-bB6hElZfUCSHbC4uLemOA34PEhz__CDMozax1iI_t8dzjDnh1x0iFSup7pSfW9iXk_WU3Dm74yWWW2jildY41vWgrEstuQ1dJ8vVFfSJ9T_tO4c-T9y8vDI8=.AQAB"},{"rel":"salmon","href":"https:\/\/quitter.no\/main\/salmon\/user\/7477"},{"rel":"http:\/\/salmon-protocol.org\/ns\/salmon-replies","href":"https:\/\/quitter.no\/main\/salmon\/user\/7477"},{"rel":"http:\/\/salmon-protocol.org\/ns\/salmon-mention","href":"https:\/\/quitter.no\/main\/salmon\/user\/7477"},{"rel":"http:\/\/ostatus.org\/schema\/1.0\/subscribe","template":"https:\/\/quitter.no\/main\/ostatussub?profile={uri}"}]}
diff --git a/spec/fixtures/quitter.no_.well-known_webfinger.xml b/spec/fixtures/quitter.no_.well-known_webfinger.xml
new file mode 100644
index 0000000..1e6c043
--- /dev/null
+++ b/spec/fixtures/quitter.no_.well-known_webfinger.xml
@@ -0,0 +1,18 @@
+
+
+ acct:gargron@quitter.no
+ https://quitter.no/user/7477
+ https://quitter.no/gargron
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spec/goldfinger/client_spec.rb b/spec/goldfinger/client_spec.rb
index 73b5883..b126a29 100644
--- a/spec/goldfinger/client_spec.rb
+++ b/spec/goldfinger/client_spec.rb
@@ -1,5 +1,14 @@
describe Goldfinger::Client do
describe '#finger' do
- pending
+ before do
+ stub_request(:get, 'https://quitter.no/.well-known/host-meta').to_return(body: fixture('quitter.no_.well-known_host-meta'))
+ stub_request(:get, 'https://quitter.no/.well-known/webfinger?resource=acct:gargron@quitter.no').to_return(body: fixture('quitter.no_.well-known_webfinger.json'))
+ end
+
+ subject { Goldfinger::Client.new('acct:gargron@quitter.no') }
+
+ it 'returns a result' do
+ expect(subject.finger).to be_instance_of Goldfinger::Result
+ end
end
end
diff --git a/spec/goldfinger/request_spec.rb b/spec/goldfinger/request_spec.rb
index 82245e7..85ed9d1 100644
--- a/spec/goldfinger/request_spec.rb
+++ b/spec/goldfinger/request_spec.rb
@@ -1,5 +1,13 @@
describe Goldfinger::Request do
describe '#perform' do
- pending
+ before do
+ stub_request(:get, 'example.com').to_return(body: 'OK')
+ end
+
+ subject { Goldfinger::Request.new(:get, 'http://example.com').perform }
+
+ it 'returns the body' do
+ expect(subject.last.to_s).to eql 'OK'
+ end
end
end
diff --git a/spec/goldfinger/result_spec.rb b/spec/goldfinger/result_spec.rb
index baa1b19..6636b7a 100644
--- a/spec/goldfinger/result_spec.rb
+++ b/spec/goldfinger/result_spec.rb
@@ -1,17 +1,41 @@
describe Goldfinger::Result do
- describe '#links' do
- pending
+ context 'application/xrd+xml' do
+ let(:headers) { h = HTTP::Headers.new; h.set(HTTP::Headers::CONTENT_TYPE, 'application/xrd+xml'); h }
+ let(:body) { File.read(fixture_path('quitter.no_.well-known_webfinger.xml')) }
+
+ subject { Goldfinger::Result.new(headers, body) }
+
+ describe '#links' do
+ it 'returns a non-empty array' do
+ expect(subject.links).to be_instance_of Array
+ expect(subject.links).to_not be_empty
+ end
+ end
+
+ describe '#link' do
+ it 'returns a value for a given rel' do
+ expect(subject.link('http://webfinger.net/rel/profile-page')[:href]).to eql 'https://quitter.no/gargron'
+ end
+ end
end
- describe '#link' do
- pending
- end
+ context 'application/jrd+json' do
+ let(:headers) { h = HTTP::Headers.new; h.set(HTTP::Headers::CONTENT_TYPE, 'application/jrd+json'); h }
+ let(:body) { File.read(fixture_path('quitter.no_.well-known_webfinger.json')) }
- describe '#parse_xml' do
- pending
- end
+ subject { Goldfinger::Result.new(headers, body) }
- describe '#parse_json' do
- pending
+ describe '#links' do
+ it 'returns a non-empty array' do
+ expect(subject.links).to be_instance_of Array
+ expect(subject.links).to_not be_empty
+ end
+ end
+
+ describe '#link' do
+ it 'returns a value for a given rel' do
+ expect(subject.link('http://webfinger.net/rel/profile-page')[:href]).to eql 'https://quitter.no/gargron'
+ end
+ end
end
end
diff --git a/spec/goldfinger/utils_spec.rb b/spec/goldfinger/utils_spec.rb
deleted file mode 100644
index ad6b398..0000000
--- a/spec/goldfinger/utils_spec.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-describe Goldfinger::Utils do
- pending
-end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index a06f2bf..850ba93 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,5 +1,6 @@
require 'goldfinger'
require 'webmock/rspec'
+require 'pry'
WebMock.disable_net_connect!
@@ -14,3 +15,11 @@ RSpec.configure do |config|
end
end
+
+def fixture_path(path)
+ File.join(File.expand_path('../fixtures', __FILE__), path)
+end
+
+def fixture(path)
+ File.new(fixture_path(path))
+end