Skip to content

Instantly share code, notes, and snippets.

@bhuga
Forked from bad/query-test-case.rb
Created December 6, 2010 01:52
Show Gist options
  • Save bhuga/729706 to your computer and use it in GitHub Desktop.
Save bhuga/729706 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'ruby-debug'
require 'spira'
require 'rdf/rdfxml'
require 'sparql/client'
class Actor
include Spira::Resource
base_uri 'http://data.linkedmdb.org/resource/actor/'
type URI.new 'http://data.linkedmdb.org/resource/movie/actor'
default_vocabulary URI.new('http://data.linkedmdb.org/resource/movie/')
property :actor_id, :type => Integer
property :actor_name, :type => String
property :label, :predicate => RDFS.label, :type => String
property :page, :predicate => FOAF.page, :type => URI
has_many :performance, :type => URI
end
lmdb = SPARQL::Client::Repository.new 'http://data.linkedmdb.org/sparql'
Spira.add_repository! :default, lmdb
Debugger.start
Debugger.add_breakpoint('SPARQL::Client', 'query')
#Debugger.add_breakpoint('SPARQL::Client', 'get')
js = Actor.for(9)
#
# this will call SPARQL::Client#query twice for each property with a
# CONSTRUCT query
#
puts js.actor_name
--- lib/sparql/client.rb.orig 2010-10-19 14:35:53.000000000 +0000
+++ lib/sparql/client.rb 2010-10-19 14:42:59.000000000 +0000
@@ -28,7 +28,8 @@
# @param [Hash{Symbol => Object}] options
def initialize(url, options = {}, &block)
@url, @options = RDF::URI.new(url.to_s), options
- @headers = {'Accept' => "#{RESULT_JSON}, #{RESULT_XML}, text/plain"}
+ @headers = {'Accept' => [RESULT_JSON, RESULT_XML,
+ RDF::Format.content_types.collect { |k,v| k.to_s }].join(', ')}
if block_given?
case block.arity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment