lib/ecoportal/api/v1/people.rb in ecoportal-api-0.1.12 vs lib/ecoportal/api/v1/people.rb in ecoportal-api-0.2.0

- old
+ new

@@ -45,13 +45,14 @@ body = get_body(doc) @client.post("/people", data: body) end def upsert(doc) - body = get_body(doc) - id = get_id(doc) - @client.post("/people/"+CGI::escape(id), data: body) + body = get_body(doc) + id = get_id(doc) + external_id = get_external_id(doc) + @client.post("/people/"+CGI::escape(external_id || id), data: body) end def batch operation = Common::BatchOperation.new("/people", person_class) yield operation @@ -71,29 +72,9 @@ private def person_class V1::Person - end - - def get_body(doc) - if doc.respond_to?(:as_update) - doc.as_update - elsif doc.respond_to?(:as_json) - doc.as_json - else - doc - end - end - def get_id(doc) - id = nil - id ||= doc.id if doc.respond_to?(:id) - id ||= doc.external_id if doc.respond_to?(:external_id) - id ||= doc["id"] if doc.is_a?(Hash) - id ||= doc["external_id"] if doc.is_a?(Hash) - id ||= doc if doc.is_a?(String) - id or raise "No ID has been given!" - id end end end end end