lib/marklogic/collection.rb in marklogic-0.0.9 vs lib/marklogic/collection.rb in marklogic-0.0.10
- old
+ new
@@ -26,19 +26,19 @@
def save(doc)
if (doc.is_a?(Array))
docs = {}
doc.each do |d|
- docs[doc_uri(d)] = JSON.generate(d)
+ docs[doc_uri(d)] = ::Oj.dump(d, mode: :compat)
end
body = build_multipart_body(docs)
response = @database.connection.post_multipart("/v1/documents", body)
raise Exception.new("Invalid response: #{response.code.to_i}, #{response.body}\n") unless response.code.to_i == 200
else
uri = doc_uri(doc)
url = "/v1/documents?uri=#{uri}&format=json&collection=#{collection}"
- json = JSON.generate(doc)
+ json = ::Oj.dump(doc, mode: :compat)
response = @database.connection.put(url, json)
raise Exception.new("Invalid response: #{response.code.to_i}, #{response.body}\n") unless [201, 204].include? response.code.to_i
doc[:_id] || doc[:id] || doc['_id'] || doc['id']
end
end
@@ -251,10 +251,10 @@
def build_multipart_body(docs, boundary = "BOUNDARY")
tmp = ""
# collection
- metadata = JSON.generate({ collections: [ collection ]})
+ metadata = ::Oj.dump({ collections: [ collection ]}, mode: :compat)
tmp << %Q{--#{boundary}\r\n}
tmp << %Q{Content-Type: application/json\r\n}
tmp << %Q{Content-Disposition: inline; category=metadata\r\n}
tmp << %Q{Content-Length: #{metadata.size}\r\n\r\n}
tmp << metadata