diff --git a/app/models/person.rb b/app/models/person.rb index 883db68bc68dc2799f84be5835b8ba6efed5e568..82ee82e62f665c67a6beed433c56dfb5e25c1fea 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 773aa1cc7ed49942d4acdd20b8dc98594418b24b..f8a3fef916a060b4cac73857fe6bfbc32ae81d3e 100644 --- a/app/views/publics/hcard.erb +++ b/app/views/publics/hcard.erb @@ -20,7 +20,8 @@ <dd> <span class="family_name" ><%= @person.profile.last_name %></span> </dd> - </dl> <dl class="entity_fn"> + </dl> + <dl class="entity_fn"> <dt>Full name</dt> <dd> <span class="fn" ><%= @person.real_name %></span> @@ -29,7 +30,7 @@ <dl class="entity_url"> <dt>URL</dt> <dd> - <a href="<%= @person.url%>" rel="me" class="url"><%= @person.url%></a> + <a href="<%= @person.url%>" rel="me" id="pod_location" class="url"><%= @person.url%></a> </dd> </dl> <dl class="entity_note"> diff --git a/lib/hcard.rb b/lib/hcard.rb new file mode 100644 index 0000000000000000000000000000000000000000..e8c1c2110201ec421cdecac4db1ffe475ce35c35 --- /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 0000000000000000000000000000000000000000..06a2371886e6c423feab245d592f274acc8e156a --- /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