Class: DiasporaFederation::Discovery::HCard
- Defined in:
- lib/diaspora_federation/discovery/h_card.rb
Overview
This needs some radical restructuring. The generated HTML is not correctly nested according to the hCard standard and class names are partially wrong. Also, apart from that, it’s just ugly.
The current implementation contains a huge amount of legacy elements and classes, that should be removed and cleaned up in later iterations.
This class provides the means of generating and parsing account data to and from the hCard format. hCard is based on RFC 2426 (vCard) which got superseded by RFC 6350. There is a draft for a new h-card format specification, that makes use of the new vCard standard.
Constant Summary collapse
- SELECTORS =
CSS selectors for finding all the hCard fields
{ uid: ".uid", nickname: ".nickname", fn: ".fn", given_name: ".given_name", family_name: ".family_name", url: "#pod_location[href]", photo: ".entity_photo .photo[src]", photo_medium: ".entity_photo_medium .photo[src]", photo_small: ".entity_photo_small .photo[src]", key: ".key", searchable: ".searchable" }.freeze
Constants inherited from Entity
Instance Attribute Summary collapse
-
#first_name ⇒ String
readonly
deprecated
Deprecated.
We decided to only use one name field, these should be removed in later iterations (will affect older diaspora* installations).
-
#full_name ⇒ String
readonly
Display name of the user.
-
#guid ⇒ String
readonly
Guid.
-
#last_name ⇒ String
readonly
deprecated
Deprecated.
We decided to only use one name field, these should be removed in later iterations (will affect older diaspora* installations).
-
#nickname ⇒ String
readonly
The first part of the diaspora* ID.
-
#photo_large_url ⇒ String
readonly
Url to the big avatar (300x300).
-
#photo_medium_url ⇒ String
readonly
Url to the medium avatar (100x100).
-
#photo_small_url ⇒ String
readonly
Url to the small avatar (50x50).
-
#public_key ⇒ String
readonly
When a user is created on the pod, the pod MUST generate a pgp keypair for them.
-
#searchable ⇒ Boolean
readonly
deprecated
Deprecated.
As this is a simple property, consider move to WebFinger instead of HCard. vCard has no comparable field for this information, but Webfinger may declare arbitrary properties (will affect older diaspora* installations).
-
#url ⇒ String
readonly
deprecated
Deprecated.
should be changed to the profile url. The pod url is in the WebFinger (see WebFinger#seed_url, will affect older diaspora* installations).
Class Method Summary collapse
-
.from_html(html_string) ⇒ HCard
Creates a new HCard instance from the given HTML string.
Instance Method Summary collapse
-
#to_html ⇒ String
Create the HTML string from the current HCard instance.
Methods inherited from Entity
entity_class, entity_name, from_xml, #initialize, #to_h, #to_s, #to_xml
Methods included from PropertiesDSL
#class_props, #default_values, #entity, #find_property_for_xml_name, #missing_props, #property, #resolv_aliases, #xml_names
Methods included from Logging
Constructor Details
This class inherits a constructor from DiasporaFederation::Entity
Instance Attribute Details
#first_name ⇒ String (readonly)
We decided to only use one name field, these should be removed in later iterations (will affect older diaspora* installations).
Returns first name.
90 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 90 property :first_name |
#full_name ⇒ String (readonly)
Returns display name of the user.
55 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 55 property :full_name |
#guid ⇒ String (readonly)
Returns guid.
46 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 46 property :guid |
#last_name ⇒ String (readonly)
We decided to only use one name field, these should be removed in later iterations (will affect older diaspora* installations).
Returns last name.
98 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 98 property :last_name |
#nickname ⇒ String (readonly)
The first part of the diaspora* ID
51 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 51 property :nickname, default: nil |
#photo_large_url ⇒ String (readonly)
Returns url to the big avatar (300x300).
76 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 76 property :photo_large_url |
#photo_medium_url ⇒ String (readonly)
Returns url to the medium avatar (100x100).
79 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 79 property :photo_medium_url |
#photo_small_url ⇒ String (readonly)
Returns url to the small avatar (50x50).
82 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 82 property :photo_small_url |
#public_key ⇒ String (readonly)
When a user is created on the pod, the pod MUST generate a pgp keypair for them. This key is used for signing messages. The format is a DER-encoded PKCS#1 key beginning with the text “—–BEGIN PUBLIC KEY—–” and ending with “—–END PUBLIC KEY—–”.
72 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 72 property :public_key |
#searchable ⇒ Boolean (readonly)
As this is a simple property, consider move to WebFinger instead of HCard. vCard has no comparable field for this information, but Webfinger may declare arbitrary properties (will affect older diaspora* installations).
flag if a user is searchable by name
108 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 108 property :searchable |
#url ⇒ String (readonly)
should be changed to the profile url. The pod url is in the WebFinger (see WebFinger#seed_url, will affect older diaspora* installations).
Returns link to the pod.
63 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 63 property :url, default: nil |
Class Method Details
.from_html(html_string) ⇒ HCard
Creates a new HCard instance from the given HTML string
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 159 def self.from_html(html_string) doc = parse_html_and_validate(html_string) new( guid: guid_from_doc(doc), nickname: content_from_doc(doc, :nickname), full_name: content_from_doc(doc, :fn), photo_large_url: photo_from_doc(doc, :photo), photo_medium_url: photo_from_doc(doc, :photo_medium), photo_small_url: photo_from_doc(doc, :photo_small), searchable: (content_from_doc(doc, :searchable) == "true"), # TODO: public key is new and can be missing public_key: (content_from_doc(doc, :key) unless element_from_doc(doc, :key).nil?), # TODO: remove first_name and last_name! first_name: content_from_doc(doc, :given_name), last_name: content_from_doc(doc, :family_name) ) end |
Instance Method Details
#to_html ⇒ String
Create the HTML string from the current HCard instance
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 127 def to_html builder = create_builder content = builder.doc.at_css("#content_inner") add_simple_property(content, :uid, "uid", @guid) add_simple_property(content, :nickname, "nickname", @nickname) add_simple_property(content, :full_name, "fn", @full_name) add_simple_property(content, :searchable, "searchable", @searchable) add_property(content, :key) do |html| html.pre(@public_key.to_s, class: "key") end # TODO: remove me! ################### add_simple_property(content, :first_name, "given_name", @first_name) add_simple_property(content, :family_name, "family_name", @last_name) ####################################### add_property(content, :url) do |html| html.a(@url.to_s, id: "pod_location", class: "url", rel: "me", href: @url.to_s) end add_photos(content) builder.doc.to_xhtml(indent: 2, indent_text: " ") end |