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
Entity::ENTITY_NAME_REGEX, Entity::INVALID_XML_REGEX
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).
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
class_name, entity_class, entity_name, from_hash, from_json, from_xml, #initialize, #to_h, #to_json, #to_s, #to_xml
Methods included from PropertiesDSL
#class_props, #default_values, #entity, #missing_props, #optional_props, #property, #resolv_aliases
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.
84 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 84 property :first_name, :string |
#full_name ⇒ String (readonly)
Returns display name of the user.
57 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 57 property :full_name, :string |
#guid ⇒ String (readonly)
Returns guid.
48 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 48 property :guid, :string |
#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.
92 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 92 property :last_name, :string |
#nickname ⇒ String (readonly)
The first part of the diaspora* ID
53 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 53 property :nickname, :string, optional: true |
#photo_large_url ⇒ String (readonly)
Returns url to the big avatar (300x300).
70 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 70 property :photo_large_url, :string |
#photo_medium_url ⇒ String (readonly)
Returns url to the medium avatar (100x100).
73 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 73 property :photo_medium_url, :string |
#photo_small_url ⇒ String (readonly)
Returns url to the small avatar (50x50).
76 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 76 property :photo_small_url, :string |
#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—–”.
66 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 66 property :public_key, :string |
#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
102 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 102 property :searchable, :boolean |
Class Method Details
.from_html(html_string) ⇒ HCard
Creates a new HCard instance from the given HTML string
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 149 def self.from_html(html_string) doc = parse_html_and_validate(html_string) new( guid: content_from_doc(doc, :uid), 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"), public_key: content_from_doc(doc, :key), # 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
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/diaspora_federation/discovery/h_card.rb', line 121 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_photos(content) builder.doc.to_xhtml(indent: 2, indent_text: " ") end |