congrega_plenum 0.2.0 → 0.3.0
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 +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +18 -7
- data/lib/catalog_page.rb +54 -0
- data/lib/client.rb +7 -0
- data/lib/congrega_plenum.rb +1 -0
- data/lib/modules/congressmen_service.rb +6 -0
- data/lib/modules/legislatures_service.rb +6 -0
- data/lib/modules/parties_service.rb +6 -0
- data/lib/version.rb +1 -1
- data/sig/congrega_plenum.rbs +11 -0
- metadata +6 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4012de687b93b47fb723add5d69ace9bb71819fc46897d7b76e16d6e650a6d72
|
|
4
|
+
data.tar.gz: b56150bdc2d785d0c1795b5ddbd44243838dd88e7a859fd3e2d650d1a0fad13a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7c3fae36ac1cc0f9d64b952025998277ee1e6ff8fd407f631aef6be396869a7441524cb4ee777d5e57467af63bdfbe47e6f610025f187ca6d26f24b99d0471cd
|
|
7
|
+
data.tar.gz: fbec4444313b03e45c5e5ed8a9ec7092f1290709c4f10bff70117bf481ddcc7335592f92e5a788f733d4def19320de04ae19f050ef9f1c4a5f14769b0d52b1af
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,14 @@ versionamento seguirá [Semantic Versioning](https://semver.org/lang/pt-BR/).
|
|
|
6
6
|
|
|
7
7
|
## Unreleased
|
|
8
8
|
|
|
9
|
+
## [0.3.0] - 2026-11-22
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `fetch_page` para os catálogos de legislaturas, partidos e deputados.
|
|
14
|
+
O resultado preserva as linhas publicadas e a continuação da página.
|
|
15
|
+
Um envelope inválido gera `CongregaPlenum::APIError`.
|
|
16
|
+
|
|
9
17
|
## [0.2.0] - 2026-08-23
|
|
10
18
|
|
|
11
19
|
### Changed
|
data/README.md
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
<picture>
|
|
2
|
+
<source media="(prefers-color-scheme: dark)" srcset="assets/branding/diafania-claritas-logo-inverse.svg">
|
|
3
|
+
<source media="(prefers-color-scheme: light)" srcset="assets/branding/diafania-claritas-logo.svg">
|
|
4
|
+
<img alt="Diafania Claritas: o Congresso Nacional observado por um olho" src="assets/branding/diafania-claritas-logo.svg" width="560">
|
|
5
|
+
</picture>
|
|
6
|
+
|
|
1
7
|
# CongregaPlenum
|
|
2
8
|
|
|
3
|
-
[](https://github.com/Diafania-Claritas/CongregaPlenum/actions/workflows/ci.yml)
|
|
10
|
+
[](https://github.com/Diafania-Claritas/CongregaPlenum/actions/workflows/ci.yml)
|
|
11
|
+
[](https://diafania-claritas.github.io/CongregaPlenum/)
|
|
6
12
|
[](https://rubygems.org/gems/congrega_plenum)
|
|
7
13
|
[](LICENSE)
|
|
8
14
|
|
|
@@ -11,7 +17,7 @@ com paginação, retries, logging e serviços para deputados, partidos e
|
|
|
11
17
|
legislaturas e votações. O projeto inclui assinaturas RBS e uma API orientada a
|
|
12
18
|
sincronizações e aplicações de dados cívicos.
|
|
13
19
|
|
|
14
|
-
- [Documentação da API](https://
|
|
20
|
+
- [Documentação da API](https://diafania-claritas.github.io/CongregaPlenum/)
|
|
15
21
|
- [Como contribuir](CONTRIBUTING.md)
|
|
16
22
|
- [Changelog](CHANGELOG.md)
|
|
17
23
|
- [Política de segurança](SECURITY.md)
|
|
@@ -27,7 +33,7 @@ sincronizações e aplicações de dados cívicos.
|
|
|
27
33
|
Adicione a gem ao seu `Gemfile`:
|
|
28
34
|
|
|
29
35
|
```ruby
|
|
30
|
-
gem 'congrega_plenum', '~> 0.
|
|
36
|
+
gem 'congrega_plenum', '~> 0.3.0'
|
|
31
37
|
```
|
|
32
38
|
|
|
33
39
|
Depois execute:
|
|
@@ -39,7 +45,7 @@ bundle install
|
|
|
39
45
|
Ou instale diretamente pelo RubyGems:
|
|
40
46
|
|
|
41
47
|
```bash
|
|
42
|
-
gem install congrega_plenum -v '~> 0.
|
|
48
|
+
gem install congrega_plenum -v '~> 0.3.0'
|
|
43
49
|
```
|
|
44
50
|
|
|
45
51
|
Consulte a [página da gem no RubyGems](https://rubygems.org/gems/congrega_plenum)
|
|
@@ -87,6 +93,11 @@ Outros fluxos disponíveis:
|
|
|
87
93
|
- `CongregaPlenum::VotingsService.fetch_votes(voting_id)`
|
|
88
94
|
- `CongregaPlenum::VotingsService.fetch_orientations(voting_id)`
|
|
89
95
|
|
|
96
|
+
Para uma sincronização retomável de catálogos, use `fetch_page` em
|
|
97
|
+
`CongressmenService`, `PartiesService` ou `LegislaturesService`. O resultado
|
|
98
|
+
fornece `records` e `next_page`. `next_page` é `nil` no fim da lista. Respostas
|
|
99
|
+
sem uma lista explícita ou com continuação inválida levantam `APIError`.
|
|
100
|
+
|
|
90
101
|
Uma votação representa uma decisão legislativa individual já concluída. Uma
|
|
91
102
|
proposição pode ser afetada por várias votações de pareceres, emendas,
|
|
92
103
|
requerimentos e destaques relacionados. Por isso, detalhes, votos individuais e
|
|
@@ -110,7 +121,7 @@ ao mesmo ano. Votações simbólicas normalmente não possuem votos individuais,
|
|
|
110
121
|
uma lista de votos vazia não identifica quais deputados estavam ausentes.
|
|
111
122
|
|
|
112
123
|
Para controle de baixo nível, use `CongregaPlenum::Client`. Consulte a
|
|
113
|
-
[documentação YARD](https://
|
|
124
|
+
[documentação YARD](https://diafania-claritas.github.io/CongregaPlenum/) para os contratos
|
|
114
125
|
completos.
|
|
115
126
|
|
|
116
127
|
## Desenvolvimento
|
data/lib/catalog_page.rb
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CongregaPlenum
|
|
4
|
+
# One validated catalogue page. Repeated identities remain in source order.
|
|
5
|
+
CatalogPage = Data.define(:records, :next_page) do
|
|
6
|
+
# Validates the API envelope and extracts sequential pagination metadata.
|
|
7
|
+
def self.parse(response, page:)
|
|
8
|
+
records = records_from(response)
|
|
9
|
+
links = links_from(response)
|
|
10
|
+
next_page = continuation(links, page)
|
|
11
|
+
raise APIError, 'empty catalogue page cannot continue' if next_page && records.empty?
|
|
12
|
+
|
|
13
|
+
new(records: records.freeze, next_page: next_page)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.records_from(response)
|
|
17
|
+
records = response['dados']
|
|
18
|
+
return records if records.is_a?(Array) && records.all?(Hash)
|
|
19
|
+
|
|
20
|
+
raise APIError, 'catalogue page requires an explicit list of objects in dados'
|
|
21
|
+
end
|
|
22
|
+
private_class_method :records_from
|
|
23
|
+
|
|
24
|
+
def self.links_from(response)
|
|
25
|
+
links = response['links']
|
|
26
|
+
return links if links.is_a?(Array) && links.all? { |link| link.is_a?(Hash) && link['rel'].is_a?(String) }
|
|
27
|
+
|
|
28
|
+
raise APIError, 'catalogue page requires pagination links'
|
|
29
|
+
end
|
|
30
|
+
private_class_method :links_from
|
|
31
|
+
|
|
32
|
+
def self.continuation(links, page)
|
|
33
|
+
next_links = links.select { |link| link['rel'] == 'next' }
|
|
34
|
+
return if next_links.empty?
|
|
35
|
+
|
|
36
|
+
unless next_links.one? && page_parameter(next_links.first['href']) == [(page + 1).to_s]
|
|
37
|
+
raise APIError, 'invalid catalogue page continuation'
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
page + 1
|
|
41
|
+
end
|
|
42
|
+
private_class_method :continuation
|
|
43
|
+
|
|
44
|
+
def self.page_parameter(href)
|
|
45
|
+
return [] unless href.is_a?(String)
|
|
46
|
+
|
|
47
|
+
query = URI.parse(href).query.to_s
|
|
48
|
+
URI.decode_www_form(query).filter_map { |name, value| value if name == 'pagina' }
|
|
49
|
+
rescue URI::InvalidURIError, ArgumentError
|
|
50
|
+
raise APIError, 'invalid catalogue page continuation'
|
|
51
|
+
end
|
|
52
|
+
private_class_method :page_parameter
|
|
53
|
+
end
|
|
54
|
+
end
|
data/lib/client.rb
CHANGED
|
@@ -44,6 +44,13 @@ module CongregaPlenum
|
|
|
44
44
|
results
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
+
# Retrieves and validates one page without discarding continuation metadata.
|
|
48
|
+
def get_catalog_page(endpoint, page:, params: {})
|
|
49
|
+
raise ArgumentError, 'page must be a positive integer' unless page.is_a?(Integer) && page.positive?
|
|
50
|
+
|
|
51
|
+
CatalogPage.parse(get(endpoint, params.merge(pagina: page)), page: page)
|
|
52
|
+
end
|
|
53
|
+
|
|
47
54
|
private
|
|
48
55
|
|
|
49
56
|
def each_response_page(endpoint, params)
|
data/lib/congrega_plenum.rb
CHANGED
|
@@ -76,6 +76,7 @@ end
|
|
|
76
76
|
require_relative 'adapters/http_adapter'
|
|
77
77
|
require_relative 'adapters/retry_policy'
|
|
78
78
|
require_relative 'adapters/response_handler'
|
|
79
|
+
require_relative 'catalog_page'
|
|
79
80
|
require_relative 'client'
|
|
80
81
|
require_relative 'modules/congressmen_service'
|
|
81
82
|
require_relative 'modules/parties_service'
|
|
@@ -84,6 +84,12 @@ module CongregaPlenum
|
|
|
84
84
|
response['dados'] || []
|
|
85
85
|
end
|
|
86
86
|
|
|
87
|
+
# Returns one validated catalogue page with its next page, if published.
|
|
88
|
+
def fetch_page(page: 1, items_per_page: ITEMS_PER_PAGE, legislature_id: nil)
|
|
89
|
+
params = { idLegislatura: legislature_id, itens: items_per_page, ordem: 'ASC', ordenarPor: 'id' }.compact
|
|
90
|
+
client.get_catalog_page('deputados', page: page, params: params)
|
|
91
|
+
end
|
|
92
|
+
|
|
87
93
|
private
|
|
88
94
|
|
|
89
95
|
def extract_detail(response, resource)
|
|
@@ -86,6 +86,12 @@ module CongregaPlenum
|
|
|
86
86
|
deputies
|
|
87
87
|
end
|
|
88
88
|
|
|
89
|
+
# Returns one validated catalogue page with its next page, if published.
|
|
90
|
+
def fetch_page(page: 1, items_per_page: PAGE_SIZE)
|
|
91
|
+
params = { itens: items_per_page }.compact
|
|
92
|
+
client.get_catalog_page('legislaturas', page: page, params: params)
|
|
93
|
+
end
|
|
94
|
+
|
|
89
95
|
private
|
|
90
96
|
|
|
91
97
|
def extract_detail(response, resource)
|
|
@@ -76,6 +76,12 @@ module CongregaPlenum
|
|
|
76
76
|
response['dados'] || []
|
|
77
77
|
end
|
|
78
78
|
|
|
79
|
+
# Returns one validated catalogue page with its next page, if published.
|
|
80
|
+
def fetch_page(page: 1, items_per_page: ITEMS_PER_PAGE)
|
|
81
|
+
params = { itens: items_per_page, ordem: 'ASC', ordenarPor: 'id' }.compact
|
|
82
|
+
client.get_catalog_page('partidos', page: page, params: params)
|
|
83
|
+
end
|
|
84
|
+
|
|
79
85
|
private
|
|
80
86
|
|
|
81
87
|
def extract_detail(response, resource)
|
data/lib/version.rb
CHANGED
data/sig/congrega_plenum.rbs
CHANGED
|
@@ -67,6 +67,13 @@ module CongregaPlenum
|
|
|
67
67
|
def parse_json_response: (::Net::HTTPResponse, String) -> payload_hash
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
+
class CatalogPage
|
|
71
|
+
attr_reader records: payload_list
|
|
72
|
+
attr_reader next_page: Integer?
|
|
73
|
+
def self.new: (records: payload_list, next_page: Integer?) -> instance
|
|
74
|
+
def self.parse: (payload_hash, page: Integer) -> instance
|
|
75
|
+
end
|
|
76
|
+
|
|
70
77
|
class Client
|
|
71
78
|
include ::Singleton
|
|
72
79
|
|
|
@@ -77,6 +84,7 @@ module CongregaPlenum
|
|
|
77
84
|
|
|
78
85
|
def initialize: () -> void
|
|
79
86
|
def get: (String, ?params_hash) -> payload_hash
|
|
87
|
+
def get_catalog_page: (String, page: Integer, ?params: params_hash) -> CatalogPage
|
|
80
88
|
def get_paginated: (String, ?params_hash) -> payload_list
|
|
81
89
|
def each_response_page: (String, params_hash) { (payload_list) -> void } -> void
|
|
82
90
|
def request_page: (String, params_hash, Integer) -> payload_hash
|
|
@@ -97,6 +105,7 @@ module CongregaPlenum
|
|
|
97
105
|
def self.api_get_paginated: (String, ?params_hash) -> payload_list
|
|
98
106
|
def self.fetch_all: () -> payload_list
|
|
99
107
|
def self.fetch_all_by_legislature: (Integer) -> payload_list
|
|
108
|
+
def self.fetch_page: (?page: Integer, ?items_per_page: Integer, ?legislature_id: Integer?) -> CatalogPage
|
|
100
109
|
def self.fetch_by_id: (Integer) -> detail_payload
|
|
101
110
|
def self.fetch_list: (?page: Integer, ?items_per_page: Integer, ?legislature_id: Integer?) -> payload_list
|
|
102
111
|
def self.fetch_deputies_collection: (context: String, params: params_hash) -> payload_list
|
|
@@ -118,6 +127,7 @@ module CongregaPlenum
|
|
|
118
127
|
def self.api_get: (String, ?params_hash) -> payload_hash
|
|
119
128
|
def self.api_get_paginated: (String, ?params_hash) -> payload_list
|
|
120
129
|
def self.fetch_all: () -> payload_list
|
|
130
|
+
def self.fetch_page: (?page: Integer, ?items_per_page: Integer) -> CatalogPage
|
|
121
131
|
def self.fetch_by_id: (Integer) -> detail_payload
|
|
122
132
|
def self.fetch_list: (?page: Integer, ?items_per_page: Integer) -> payload_list
|
|
123
133
|
def self.extract_detail: (payload_hash, String) -> detail_payload
|
|
@@ -138,6 +148,7 @@ module CongregaPlenum
|
|
|
138
148
|
def self.api_get: (String, ?params_hash) -> payload_hash
|
|
139
149
|
def self.api_get_paginated: (String, ?params_hash) -> payload_list
|
|
140
150
|
def self.fetch_all: () -> payload_list
|
|
151
|
+
def self.fetch_page: (?page: Integer, ?items_per_page: Integer) -> CatalogPage
|
|
141
152
|
def self.fetch_by_id: (Integer) -> detail_payload
|
|
142
153
|
def self.fetch_mesa: (Integer) -> payload_list
|
|
143
154
|
def self.fetch_deputies: (Integer) -> payload_list
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: congrega_plenum
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- zarbielli
|
|
@@ -23,6 +23,7 @@ files:
|
|
|
23
23
|
- lib/adapters/http_adapter.rb
|
|
24
24
|
- lib/adapters/response_handler.rb
|
|
25
25
|
- lib/adapters/retry_policy.rb
|
|
26
|
+
- lib/catalog_page.rb
|
|
26
27
|
- lib/client.rb
|
|
27
28
|
- lib/congrega_plenum.rb
|
|
28
29
|
- lib/modules/congressmen_service.rb
|
|
@@ -31,14 +32,14 @@ files:
|
|
|
31
32
|
- lib/modules/votings_service.rb
|
|
32
33
|
- lib/version.rb
|
|
33
34
|
- sig/congrega_plenum.rbs
|
|
34
|
-
homepage: https://github.com/
|
|
35
|
+
homepage: https://github.com/Diafania-Claritas/CongregaPlenum
|
|
35
36
|
licenses:
|
|
36
37
|
- AGPL-3.0-or-later
|
|
37
38
|
metadata:
|
|
38
39
|
allowed_push_host: https://rubygems.org
|
|
39
|
-
homepage_uri: https://github.com/
|
|
40
|
-
source_code_uri: https://github.com/
|
|
41
|
-
changelog_uri: https://github.com/
|
|
40
|
+
homepage_uri: https://github.com/Diafania-Claritas/CongregaPlenum
|
|
41
|
+
source_code_uri: https://github.com/Diafania-Claritas/CongregaPlenum
|
|
42
|
+
changelog_uri: https://github.com/Diafania-Claritas/CongregaPlenum/blob/main/CHANGELOG.md
|
|
42
43
|
rubygems_mfa_required: 'true'
|
|
43
44
|
rdoc_options: []
|
|
44
45
|
require_paths:
|