/
grabmytriples.rb
41 lines (36 loc) · 1.01 KB
/
grabmytriples.rb
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
41
require 'rubygems'
require 'net/http'
require 'uri'
require 'sinatra'
require 'erb'
def set(endpoint, graph, rdf)
puts "#{endpoint} -> #{graph} - #{rdf.size}"
http = Net::HTTP.new(endpoint.host, endpoint.port)
http.start do |h|
request = Net::HTTP::Put.new(endpoint.path + graph)
request.body = rdf
response = h.request(request)
end
end
def get_rdf(url, content_type='application/rdf+xml')
req = Net::HTTP::Get.new(url.path)
req.add_field('Accept', content_type)
res = Net::HTTP.start(url.host, url.port) {|http|
http.request(req)
}
end
def process(store, url, graph=nil)
endpoint, uri = URI.parse(store), URI.parse(url)
res = get_rdf(uri)
p set(endpoint, (graph || url), res.body)
end
get '/set' do
store = params['store'] || 'http://dbtune.org/beancounter/data/'
process(store, params['url'], params['graph'])
redirect params['url']
end
get '/' do
erb %[
<a href="javascript:location.href='http://grabmytriples.heroku.com/set?url='+location.href;">grabmytriples</a>
]
end