Class: DiasporaFederation::Discovery::WebFinger

Inherits:
Entity
  • Object
show all
Defined in:
lib/diaspora_federation/discovery/web_finger.rb

Overview

The WebFinger document used for diaspora* user discovery is based on an older draft of the specification.

In the meantime an actual RFC draft has been in development, which should serve as a base for all future changes of this implementation.

Examples:

Creating a WebFinger document from a person hash

wf = WebFinger.new(
  acct_uri:    "acct:[email protected]",
  hcard_url:   "https://server.example/hcard/users/user",
  seed_url:    "https://server.example/",
  profile_url: "https://server.example/u/user",
  atom_url:    "https://server.example/public/user.atom",
  salmon_url:  "https://server.example/receive/users/0123456789abcdef"
)
xml_string = wf.to_xml

Creating a WebFinger instance from an xml document

wf = WebFinger.from_xml(xml_string)
...
hcard_url = wf.hcard_url
...

See Also:

Constant Summary collapse

REL_HCARD =

hcard_url link relation

"http://microformats.org/profile/hcard".freeze
REL_SEED =

seed_url link relation

"http://joindiaspora.com/seed_location".freeze
REL_PROFILE =
Note:

This might just as well be an Alias instead of a Link.

profile_url link relation.

"http://webfinger.net/rel/profile-page".freeze
REL_ATOM =

atom_url link relation

"http://schemas.google.com/g/2010#updates-from".freeze
REL_SALMON =

salmon_url link relation

"salmon".freeze
REL_SUBSCRIBE =

subscribe_url link relation

"http://ostatus.org/schema/1.0/subscribe".freeze

Constants inherited from Entity

Entity::ENTITY_NAME_REGEX, Entity::INVALID_XML_REGEX

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

class_name, entity_class, entity_name, #to_h

Methods included from PropertiesDSL

#class_props, #default_values, #entity, #find_property_for_xml_name, #missing_props, #optional_props, #property, #resolv_aliases, #xml_names

Methods included from Logging

included

Constructor Details

#initialize(data, additional_data = {}) ⇒ WebFinger

Initializes a new WebFinger Entity

Parameters:

  • data (Hash)

    WebFinger data

  • additional_data (Hash) (defaults to: {})

    additional WebFinger data

Options Hash (additional_data):

  • :aliases (Array<String>)

    additional aliases

  • :properties (Hash)

    properties

  • :links (Array<Hash>)

    additional link elements

See Also:



102
103
104
105
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 102

def initialize(data, additional_data={})
  @additional_data = additional_data
  super(data)
end

Instance Attribute Details

#acct_uriString (readonly)

The Subject element should contain the webfinger address that was asked for. If it does not, then this webfinger profile MUST be ignored.

Returns:

  • (String)


35
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 35

property :acct_uri, :string

#additional_dataHash (readonly)

Additional WebFinger data

Returns:

  • (Hash)

    additional elements



92
93
94
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 92

def additional_data
  @additional_data
end

#atom_urlString (readonly)

This atom feed is an Activity Stream of the user’s public posts. diaspora* pods SHOULD publish an Activity Stream of public posts, but there is currently no requirement to be able to read Activity Streams. Note that this feed MAY also be made available through the PubSubHubbub mechanism by supplying a <link rel=“hub”> in the atom feed itself.

Returns:

  • (String)

    atom feed url

See Also:



58
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 58

property :atom_url, :string, optional: true

#hcard_urlString (readonly)

Returns link to the hCard.

Returns:

  • (String)

    link to the hCard



39
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 39

property :hcard_url, :string

#profile_urlString (readonly)

Returns link to the users profile.

Returns:

  • (String)

    link to the users profile



47
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 47

property :profile_url, :string, optional: true

#salmon_urlString (readonly)

Note:

could be nil

Returns salmon endpoint url.

Returns:

  • (String)

    salmon endpoint url

See Also:



65
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 65

property :salmon_url, :string, optional: true

#seed_urlString (readonly)

Returns link to the pod.

Returns:

  • (String)

    link to the pod



43
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 43

property :seed_url, :string

#subscribe_urlObject (readonly)

This url is used to find another user on the home-pod of the user in the webfinger.



69
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 69

property :subscribe_url, :string, optional: true

Class Method Details

.from_hash(data) ⇒ WebFinger

Creates a WebFinger instance from the given data

Parameters:

  • data (Hash)

    WebFinger data hash

Returns:



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 135

def self.from_hash(data)
  links = data[:links]

  new(
    acct_uri:      data[:subject],

    hcard_url:     parse_link(links, REL_HCARD),
    seed_url:      parse_link(links, REL_SEED),
    profile_url:   parse_link(links, REL_PROFILE),
    atom_url:      parse_link(links, REL_ATOM),
    salmon_url:    parse_link(links, REL_SALMON),

    subscribe_url: parse_link_template(links, REL_SUBSCRIBE)
  )
end

.from_json(webfinger_json) ⇒ WebFinger

Creates a WebFinger instance from the given JSON string

Parameters:

  • webfinger_json (String)

    WebFinger JSON string

Returns:



128
129
130
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 128

def self.from_json(webfinger_json)
  from_hash(XrdDocument.json_data(webfinger_json))
end

.from_xml(webfinger_xml) ⇒ WebFinger

Creates a WebFinger instance from the given XML string

Parameters:

  • webfinger_xml (String)

    WebFinger XML string

Returns:

Raises:

  • (InvalidData)

    if the given XML string is invalid or incomplete



121
122
123
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 121

def self.from_xml(webfinger_xml)
  from_hash(parse_xml_and_validate(webfinger_xml))
end

Instance Method Details

#to_jsonObject



113
114
115
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 113

def to_json
  to_xrd.to_json
end

#to_sString

Returns string representation of this object.

Returns:

  • (String)

    string representation of this object



152
153
154
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 152

def to_s
  "WebFinger:#{acct_uri}"
end

#to_xmlString

Creates the XML string from the current WebFinger instance

Returns:

  • (String)

    XML string



109
110
111
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 109

def to_xml
  to_xrd.to_xml
end