summaryrefslogtreecommitdiff
path: root/users/lib/webfinger/host_meta_presenter.rb
blob: 84ab7a959de8caf24b4214a74b47418ba6c24d7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'uri'

class Webfinger::HostMetaPresenter
  def initialize(request)
    @request = request
  end

  def to_json(options = {})
    {
      subject: subject,
      links: links
    }.to_json(options)
  end

  def subject
    url = URI.parse(@request.url)
    url.path = ''
    url.to_s
  end

  def links
    { lrdd: { type: 'application/xrd+xml', template: webfinger_template } }
  end

  protected

  def webfinger_template(path = 'webfinger', query_param='q')
    "#{subject}/#{path}?#{query_param}={uri}"
  end
end