# File lib/activerdf_sparql/sparql.rb, line 49
49:         def execute_sparql_query(qs, header=nil, &block)
50:     header = header(nil) if header.nil?
51: 
52:                 # encoding query string in URL
53:                 url = "#@url?query=#{CGI.escape(qs)}"
54:     #url += "&content-type=#{CGI.escape('application/sparql-results+xml')}" if @yars2
55:     url = url.gsub("DISTINCT", "") if @yars2
56:                 $activerdflog.debug "executing: requesting #{url}"
57: 
58:     # querying sparql endpoint
59:                 response = ''
60:                 begin 
61:                   open(url, header) do |f|
62:                                 response = f.read
63:                         end
64:                 rescue OpenURI::HTTPError => e
65:                         raise ActiveRdfError, "could not query SPARQL endpoint, server said: #{e}"
66:                         return []
67:                 rescue Errno::ECONNREFUSED
68:                         raise ActiveRdfError, "connection refused on SPARQL endpoint #@url"
69:                         return []
70:                end
71:     $activerdflog.debug "response:\n#{response}"
72: 
73:     # we parse content depending on the result format
74:     results = case @result_format
75:                                                   when :json 
76:                                                                 parse_json(response)
77:                                                   when :xml, :sparql_xml
78:                                                                  parse_xml(response)
79:                                                   end
80: 
81:     if block_given?
82:       results.each do |*clauses|
83:         yield(*clauses)
84:       end
85:     else
86:       results
87:     end
88:         end