Sha256: a818d937b646abb7cb3237449e05b59fd237a79d234db25073b1b51dbc995aca

Contents?: true

Size: 926 Bytes

Versions: 3

Compression:

Stored size: 926 Bytes

Contents

module Targetdata
  module Api
    class Pf
      include Auth
      include Requester

      def initialize cpf
        @cpf = cpf
      end
      
      def person
        response = get_person
        Entities::Person.new hash_person(response.body.to_s)
      end

      private
        def hash_person string_body
          parsed = JSON.parse(string_body)
          raise Targetdata::Errors::PersonNotFound unless person_found?(parsed)
          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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
targetdata-0.4.0 lib/targetdata/api/pf.rb
targetdata-0.3.1 lib/targetdata/api/pf.rb
targetdata-0.3.0 lib/targetdata/api/pf.rb