diff --git a/app/models/person.rb b/app/models/person.rb index 883db68bc..82ee82e62 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -1,3 +1,5 @@ +require 'lib/hcard' + class Person include MongoMapper::Document include ROXML @@ -97,13 +99,13 @@ class Person puts profile.hcard.first[:href] - hcard = Prism.find profile.hcard.first[:href], :hcard - pp hcard.class - debugger + hcard = HCard.find profile.hcard.first[:href] + receive_url = profile.links.select{ |l| l.rel == 'http://joindiaspora.com/seed_location'}.first.href - new_person.url = receive_url.split('receive').first - new_person.profile = Profile.new(:first_name => "Anon", :last_name => "ymous") - if new_person.save + new_person.url = hcard[:url] + puts new_person.url + new_person.profile = Profile.new(:first_name => hcard[:given_name], :last_name => hcard[:family_name]) + if new_person.save! new_person else nil diff --git a/app/views/publics/hcard.erb b/app/views/publics/hcard.erb index 773aa1cc7..f8a3fef91 100644 --- a/app/views/publics/hcard.erb +++ b/app/views/publics/hcard.erb @@ -20,7 +20,8 @@
<%= @person.profile.last_name %>
-
+
+
Full name
<%= @person.real_name %> @@ -29,7 +30,7 @@
URL
- <%= @person.url%> + <%= @person.url%>
diff --git a/lib/hcard.rb b/lib/hcard.rb new file mode 100644 index 000000000..e8c1c2110 --- /dev/null +++ b/lib/hcard.rb @@ -0,0 +1,8 @@ +module HCard + def self.find url + doc = Nokogiri::HTML(Net::HTTP.get URI.parse(url)) + {:given_name => doc.css(".given_name").text, + :family_name => doc.css(".family_name").text, + :url => doc.css("#pod_location").text} + end +end diff --git a/spec/lib/hcard.rb b/spec/lib/hcard.rb new file mode 100644 index 000000000..06a237188 --- /dev/null +++ b/spec/lib/hcard.rb @@ -0,0 +1,13 @@ +require File.dirname(__FILE__) + '/../spec_helper' +require File.dirname(__FILE__) + '/../../lib/hcard' + +describe HCard do + it 'should retreive and parse an hcard' do + f = Redfinger.finger('tom@tom.joindiaspora.com') + hcard = HCard.find f.hcard.first[:href] + hcard[:family_name].include?("Hamiltom").should be true + hcard[:given_name].include?("Alex").should be true + pp hcard + (hcard[:url] == "http://tom.joindiaspora.com").should be true + end +end