datajud 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: df44322c1e2eba6972b67d741f06397c71ce2496ba2083d4872b2921a3d2c15f
4
+ data.tar.gz: 2c7824b296dc66eab4dc9cf9a7b0a1fcba7695127d862db69345f8ee119ab357
5
+ SHA512:
6
+ metadata.gz: 873b56c67fcc760489fcf5f334094bd7468a6a2e5df70cdd2719cee79e5996180bbf34e88d3cca0e902358746b3920038774c86613dde0d2a4457a04a0acfb1e
7
+ data.tar.gz: 78ffe423908d0c1713969adabef58b3663690f9e585b766f101876c36909ea85c08c5eb756cd094b94ba47b505cf95f678334b2b521906b5ad8e66aac9071f63
data/.datajud_api_key ADDED
File without changes
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-11-25
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at pabloaurelio1163@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ gem "rake", "~> 13.0"
8
+ gem "nokogiri", "~> 1.14"
9
+ gem "json", "~> 2.0"
10
+ gem "net-http", "~> 0.3"
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ datajud (0.1.0)
5
+ json (~> 2.0)
6
+ net-http (~> 0.3)
7
+ nokogiri (~> 1.14)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ json (2.16.0)
13
+ net-http (0.8.0)
14
+ uri (>= 0.11.1)
15
+ nokogiri (1.17.2-x86_64-linux)
16
+ racc (~> 1.4)
17
+ racc (1.8.1)
18
+ rake (13.3.1)
19
+ uri (1.1.1)
20
+
21
+ PLATFORMS
22
+ x86_64-linux
23
+
24
+ DEPENDENCIES
25
+ datajud!
26
+ json (~> 2.0)
27
+ net-http (~> 0.3)
28
+ nokogiri (~> 1.14)
29
+ rake (~> 13.0)
30
+
31
+ BUNDLED WITH
32
+ 2.3.26
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Pablo Aurelio Melo Almeida
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Datajud
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/datajud`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add datajud
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install datajud
16
+
17
+ ## Usage
18
+
19
+ TODO: Write usage instructions here
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/datajud. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/datajud/blob/master/CODE_OF_CONDUCT.md).
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
34
+
35
+ ## Code of Conduct
36
+
37
+ Everyone interacting in the Datajud project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/datajud/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "datajud"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+ require 'fileutils'
4
+ require 'net/http'
5
+ require 'uri'
6
+
7
+ module Datajud
8
+ module KeyFetcher
9
+ ACCESS_URL = "https://datajud-wiki.cnj.jus.br/api-publica/acesso/"
10
+ CACHE_PATH = File.join(Dir.home, ".datajud_api_key")
11
+
12
+ def self.fetch_api_key
13
+ # Tenta carregar do cache
14
+ if File.exist?(CACHE_PATH)
15
+ key = File.read(CACHE_PATH).strip
16
+ return key unless key.empty?
17
+ end
18
+
19
+ html = Net::HTTP.get(URI.parse(ACCESS_URL))
20
+ doc = Nokogiri::HTML.parse(html)
21
+ key = doc.text[/Authorization:\s*APIKey\s*([A-Za-z0-9+\/]+=+)/, 1]
22
+ raise "API Key not found on Datajud-Wiki page!" unless key
23
+
24
+ # Salva em cache
25
+ File.write(CACHE_PATH, key)
26
+ key
27
+ end
28
+
29
+ def self.clear_cache
30
+ FileUtils.rm_f(CACHE_PATH)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datajud
4
+ VERSION = "0.1.0"
5
+ end
data/lib/datajud.rb ADDED
@@ -0,0 +1,145 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "datajud/version"
4
+ require_relative "datajud/key_fetcher"
5
+ require 'net/http'
6
+ require 'json'
7
+
8
+ module Datajud
9
+ BASE_ENDPT = "https://api-publica.datajud.cnj.jus.br"
10
+ # Tribunais de Justiça Estaduais (TJs)
11
+ TJS_SIGLAS = [
12
+ "tjac", "tjal", "tjap", "tjba", "tjce", "tjdf", "tjes", "tjgo", "tjma",
13
+ "tjmg", "tjms", "tjmt", "tjpa", "tjpb", "tjpe", "tjpi", "tjpr", "tjrj",
14
+ "tjrn", "tjro", "tjrr", "tjrs", "tjsc", "tjse", "tjsp", "to"
15
+ ]
16
+
17
+ # Tribunais Regionais Federais (TRFs)
18
+ TRFS_SIGLAS = [
19
+ "trf1", "trf2", "trf3", "trf4", "trf5"
20
+ ]
21
+
22
+ # Tribunais Regionais do Trabalho (TRTs)
23
+ TRTS_SIGLAS = [
24
+ "trt1", "trt2", "trt3", "trt4", "trt5", "trt6", "trt7", "trt8", "trt9",
25
+ "trt10", "trt11", "trt12", "trt13", "trt14", "trt15", "trt16", "trt17",
26
+ "trt18", "trt19", "trt20", "trt21", "trt22", "trt23", "trt24"
27
+ ]
28
+
29
+ # Tribunais Regionais Eleitorais (TREs)
30
+ TRES_SIGLAS = [
31
+ "treac", "treal", "tream", "treap", "treba", "trece", "tredf", "tresp",
32
+ "trego", "trema", "tremg", "trems", "tremt", "trepa", "trepb", "trepe",
33
+ "trepi", "trepr", "trerj", "trern", "trero", "trerr", "trers", "tresc",
34
+ "trese", "tretoc"
35
+ ]
36
+
37
+ # Tribunais Superiores
38
+ SUPERIORES_SIGLAS = [
39
+ "tse", "stf", "stj", "stm", "tst"
40
+ ]
41
+
42
+ # Para consultar em todos, você pode unificar todas as listas:
43
+ TRIBUNAIS_SIGLAS = TJS_SIGLAS + TRFS_SIGLAS + TRTS_SIGLAS + TRES_SIGLAS + SUPERIORES_SIGLAS
44
+
45
+ # Pega a API Key sempre atual (consulta ao site DataJud)
46
+ def self.api_key
47
+ @api_key ||= KeyFetcher.fetch_api_key
48
+ end
49
+
50
+ def self.reset_api_key
51
+ KeyFetcher.clear_cache
52
+ @api_key = nil
53
+ end
54
+
55
+ def self.processo(numero, tribunal: nil)
56
+ siglas_consulta = tribunal ? Array(tribunal).flatten.map { |t| t.to_s.downcase } : TRIBUNAIS_SIGLAS
57
+ resultado = nil
58
+
59
+ siglas_consulta.each do |sigla|
60
+ endpoint = "#{BASE_ENDPT}/api_publica_#{sigla}/_search"
61
+ payload = {
62
+ "query": {
63
+ "bool": {
64
+ "must": [
65
+ { "match": { "numeroProcesso": numero } }
66
+ ]
67
+ }
68
+ }
69
+ }
70
+
71
+ uri = URI(endpoint)
72
+ req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
73
+ req.body = payload.to_json
74
+ req['Authorization'] = "APIKey #{api_key}"
75
+
76
+ http = Net::HTTP.new(uri.hostname, uri.port)
77
+ http.use_ssl = true
78
+ resp = http.request(req)
79
+
80
+ # Se falhar por chave expirada:
81
+ if [401, 403].include?(resp.code.to_i)
82
+ reset_api_key
83
+ req['Authorization'] = "APIKey #{api_key}"
84
+ resp = http.request(req)
85
+ end
86
+
87
+ next unless resp.code.to_i == 200
88
+
89
+ processos = JSON.parse(resp.body)
90
+ if processos['hits'] && !processos['hits']['hits'].empty?
91
+ proc = processos['hits']['hits'][0]['_source']
92
+
93
+ resultado = {
94
+ tribunal: sigla.upcase,
95
+ processo: {
96
+ numero: proc['numeroProcesso'],
97
+ vara: proc['orgaoJulgador'] ? {
98
+ nome: proc['orgaoJulgador']['nome'],
99
+ codigo: proc['orgaoJulgador']['codigo'],
100
+ comarca: proc['orgaoJulgador']['comarca'],
101
+ tribunal: sigla.upcase
102
+ } : nil,
103
+ situacao: proc['situacao'],
104
+ origem: proc['origem'],
105
+ instancia: proc['grau'],
106
+ classe: proc['classeProcessual'],
107
+ assunto: proc['assuntos'],
108
+ partes: proc['partes']&.map do |p|
109
+ {
110
+ nome: p['nome'],
111
+ tipo: p['tipoParte'],
112
+ documento: p['documento']
113
+ }
114
+ end,
115
+ andamentos: proc['movimentacoes']&.map do |mv|
116
+ {
117
+ descricao: mv['descricao'],
118
+ data: mv['dataHora'],
119
+ tipo: mv['codigoTipoMovimento']
120
+ }
121
+ end,
122
+ documentos: proc['documentos']&.map do |doc|
123
+ {
124
+ titulo: doc['nomeDocumento'],
125
+ tipo: doc['tipoDocumento'],
126
+ data: doc['dataJuntada'],
127
+ assinatura_digital: doc['assinaturaDigital']
128
+ }
129
+ end,
130
+ audiencias: proc['audiencias']&.map do |aud|
131
+ {
132
+ data_hora: aud['dataHora'],
133
+ tipo: aud['tipo'],
134
+ status: aud['statusAudiencia'],
135
+ observacao: aud['observacao']
136
+ }
137
+ end
138
+ }
139
+ }
140
+ break
141
+ end
142
+ end
143
+ resultado
144
+ end
145
+ end
data/sig/datajud.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Datajud
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: datajud
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - PablUoo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-11-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: net-http
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.3'
55
+ description: Gem Ruby que permite busca e extração detalhada de processos judiciais
56
+ diretamente da API pública DataJUD do CNJ, preenchendo estruturas compatíveis com
57
+ banco e DER de processos brasileiros.
58
+ email:
59
+ - pabloaurelio1163@gmail.com
60
+ executables:
61
+ - console
62
+ - setup
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - ".datajud_api_key"
67
+ - CHANGELOG.md
68
+ - CODE_OF_CONDUCT.md
69
+ - Gemfile
70
+ - Gemfile.lock
71
+ - LICENSE
72
+ - README.md
73
+ - Rakefile
74
+ - bin/console
75
+ - bin/setup
76
+ - lib/datajud.rb
77
+ - lib/datajud/key_fetcher.rb
78
+ - lib/datajud/version.rb
79
+ - sig/datajud.rbs
80
+ homepage: https://github.com/PablUoo/datajud
81
+ licenses:
82
+ - MIT
83
+ metadata:
84
+ allowed_push_host: https://rubygems.org
85
+ homepage_uri: https://github.com/PablUoo/datajud
86
+ source_code_uri: https://github.com/PablUoo/datajud
87
+ changelog_uri: https://github.com/PablUoo/datajud/CHANGELOG.md
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 2.6.0
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubygems_version: 3.2.32
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Gem para consultar a API DataJUD por número de processo
107
+ test_files: []