Class: Receitaws::Cnpj

Inherits:
Object
  • Object
show all
Defined in:
lib/receitaws/cnpj.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result = nil) ⇒ Cnpj

Returns a new instance of Cnpj.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/receitaws/cnpj.rb', line 7

def initialize(result=nil)

  if result.nil?
    @status = :error
    @message = "Timeout"
    return self
  end

  if result["status"] == "ERROR"
    @status = :error
    @message = result["message"]
    return self
  end

  @status = :ok
  @nome = result["nome"]
  @uf = result["uf"]
  @telefone = result["telefone"]
  @email = result["email"]
  @fantasia = result["fantasia"]
  @cnpj = result["cnpj"]
  @bairro = result["bairro"]
  @logradouro = result["logradouro"]
  @numero = result["numero"]
  @cep = result["cep"]
  @municipio = result["municipio"]
  @abertura = result["abertura"]
  @data_situacao = result["data_situacao"]
  @situacao = result["situacao"]
  @complemento = result["complemento"]
  @atividades = []
  result["atividade_principal"].each do |atividade|
    @atividades << {code: atividade["code"], text: atividade["text"]}
  end
  result["atividades_secundarias"].each do |atividade|
    @atividades << {code: atividade["code"], text: atividade["text"]}
  end
  @cnaes = @atividades.collect{|a| a[:code].to_s.gsub(/[^0-9A-Za-z]/, '')}

  return self
end

Instance Attribute Details

#aberturaObject (readonly)

Returns the value of attribute abertura.



5
6
7
# File 'lib/receitaws/cnpj.rb', line 5

def abertura
  @abertura
end

#atividadesObject (readonly)

Returns the value of attribute atividades.



5
6
7
# File 'lib/receitaws/cnpj.rb', line 5

def atividades
  @atividades
end

#bairroObject (readonly)

Returns the value of attribute bairro.



5
6
7
# File 'lib/receitaws/cnpj.rb', line 5

def bairro
  @bairro
end

#cepObject (readonly)

Returns the value of attribute cep.



5
6
7
# File 'lib/receitaws/cnpj.rb', line 5

def cep
  @cep
end

#cnaesObject (readonly)

Returns the value of attribute cnaes.



5
6
7
# File 'lib/receitaws/cnpj.rb', line 5

def cnaes
  @cnaes
end

#cnpjObject (readonly)

Returns the value of attribute cnpj.



5
6
7
# File 'lib/receitaws/cnpj.rb', line 5

def cnpj
  @cnpj
end

#complementoObject (readonly)

Returns the value of attribute complemento.



5
6
7
# File 'lib/receitaws/cnpj.rb', line 5

def complemento
  @complemento
end

#data_situacaoObject (readonly)

Returns the value of attribute data_situacao.



5
6
7
# File 'lib/receitaws/cnpj.rb', line 5

def data_situacao
  @data_situacao
end

#emailObject (readonly)

Returns the value of attribute email.



5
6
7
# File 'lib/receitaws/cnpj.rb', line 5

def email
  @email
end

#fantasiaObject (readonly)

Returns the value of attribute fantasia.



5
6
7
# File 'lib/receitaws/cnpj.rb', line 5

def fantasia
  @fantasia
end

#logradouroObject (readonly)

Returns the value of attribute logradouro.



5
6
7
# File 'lib/receitaws/cnpj.rb', line 5

def logradouro
  @logradouro
end

#messageObject (readonly)

Returns the value of attribute message.



5
6
7
# File 'lib/receitaws/cnpj.rb', line 5

def message
  @message
end

#municipioObject (readonly)

Returns the value of attribute municipio.



5
6
7
# File 'lib/receitaws/cnpj.rb', line 5

def municipio
  @municipio
end

#nomeObject (readonly)

Returns the value of attribute nome.



5
6
7
# File 'lib/receitaws/cnpj.rb', line 5

def nome
  @nome
end

#numeroObject (readonly)

Returns the value of attribute numero.



5
6
7
# File 'lib/receitaws/cnpj.rb', line 5

def numero
  @numero
end

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/receitaws/cnpj.rb', line 5

def status
  @status
end

#telefoneObject (readonly)

Returns the value of attribute telefone.



5
6
7
# File 'lib/receitaws/cnpj.rb', line 5

def telefone
  @telefone
end

#ufObject (readonly)

Returns the value of attribute uf.



5
6
7
# File 'lib/receitaws/cnpj.rb', line 5

def uf
  @uf
end