Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/typesense/api_call.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require 'faraday'
require 'oj'
require 'json'

module Typesense
class ApiCall
Expand Down Expand Up @@ -81,7 +81,7 @@ def perform_request(method, endpoint, query_parameters: nil, body_parameters: ni
req.params = query_parameters unless query_parameters.nil?
unless body_parameters.nil?
body = body_parameters
body = Oj.dump(body_parameters, mode: :compat) if headers['Content-Type'] == 'application/json'
body = JSON.dump(body_parameters) if headers['Content-Type'] == 'application/json'
req.body = body
end
end
Expand All @@ -90,7 +90,7 @@ def perform_request(method, endpoint, query_parameters: nil, body_parameters: ni
@logger.debug "Request #{method}:#{uri_for(endpoint, node)} to Node #{node[:index]} was successfully made (at the network layer). response.status was #{response.status}."

parsed_response = if response.headers && (response.headers['content-type'] || '').include?('application/json')
Oj.load(response.body, mode: :compat)
JSON.parse(response.body)
else
response.body
end
Expand Down
8 changes: 4 additions & 4 deletions lib/typesense/documents.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'oj'
require 'json'

module Typesense
class Documents
Expand Down Expand Up @@ -36,7 +36,7 @@ def create_many(documents, options = {})
# @param [Array,String] documents An array of document hashes or a JSONL string of documents.
def import(documents, options = {})
documents_in_jsonl_format = if documents.is_a?(Array)
documents.map { |document| Oj.dump(document, mode: :compat) }.join("\n")
documents.map { |document| JSON.dump(document) }.join("\n")
else
documents
end
Expand All @@ -51,8 +51,8 @@ def import(documents, options = {})

if documents.is_a?(Array)
results_in_jsonl_format.split("\n").map do |r|
Oj.load(r)
rescue Oj::ParseError => e
JSON.parse(r)
rescue JSON::ParserError => e
{
'success' => false,
'exception' => e.class.name,
Expand Down
4 changes: 2 additions & 2 deletions lib/typesense/stemming_dictionaries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(api_call)

def upsert(dict_id, words_and_roots_combinations)
words_and_roots_combinations_in_jsonl = if words_and_roots_combinations.is_a?(Array)
words_and_roots_combinations.map { |combo| Oj.dump(combo, mode: :compat) }.join("\n")
words_and_roots_combinations.map { |combo| JSON.dump(combo) }.join("\n")
else
words_and_roots_combinations
end
Expand All @@ -25,7 +25,7 @@ def upsert(dict_id, words_and_roots_combinations)
)

if words_and_roots_combinations.is_a?(Array)
result_in_jsonl.split("\n").map { |r| Oj.load(r) }
result_in_jsonl.split("\n").map { |r| JSON.parse(r) }
else
result_in_jsonl
end
Expand Down
2 changes: 1 addition & 1 deletion typesense.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ Gem::Specification.new do |spec|

spec.add_dependency 'base64', '~> 0.2.0'
spec.add_dependency 'faraday', '~> 2.8'
spec.add_dependency 'oj', '~> 3.16'
spec.add_dependency 'json', '~> 2.3'
spec.metadata['rubygems_mfa_required'] = 'true'
end