Add hcard, add id for pod_location
This commit is contained in:
parent
59006e657f
commit
67f9d9dab5
4 changed files with 32 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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">
|
||||
|
|
|
|||
8
lib/hcard.rb
Normal file
8
lib/hcard.rb
Normal file
|
|
@ -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
|
||||
13
spec/lib/hcard.rb
Normal file
13
spec/lib/hcard.rb
Normal file
|
|
@ -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
|
||||
Loading…
Reference in a new issue