ibge-localidades 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/ibge-localidades.rb +47 -0
- data/lib/ibge_localidades/cidade.rb +17 -0
- data/lib/ibge_localidades/estado.rb +18 -0
- data/lib/ibge_localidades/mesorregiao.rb +17 -0
- data/lib/ibge_localidades/microrregiao.rb +17 -0
- data/lib/ibge_localidades/regiao.rb +15 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5b4f5cd87204648efae4de0ef0058832be3f99f3e84630623ef67cba63334781
|
4
|
+
data.tar.gz: 446cd679598cec86718c4badb73779853588466452dab65ebde898b8392d2738
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9ebca9b5bc7579ebf63ebc44c15710b540d9f028284118763b7a3df476b35512abe6e160f23bd18f6e40a17e78295146527da297e9842e9243bf0caa59522654
|
7
|
+
data.tar.gz: 2412c3ef4568fbfe7ce4a0fefe03fcf67ba903124ed85f63c4805d44426b613826a70bce078294b80a2dc53bbaaa3bed9865029f713f3180b291fe8c365180d2
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module IbgeLocalidades
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
VERSION = 'v1'
|
7
|
+
MAIN_URL = 'https://servicodados.ibge.gov.br/api/' + VERSION + '/localidades'
|
8
|
+
|
9
|
+
def get(url)
|
10
|
+
uri = URI(MAIN_URL + url)
|
11
|
+
resposta = JSON.parse(Net::HTTP.get(uri))
|
12
|
+
|
13
|
+
return resposta
|
14
|
+
rescue StandardError => e
|
15
|
+
return { 'error' => 'Ocorreu um erro.',
|
16
|
+
'backtrace'=> e.backtrace.join("\n") }
|
17
|
+
end
|
18
|
+
|
19
|
+
def as_objects resposta
|
20
|
+
return self.new(resposta) if resposta.is_a? Hash
|
21
|
+
resposta.each_with_object([]) do |obj, arr|
|
22
|
+
arr << self.new(obj)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def buscar_por_relacionamento *args
|
27
|
+
args.each do |relacionamento|
|
28
|
+
define_singleton_method "listar_por_#{relacionamento}" do |id|
|
29
|
+
as_objects get(Module.const_get("IbgeLocalidades::#{relacionamento.capitalize}::PATH") + id + self::PATH)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def listar
|
35
|
+
as_objects get(self::PATH)
|
36
|
+
end
|
37
|
+
|
38
|
+
def find_by_id id
|
39
|
+
as_objects get(self::PATH + id)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
require 'ibge_localidades/cidade.rb'
|
44
|
+
require 'ibge_localidades/mesorregiao.rb'
|
45
|
+
require 'ibge_localidades/microrregiao.rb'
|
46
|
+
require 'ibge_localidades/regiao.rb'
|
47
|
+
require 'ibge_localidades/estado.rb'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class IbgeLocalidades::Cidade
|
2
|
+
|
3
|
+
extend IbgeLocalidades
|
4
|
+
|
5
|
+
attr_reader :id, :nome, :microrregiao
|
6
|
+
|
7
|
+
buscar_por_relacionamento "mesorregiao", "microrregiao", "regiao", "estado"
|
8
|
+
|
9
|
+
PATH = "/municipios/"
|
10
|
+
|
11
|
+
def initialize(params={})
|
12
|
+
@id = params["id"]
|
13
|
+
@nome = params["nome"]
|
14
|
+
@microrregiao = ::IbgeLocalidades::Microrregiao.new(params["microrregiao"])
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class IbgeLocalidades::Estado
|
2
|
+
|
3
|
+
extend IbgeLocalidades
|
4
|
+
|
5
|
+
attr_reader :id, :nome, :sigla, :regiao
|
6
|
+
|
7
|
+
buscar_por_relacionamento "regiao"
|
8
|
+
|
9
|
+
PATH = "/estados/"
|
10
|
+
|
11
|
+
def initialize(params={})
|
12
|
+
@id = params["id"]
|
13
|
+
@nome = params["nome"]
|
14
|
+
@sigla = params["sigla"]
|
15
|
+
@regiao = ::IbgeLocalidades::Regiao.new(params["regiao"])
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class IbgeLocalidades::Mesorregiao
|
2
|
+
|
3
|
+
extend IbgeLocalidades
|
4
|
+
|
5
|
+
attr_reader :id, :nome, :estado
|
6
|
+
|
7
|
+
buscar_por_relacionamento "regiao", "estado"
|
8
|
+
|
9
|
+
PATH = "/mesorregioes/"
|
10
|
+
|
11
|
+
def initialize(params={})
|
12
|
+
@id = params["id"]
|
13
|
+
@nome = params["nome"]
|
14
|
+
@estado = ::IbgeLocalidades::Estado.new(params["UF"])
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class IbgeLocalidades::Microrregiao
|
2
|
+
|
3
|
+
extend IbgeLocalidades
|
4
|
+
|
5
|
+
attr_reader :id, :nome, :mesorregiao
|
6
|
+
|
7
|
+
buscar_por_relacionamento "mesorregiao", "regiao", "estado"
|
8
|
+
|
9
|
+
PATH = "/microrregioes/"
|
10
|
+
|
11
|
+
def initialize(params={})
|
12
|
+
@id = params["id"]
|
13
|
+
@nome = params["nome"]
|
14
|
+
@mesorregiao = ::IbgeLocalidades::Mesorregiao.new(params["mesorregiao"])
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ibge-localidades
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Victor Palombo Silvano
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Uma gem criada para acessar os dados da API do IBGE (cidades, estados,
|
14
|
+
regiões etc)
|
15
|
+
email: victorpsilvano@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/ibge-localidades.rb
|
21
|
+
- lib/ibge_localidades/cidade.rb
|
22
|
+
- lib/ibge_localidades/estado.rb
|
23
|
+
- lib/ibge_localidades/mesorregiao.rb
|
24
|
+
- lib/ibge_localidades/microrregiao.rb
|
25
|
+
- lib/ibge_localidades/regiao.rb
|
26
|
+
homepage: https://rubygems.org/gems/ibge-localidades
|
27
|
+
licenses:
|
28
|
+
- MIT
|
29
|
+
metadata: {}
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubygems_version: 3.0.3
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: Uma gem criada para acessar os dados da API do IBGE (cidades, estados, regiões
|
49
|
+
etc)
|
50
|
+
test_files: []
|