Patches: Browse | Submit New | Admin

[#29396] Facebook and Twitter urls

Date:
2011-10-05 06:26
Priority:
3
Submitted By:
Scott Williams (krazyyak)
Assigned To:
Nobody (None)
Category:
Widget (example)
State:
Open
Summary:
Facebook and Twitter urls

Detailed description
We needed to read and write Twitter and Facebook urls, so I followed one of the examples, and created this monkey patch
to write them out:

module Vpim
    class Vcard
        class Maker
            def add_twitter(value)
                @card << Vpim::DirectoryInfo::Field.create('X-SOCIALPROFILE', value.to_str, {'type' =>
"twitter"})
            end

            def add_facebook(value)
                @card << Vpim::DirectoryInfo::Field.create('X-SOCIALPROFILE', value.to_str, {'type' =>
"facebook"})
            end
        end
    end
end

Reading them was simpler: 

Vpim::Vcard.decode(card_file).map do |card|
  contact.facebook_url = card.value("X-SOCIALPROFILE", type="facebook")
  contact.twitter_url = card.value("X-SOCIALPROFILE", type="twitter")
end

This follows the format used in OS X's Address Book.app.

Regards,
Scott Williams

Add A Comment: Notepad

Please login


Followup

No Followups Have Been Posted

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

No Changes Have Been Made to This Item