first trial of linked data map response

This commit is contained in:
Connor Turland 2015-01-24 16:37:40 -05:00
parent 1a4a2df6c6
commit e22c3f33e9
3 changed files with 55 additions and 0 deletions

View file

@ -1,4 +1,5 @@
class MapsController < ApplicationController
include MapsHelper
before_filter :require_user, only: [:create, :update, :screenshot, :destroy]
@ -123,6 +124,21 @@ class MapsController < ApplicationController
end
end
# GET maps/:id/ld
def ld
@current = current_user
@map = Map.find(params[:id]).authorize_to_show(@current)
if not @map
redirect_to root_url, notice: "Access denied. That map is private." and return
end
respond_to do |format|
format.json { render json: linkeddata(@map) }
end
end
# POST maps
def create

View file

@ -33,4 +33,39 @@ module MapsHelper
return temp
end
def linkeddata(map)
@alltopics = map.topics.delete_if {|t| t.permission == "private" && (!authenticated? || (authenticated? && @current.id != t.user_id)) }
js = Hash.new()
js['@context'] = { "@vocab" => "http://schema.org/", "mm" => "http://ns.metamaps.cc/", "mmc" => "http://metamaps.cc/metacodes/" }
js['@id'] = "http://metamaps.cc/maps/" + map.id.to_s
js['@type'] = [ "CreativeWork", "mm:Metamap" ]
js['name'] = map.name
js['description'] = map.desc
graph = []
@alltopics.each do |t|
topic = Hash.new()
topic['@id'] = 'http://metamaps.cc/topics/' + t.id.to_s
topic['@type'] = [
'mmc:' + t.metacode_id.to_s
]
topic['name'] = t.name
t.synapses2.each do |s|
topic['http://metamaps.cc/synapses/' + s.id.to_s] = [ 'http://metamaps.cc/topics/' + s.node1_id.to_s ]
end
graph.push(topic)
end
js['@graph'] = graph
return js
end
end

View file

@ -26,6 +26,10 @@ Metamaps::Application.routes.draw do
match 'explore/mapper/:id', to: 'maps#index', via: :get, as: :usermaps
resources :maps, except: [:new, :edit]
match 'maps/:id/contains', to: 'maps#contains', via: :get, as: :contains
# for linked data structure
match 'maps/:id/ld', to: 'maps#ld', via: :get, as: :ld
match 'maps/:id/upload_screenshot', to: 'maps#screenshot', via: :post, as: :screenshot
devise_for :users, controllers: { registrations: 'users/registrations', passwords: 'users/passwords', sessions: 'devise/sessions' }, :skip => [:sessions]