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 RFC 7033.

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"
)
json_string = wf.to_json

Creating a WebFinger instance from an JSON document

wf = WebFinger.from_json(json_string)
...
hcard_url = wf.hcard_url
...

See Also:

Constant Summary collapse

REL_HCARD =

hcard_url link relation

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

seed_url link relation

"http://joindiaspora.com/seed_location"
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"
REL_ATOM =

atom_url link relation

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

salmon_url link relation

"salmon"
REL_SUBSCRIBE =

subscribe_url link relation

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

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, #missing_props, #optional_props, #property, #resolv_aliases

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:



99
100
101
102
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 99

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)


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

property :acct_uri, :string

#additional_dataHash (readonly)

Additional WebFinger data

Returns:

  • (Hash)

    additional elements



89
90
91
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 89

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:



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

property :atom_url, :string, optional: true

#hcard_urlString (readonly)

Returns link to the hCard.

Returns:

  • (String)

    link to the hCard



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

property :hcard_url, :string

#profile_urlString (readonly)

Returns link to the users profile.

Returns:

  • (String)

    link to the users profile



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

property :profile_url, :string, optional: true

#salmon_urlString (readonly)

Note:

could be nil

Returns salmon endpoint url.

Returns:

  • (String)

    salmon endpoint url

See Also:



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

property :salmon_url, :string, optional: true

#seed_urlString (readonly)

Returns link to the pod.

Returns:

  • (String)

    link to the pod



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

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.



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

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:



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

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:



125
126
127
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 125

def self.from_json(webfinger_json)
  from_hash(parse_json_and_validate(webfinger_json))
end

Instance Method Details

#to_json(*_args) ⇒ String

Creates the JSON string from the current WebFinger instance

Returns:

  • (String)

    JSON string



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

def to_json(*_args)
  to_xrd.to_json
end

#to_sString

Returns string representation of this object.

Returns:

  • (String)

    string representation of this object



149
150
151
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 149

def to_s
  "WebFinger:#{acct_uri}"
end