summaryrefslogtreecommitdiff
path: root/lib/webfinger
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2014-04-08 14:22:56 +0200
committerAzul <azul@leap.se>2014-04-08 14:30:07 +0200
commit9776dd10fc60efde38946588d0955c406f6c1f5e (patch)
treea77a83984e39a72cd1bb2f8f89c6d9646de117d7 /lib/webfinger
parentb6d14dc19dd350a807826e3e097738a36613e083 (diff)
move users: config and lib
Diffstat (limited to 'lib/webfinger')
-rw-r--r--lib/webfinger/host_meta_presenter.rb30
-rw-r--r--lib/webfinger/user_presenter.rb35
2 files changed, 65 insertions, 0 deletions
diff --git a/lib/webfinger/host_meta_presenter.rb b/lib/webfinger/host_meta_presenter.rb
new file mode 100644
index 0000000..84ab7a9
--- /dev/null
+++ b/lib/webfinger/host_meta_presenter.rb
@@ -0,0 +1,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
diff --git a/lib/webfinger/user_presenter.rb b/lib/webfinger/user_presenter.rb
new file mode 100644
index 0000000..329f477
--- /dev/null
+++ b/lib/webfinger/user_presenter.rb
@@ -0,0 +1,35 @@
+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,
+ links: links
+ }.to_json(options)
+ end
+
+ def subject
+ "acct:#{@user.email_address}"
+ 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