summaryrefslogtreecommitdiff
path: root/users/lib/webfinger/user_presenter.rb
blob: 41153a87d36598fb2d53db6f2251a7ef3506a9e1 (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
31
32
33
34
35
36
37
38
39
40
class Webfinger::UserPresenter
  include Rails.application.routes.url_helpers
  attr_accessor :user

  def initialize(user, request)
    @user = user
    @request = request
  end

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

  def subject
    "acct:#{@user.email_address}"
  end

  def aliases
    [ user_url(@user, :host => @request.host) ]
  end

  def links
    links = {}
    links[:public_key] = { type: 'PGP', href: key } if key
    return links
  end

  protected

  def key
    if @user.public_key.present?
      Base64.encode64(@user.public_key.to_s)
    end
  end

end