lib/search_flip/bulk.rb in search_flip-2.0.0.beta2 vs lib/search_flip/bulk.rb in search_flip-2.0.0.beta3

- old
+ new

@@ -12,11 +12,11 @@ # end class Bulk class Error < StandardError; end - attr_accessor :url, :count, :options, :ignore_errors + attr_accessor :url, :count, :options, :http_client, :ignore_errors # Builds and yields a new Bulk object, ie initiates the buffer, yields, # sends batches of records each time the buffer is full, and sends a final # batch after the yielded code returns and there are still documents # present within the buffer. @@ -38,15 +38,18 @@ # ignored. If you eg want to ignore errors resulting from conflicts, # you can specify to ignore 409 here. # @option options raise [Boolean] If you want the bulk requests to never # raise any exceptions (fire and forget), you can pass false here. # Default is true. + # @option options http_client [SearchFlip::HTTPClient] An optional http + # client instance def initialize(url, count = 1_000, options = {}) self.url = url self.count = count self.options = options + self.http_client = options[:http_client] || SearchFlip::HTTPClient.new self.ignore_errors = Array(options[:ignore_errors]).to_set if options[:ignore_errors] init yield self @@ -112,10 +115,10 @@ @num = 0 end def upload response = - SearchFlip::HTTPClient + http_client .headers(accept: "application/json", content_type: "application/x-ndjson") .put(url, body: @payload, params: ignore_errors ? {} : { filter_path: "errors" }) return if options[:raise] == false