summaryrefslogtreecommitdiff
path: root/users/lib/webfinger/host_meta_presenter.rb
blob: b48729c83326fecabe1dc4415bc35d99819e0709 (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
require 'uri'

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

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

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

  def to_json(options)
    {
      subject: subject,
      links: {
        lrdd: { type: 'application/xrd+xml', template: webfinger_template }
      }
    }.to_json(options)
  end
end