lib/inquisitio/indexer.rb in inquisitio-0.1.6 vs lib/inquisitio/indexer.rb in inquisitio-0.1.7

- old
+ new

@@ -14,16 +14,15 @@ @documents = documents end def index Inquisitio.config.logger.info "Indexer posting to #{batch_index_url} body: #{body}" - response = Excon.post(batch_index_url, - :body => body, - :headers => {"Content-Type" =>"application/json"}) - Inquisitio.config.logger.info "Response - status: #{response.status} body: #{response.body}" - raise InquisitioError.new("Index failed with status code: #{response.status} Message: #{response.body}") unless response.status == 200 - response.body + if Inquisitio.config.dry_run + Inquisitio.config.logger.info "Skipping POST as running in dry-run mode" + else + post_to_endpoint + end end private def body @@ -32,7 +31,17 @@ end def batch_index_url "#{Inquisitio.config.document_endpoint}/2011-02-01/documents/batch" end + + def post_to_endpoint + response = Excon.post(batch_index_url, + :body => body, + :headers => {"Content-Type" =>"application/json"}) + Inquisitio.config.logger.info "Response - status: #{response.status} body: #{response.body}" + raise InquisitioError.new("Index failed with status code: #{response.status} Message: #{response.body}") unless response.status == 200 + response.body + end + end end