I am trying to get both hCard and XFN (aka relation) information from
my twitter profile.
I'd like to be able to do hCardObject.relation => 'contect'
Any idea on how to to that? I guess it's already possible but I can't
figure how!
Thanks in advance,
> I am trying to get both hCard and XFN (aka relation) information from
> my twitter profile.
You want to get the hCards for all your contacts marked 'contact' via XFN?
If so, there's nothing built-in for that. But here is how I would do it:
>> require 'rubygems'
=> false
>> require 'mofo'
=> false
>> friends = XFN.find 'http://twitter.com/defunkt'
=> #<XFN:0x16b2cbc @links=[#<XFN::Link relation="me", ...>]
>> hcards = friends.contact.map do |contact|
?> hCard.find :text => %(<span class="vcard">#{contact.name}</span>)
?> end
=> [#<HCard:0x12d56e4 @photo="http://s3.amazonaws.com/twitter_production/...>]
>> hcards.size
=> 100
>> hcards.first
=> #<HCard:0x12d56e4 @photo="http://s3.amazonaws.com/twitter_production/...>]
>> hcards.first.fn
=> "Blaine Cook"
I guess we could have a :relation option for all microformats, to scope finds by
relation. Not a bad idea. If you can submit a failing spec I can implement it.
--
Chris Wanstrath
http://errfree.com // http://errtheblog.com
Well, I don't know what is the best approach. I fact, I want to be
able to know what is the XFN::rel of an hCard object.
So I don't what's would be the best approach :
- HCard.find('http://twitter.com/foo')[0].XFN::relation = :me ||
:friend || :contact
- HCard.find('http://twitter.com/foo') .contacts or .me or .friends
- HCard.find('http://twitter.com/foo', :relation => :me || :friend || :contact)
The third and second solution are already possible with your snippet though
So, what do you think?
--
Simon Rozet, http://atonie.org/sr/
> The third and second solution are already possible with your snippet though
> So, what do you think?
The thing is, hCards don't really know about XFN. XFN is for relating
links to the page you're on, hCards are more than links and can live
outside of the page your'e on. Someone please correct me if I'm
wrong.
Because of that, I'm not sure I can imagine a clear mental model for
how this should work. Do any of the other parser implementations
handle this?
- Chris
Well, I think you are right. I've checked some parser and it looks
it's not the parser's job to do that. I'll use your method then. Thank
you :-)