lib/ecoportal/api/common/batch_operation.rb in ecoportal-api-0.2.0 vs lib/ecoportal/api/common/batch_operation.rb in ecoportal-api-0.2.1
- old
+ new
@@ -26,14 +26,15 @@
status = subresponse["status"]
body = subresponse["response"]
method = @operations[idx][:method]
- batch_response = BatchResponse.new(status, body)
- if batch_response.success? && method == "GET"
- callback.call batch_response, @wrapper.new(body)
+ if status == 200 && method == "GET"
+ batch_response = BatchResponse.new(status, body, @wrapper.new(body))
+ callback.call batch_response, batch_response.result
else
+ batch_response = BatchResponse.new(status, body)
callback.call batch_response
end
end
else
raise "Total failure in batch operation"
@@ -59,13 +60,14 @@
callback: block_given? && Proc.new
}
end
def upsert(doc)
- id = get_id(doc)
- body = get_body(doc)
+ id = get_id(doc)
+ external_id = get_external_id(doc)
+ body = get_body(doc)
@operations << {
- path: @base_path + "/" + CGI::escape(id),
+ path: @base_path + "/" + CGI::escape(external_id || id),
method: "POST",
body: body,
callback: block_given? && Proc.new
}
end