Commit dd80b7dcffc11134687d1c9ff9459f8ba1ea9907
1 parent
fedb0d62
Exists in
federation_webfinger
and in
1 other branch
Adding uri to webfinger resource
Signed-off-by: Thiago Ribeiro <thiagitosouza@gmail.com>
Showing
1 changed file
with
32 additions
and
3 deletions
Show diff stats
lib/noosfero/api/federation/webfinger.rb
1 | +require 'active_support/inflector' | |
1 | 2 | module Noosfero |
2 | 3 | module API |
3 | 4 | module Federation |
... | ... | @@ -27,12 +28,29 @@ def valid_domain? |
27 | 28 | end |
28 | 29 | end |
29 | 30 | |
31 | +def valid_uri?(url) | |
32 | + uri = URI.parse(url) | |
33 | + uri.kind_of?(URI::HTTP) | |
34 | + rescue URI::BadURIError | |
35 | + false | |
36 | + rescue URI::InvalidURIError | |
37 | + false | |
38 | +end | |
39 | + | |
40 | +def entity_exists?(uri) | |
41 | + possible_entity = uri.split('/') | |
42 | + possible_entity.map! {|entity| "#{entity}s"} | |
43 | + ( ActiveRecord::Base.connection.tables & possible_entity ) | |
44 | + rescue ActiveRecord::RecordNotFound | |
45 | + false | |
46 | +end | |
47 | + | |
30 | 48 | def generate_jrd |
49 | + result = {} | |
31 | 50 | if valid_domain? && request_acct? |
32 | - result = {} | |
33 | 51 | result = acct_hash |
34 | - else | |
35 | - "This Domain this not exist in this envinronment" | |
52 | + elsif valid_uri?(params[:resource]) | |
53 | + result = uri_hash | |
36 | 54 | end |
37 | 55 | end |
38 | 56 | |
... | ... | @@ -46,3 +64,14 @@ def acct_hash |
46 | 64 | acct[:properties] = Person.find_by_identifier(extract_person_identifier) |
47 | 65 | acct |
48 | 66 | end |
67 | + | |
68 | +def uri_hash | |
69 | + uri = {} | |
70 | + uri[:subject] = params[:resource] | |
71 | + entity = entity_exists?(params[:resource]) | |
72 | + noosfero_entity = ActiveSupport::Inflector.classify(entity) | |
73 | + id = params[:resource].split('/').last.to_i | |
74 | + uri[:properties] = entity.first.classify.constantize.find(id) | |
75 | + puts uri.inspect | |
76 | + uri | |
77 | +end | ... | ... |