lib/targetdata/api/pf.rb in targetdata-0.2.1 vs lib/targetdata/api/pf.rb in targetdata-0.3.0
- old
+ new
@@ -14,16 +14,26 @@
end
private
def hash_person string_body
parsed = JSON.parse(string_body)
-
raise Targetdata::Errors::PersonNotFound unless person_found?(parsed)
- parsed["result"].first["pessoa"]["cadastral"]
+ parse_person_hash parsed
end
def person_found? hash
!hash["result"].empty?
+ end
+
+ def parse_person_hash hash
+ pessoa = hash["result"].first["pessoa"]
+ pessoa["cadastral"]["email"] = nil
+
+ if hash["report"]["email"] >= 1
+ pessoa["cadastral"]["email"] = pessoa["contato"]["email"].first["email"]
+ end
+
+ pessoa["cadastral"]
end
end
end
end
\ No newline at end of file