rdf-sesame 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e058f96f2674ca2473f1c1287cb9956d2dd40ec3
4
- data.tar.gz: 16cfeacf6604c3808414652904e0f15550759fdd
3
+ metadata.gz: c2f329d7861b08b851a2eccae110ace25fe424e6
4
+ data.tar.gz: f457fb5e4db30918ebaf472fa8c574ad7236b932
5
5
  SHA512:
6
- metadata.gz: 1f7b9ed8834936df2bf5da9260136fa230e88dcb8b8ad9727b2316a66103b5d03f640e0059b71744c542ce84ebb288c0b4b9846c4ed61d8a10e77e813cae6d20
7
- data.tar.gz: 7e751f8d6db397afb38ecbe1d4654b55abfe51d9df03decdd49717cca91ead4f5ecc58342bd64c148fb41304839672747c4d44f492c55e90cb2db1ad8a6bbf98
6
+ metadata.gz: 24201ab9073a36d5f8d715f42cfb298edae092de72697534220dc637b2aad14008cbe74389c156fbcfa1baae7002ff66769cc1da7ebe12e99a7c064d00cf488d
7
+ data.tar.gz: f8639b735212b6da34887e18832fadd961ec7290935793c59778907882dcf46b475e03837d031a1f74aec1af57368caea9a004e4276f837c666c0bfdf5986bde
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.1
1
+ 2.0.2
@@ -321,7 +321,9 @@ module RDF::Sesame
321
321
  if queryLn == 'sparql' and options[:format].nil? and query =~ /\bconstruct\b/i
322
322
  options[:format] = Server::ACCEPT_NTRIPLES
323
323
  end
324
+
324
325
  options[:format] = Server::ACCEPT_JSON unless options[:format]
326
+ options[:parsing] = :full unless options[:parsing]
325
327
 
326
328
  parameters = { :query => query, :queryLn => queryLn, :infer => options[:infer] }
327
329
 
@@ -339,7 +341,12 @@ module RDF::Sesame
339
341
  server.get(url, options[:format])
340
342
  end
341
343
 
342
- results = parse_response(response)
344
+ results = if (options[:parsing] == :full)
345
+ parse_response(response)
346
+ else
347
+ raw_parse_response(response)
348
+ end
349
+
343
350
  if block_given?
344
351
  results.each {|s| yield s }
345
352
  else
@@ -480,13 +487,41 @@ module RDF::Sesame
480
487
  end
481
488
  end
482
489
 
490
+ ##
491
+ # @param [Net::HTTPSuccess] response
492
+ # @param [Hash{Symbol => Object}] options
493
+ # @return [Object]
494
+ def raw_parse_response(response, options = {})
495
+ case content_type = options[:content_type] || response.content_type
496
+ when Server::RESULT_BOOL
497
+ response.body == 'true'
498
+ when Server::RESULT_JSON, Server::RESULT_RDF_JSON
499
+ self.class.parse_json(response.body)
500
+ when Server::RESULT_XML
501
+ self.class.parse_xml(response.body)
502
+ else
503
+ response.body
504
+ end
505
+ end
506
+
507
+ def self.parse_json(json)
508
+ require 'json' unless defined?(::JSON)
509
+ json = JSON.parse(json.to_s) unless json.is_a?(Hash)
510
+ end
511
+
512
+ def self.parse_xml(xml)
513
+ xml.force_encoding(::Encoding::UTF_8) if xml.respond_to?(:force_encoding)
514
+ require 'rexml/document' unless defined?(::REXML::Document)
515
+ xml = REXML::Document.new(xml).root unless xml.is_a?(REXML::Element)
516
+ xml
517
+ end
518
+
483
519
  ##
484
520
  # @param [String, Hash] json
485
521
  # @return [<RDF::Query::Solutions>]
486
522
  # @see http://www.w3.org/TR/rdf-sparql-json-res/#results
487
523
  def self.parse_json_bindings(json, nodes = {})
488
- require 'json' unless defined?(::JSON)
489
- json = JSON.parse(json.to_s) unless json.is_a?(Hash)
524
+ json = self.parse_json(json)
490
525
 
491
526
  case
492
527
  when json['boolean']
@@ -526,9 +561,7 @@ module RDF::Sesame
526
561
  # @return [<RDF::Query::Solutions>]
527
562
  # @see http://www.w3.org/TR/rdf-sparql-json-res/#results
528
563
  def self.parse_xml_bindings(xml, nodes = {})
529
- xml.force_encoding(::Encoding::UTF_8) if xml.respond_to?(:force_encoding)
530
- require 'rexml/document' unless defined?(::REXML::Document)
531
- xml = REXML::Document.new(xml).root unless xml.is_a?(REXML::Element)
564
+ xml = self.parse_xml(xml)
532
565
 
533
566
  case
534
567
  when boolean = xml.elements['boolean']
@@ -589,7 +622,7 @@ module RDF::Sesame
589
622
  if c == 'null' or !c
590
623
  c
591
624
  else
592
- RDF::NTriples.serialize(RDF::URI.new(c))
625
+ RDF::NTriples.serialize(RDF::URI(c))
593
626
  end
594
627
  end
595
628
 
@@ -42,6 +42,7 @@ module RDF::Sesame
42
42
  class Server
43
43
  include Enumerable
44
44
 
45
+ ACCEPT_RDF_JSON = {'Accept' => 'application/rdf+json'}.freeze
45
46
  ACCEPT_JSON = {'Accept' => 'application/sparql-results+json'}.freeze
46
47
  ACCEPT_NTRIPLES = {'Accept' => 'text/plain'}.freeze
47
48
  ACCEPT_XML = {'Accept' => 'application/sparql-results+xml'}.freeze
@@ -60,6 +61,7 @@ module RDF::Sesame
60
61
  RESULT_BOOL = 'text/boolean'.freeze
61
62
  RESULT_JSON = 'application/sparql-results+json'.freeze
62
63
  RESULT_XML = 'application/sparql-results+xml'.freeze
64
+ RESULT_RDF_JSON = 'application/rdf+json'.freeze
63
65
 
64
66
  # @return [Connection]
65
67
  attr_reader :connection
@@ -2,7 +2,7 @@ module RDF; module Sesame
2
2
  module VERSION
3
3
  MAJOR = 2
4
4
  MINOR = 0
5
- TINY = 1
5
+ TINY = 2
6
6
  EXTRA = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, EXTRA].compact.join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-sesame
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arto Bendiken
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-01-13 00:00:00.000000000 Z
12
+ date: 2017-03-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdf
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  requirements: []
134
134
  rubyforge_project: rdf
135
- rubygems_version: 2.4.5.1
135
+ rubygems_version: 2.4.5.2
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: Sesame 2.0 adapter for RDF.rb.