Class: Riddl::Utils::Turtle::GetQuery

Inherits:
Implementation show all
Defined in:
lib/ruby/riddl/utils/turtle.rb

Overview

}}}

Instance Method Summary collapse

Methods inherited from Implementation

#headers, #initialize, #status

Constructor Details

This class inherits a constructor from Riddl::Implementation

Instance Method Details

#responseObject

{{{



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ruby/riddl/utils/turtle.rb', line 50

def response #{{{
  a = RDF::Smart.new(@a[0])
  if a.namespaces.size > 0
    ns = ""
    if @r[-1].start_with?(":")
      if (!(a.namespaces[nil]))
        return Riddl::Parameter::Complex.new "value","text/plain", "Error parsing namespaces"
      end
      return Riddl::Parameter::Complex.new "value","application/json", JSON::pretty_generate(a.execute("PREFIX : <" + a.namespaces[nil] + "> SELECT * WHERE { #{@r[-1]} ?p ?o}"))
    else
      if (!(a.namespaces[@r[-1].partition(":")[0]]))
        return Riddl::Parameter::Complex.new "value","text/plain", "Error parsing namespaces"
      end
      return Riddl::Parameter::Complex.new "value","application/json", JSON::pretty_generate(a.execute("PREFIX #{@r[-1].partition(":")[0]}: <" + a.namespaces[@r[-1].partition(":")[0]] + "> SELECT * WHERE { #{@r[-1]} ?p ?o}"))
    end 
  end
  Riddl::Parameter::Complex.new "list","application/json", JSON::pretty_generate(a.execute("select * where {#{@r[-1]} ?p ?o}"))
end