How to retrieve both hCard and XFN info?

1 view
Skip to first unread message

Simon Rozet

unread,
Sep 26, 2007, 12:41:12 PM9/26/07
to mofo
Hello,

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,

Chris Wanstrath

unread,
Sep 28, 2007, 5:14:50 PM9/28/07
to mof...@googlegroups.com
On 9/26/07, Simon Rozet <simon...@gmail.com> wrote:

> 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

Simon Rozet

unread,
Sep 29, 2007, 1:07:58 PM9/29/07
to mof...@googlegroups.com
2007/9/28, Chris Wanstrath <ch...@ozmm.org>:

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/

Chris Wanstrath

unread,
Sep 29, 2007, 1:37:36 PM9/29/07
to mof...@googlegroups.com
On 9/29/07, Simon Rozet <simon...@gmail.com> wrote:

> 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

Simon Rozet

unread,
Sep 29, 2007, 2:31:18 PM9/29/07
to mof...@googlegroups.com

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 :-)

Reply all
Reply to author
Forward
0 new messages