calendario_api 0.1.0b

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: b378f3354647c8fe025a4542a44cf16e4663cab3a9299cc41dc8c82487bce62f
4
+ data.tar.gz: 6e9e1e13fed18f275e4c2420a2c7814aa5918d46698722e2890facaae83d2ae2
5
+ SHA512:
6
+ metadata.gz: 66126736c60bc47fc92baa48e15656beb713b0f4ae91878ba53dccc9d708c75aaca645a6d99859054dab74adf132305165bc0b01427ebd8938eb1c538ca0deda
7
+ data.tar.gz: 821a3ccff14f7cff6f2e9753de4f8dfea0ede5a811e38e2e4298f3d1eb684938ee4662d797ff1df53d9c1e6b238733ef329a5f8867775235eb1ac7493c761d8f
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ # VCR Cassetes folder
14
+ spec/vcr_cassettes/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ Style/AsciiComments:
2
+ Enabled: false
3
+ Style/HashEachMethods:
4
+ Enabled: true
5
+ Style/HashTransformKeys:
6
+ Enabled: true
7
+ Style/HashTransformValues:
8
+ Enabled: true
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.2
@@ -0,0 +1,18 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "RSpec - all",
9
+ "type": "Ruby",
10
+ "request": "launch",
11
+ "program": "rspec",
12
+ "args": [
13
+ "-I",
14
+ "${workspaceRoot}"
15
+ ]
16
+ }
17
+ ]
18
+ }
data/.yardopts ADDED
@@ -0,0 +1,5 @@
1
+ --no-private
2
+ --markup provider=redcarpet
3
+ --markup=markdown
4
+ -
5
+ CHANGELOG.md
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # MASTER
2
+
3
+ ## 0.1.0
4
+ - API de cidades do Brasil
5
+ - Filtrar Cidades por Estado
6
+ - API de feriados do Brasil
7
+ - Filtrar Feriados por Mês
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at ruanmacambira@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in calendario_api.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,102 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ calendario_api (0.1.0b)
5
+ rest-client
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (6.0.2.1)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 0.7, < 2)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
15
+ zeitwerk (~> 2.2)
16
+ addressable (2.7.0)
17
+ public_suffix (>= 2.0.2, < 5.0)
18
+ coderay (1.1.2)
19
+ concurrent-ruby (1.1.5)
20
+ crack (0.4.3)
21
+ safe_yaml (~> 1.0.0)
22
+ diff-lcs (1.3)
23
+ docile (1.3.2)
24
+ domain_name (0.5.20190701)
25
+ unf (>= 0.0.5, < 1.0.0)
26
+ factory_bot (5.1.1)
27
+ activesupport (>= 4.2.0)
28
+ github-markup (3.0.4)
29
+ hashdiff (1.0.1)
30
+ http-accept (1.7.0)
31
+ http-cookie (1.0.3)
32
+ domain_name (~> 0.5)
33
+ i18n (1.8.2)
34
+ concurrent-ruby (~> 1.0)
35
+ method_source (0.9.2)
36
+ mime-types (3.3.1)
37
+ mime-types-data (~> 3.2015)
38
+ mime-types-data (3.2019.1009)
39
+ minitest (5.14.0)
40
+ netrc (0.11.0)
41
+ pry (0.12.2)
42
+ coderay (~> 1.1.0)
43
+ method_source (~> 0.9.0)
44
+ public_suffix (4.0.3)
45
+ rake (13.0.1)
46
+ redcarpet (3.5.0)
47
+ rest-client (2.1.0)
48
+ http-accept (>= 1.7.0, < 2.0)
49
+ http-cookie (>= 1.0.2, < 2.0)
50
+ mime-types (>= 1.16, < 4.0)
51
+ netrc (~> 0.8)
52
+ rspec (3.9.0)
53
+ rspec-core (~> 3.9.0)
54
+ rspec-expectations (~> 3.9.0)
55
+ rspec-mocks (~> 3.9.0)
56
+ rspec-core (3.9.1)
57
+ rspec-support (~> 3.9.1)
58
+ rspec-expectations (3.9.0)
59
+ diff-lcs (>= 1.2.0, < 2.0)
60
+ rspec-support (~> 3.9.0)
61
+ rspec-mocks (3.9.1)
62
+ diff-lcs (>= 1.2.0, < 2.0)
63
+ rspec-support (~> 3.9.0)
64
+ rspec-support (3.9.2)
65
+ safe_yaml (1.0.5)
66
+ simplecov (0.18.5)
67
+ docile (~> 1.1)
68
+ simplecov-html (~> 0.11)
69
+ simplecov-html (0.12.2)
70
+ thread_safe (0.3.6)
71
+ tzinfo (1.2.6)
72
+ thread_safe (~> 0.1)
73
+ unf (0.1.4)
74
+ unf_ext
75
+ unf_ext (0.0.7.6)
76
+ vcr (5.1.0)
77
+ webmock (3.8.2)
78
+ addressable (>= 2.3.6)
79
+ crack (>= 0.3.2)
80
+ hashdiff (>= 0.4.0, < 2.0.0)
81
+ yard (0.9.24)
82
+ zeitwerk (2.2.2)
83
+
84
+ PLATFORMS
85
+ ruby
86
+
87
+ DEPENDENCIES
88
+ bundler (~> 2.0)
89
+ calendario_api!
90
+ factory_bot (~> 5.1)
91
+ github-markup
92
+ pry
93
+ rake (~> 13.0)
94
+ redcarpet
95
+ rspec (~> 3.0)
96
+ simplecov (~> 0.18)
97
+ vcr (~> 5.1)
98
+ webmock (~> 3.8)
99
+ yard
100
+
101
+ BUNDLED WITH
102
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 MxBromelia
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # CalendarioApi
2
+
3
+ Wrapper da Api de Feriados Brasileiros de http://www.calendario.com.br/
4
+
5
+ ## Instalação
6
+
7
+ Adicione essa linha na Gemfile da sua aplicação:
8
+
9
+ ```` ruby
10
+ gem 'calendario_api'
11
+ ````
12
+
13
+ E então execute:
14
+
15
+ ````
16
+ $ bundle
17
+ ````
18
+
19
+ Ou instale você mesmo, conforme abaixo:
20
+ ````
21
+ $ gem install calendario_api
22
+ ````
23
+
24
+ ## Uso
25
+
26
+ Acesse http://www.calendario.com.br/api_feriados_municipais_estaduais_nacionais.php e peça uma chave de API. Sem uma chave, você não poderá utilizar a API de Feriados.
27
+
28
+ ```` ruby
29
+ require 'calendario_api'
30
+
31
+ # Traz Feriados Nacionais de 2020
32
+ CalendarioApi.busca_feriados(token: '<TOKEN_VALIDO>', ano: 2020)
33
+
34
+ # Traz Feriados Nacionais e Estaduais de SP em 2020
35
+ CalendarioApi.busca_feriados(token: '<TOKEN_VALIDO>', ano: 2020, estado: 'SP')
36
+
37
+ # Traz Feriados Nacionais, Estaduais de SP, e Municipais de São Paulo em 2020
38
+ CalendarioApi.busca_feriados(token: '<TOKEN_VALIDO>', ano: 2020, estado: 'SP', cidade: 'SAO_PAULO')
39
+ ````
40
+
41
+ Uma alternativa, caso deseje fazer várias requisições diferentes sem ter de repetir o token.
42
+
43
+ ```` ruby
44
+ require 'calendario_api'
45
+
46
+ consulta = CalendarioApi::FeriadoConsulta.new('<TOKEN_VALIDO>')
47
+
48
+ # Traz Feriados Nacionais de 2020
49
+ consulta.busca_por_parametros(2020, '', '')
50
+
51
+ # Traz Feriados Nacionais e Estaduais de SP em 2020
52
+ consulta.busca_por_parametros(2020, 'SP', '')
53
+
54
+ # Traz Feriados Nacionais, Estaduais de SP, e Municipais de São Paulo em 2020
55
+ consulta.busca_por_parametros(2020, 'SP', 'SAO_PAULO')
56
+ ````
57
+
58
+ você também pode filtrar os resultados da busca de feriados por mês
59
+ ```` ruby
60
+ feriados = CalendarioApi.busca_feriados(token: '<TOKEN_VALIDO>', ano: 2020)
61
+
62
+ # Filtra os resultados da busca para apenas os feriados do mês de janeiro
63
+ feriados.filtrar_mes(1)
64
+
65
+ # Filtra os resultados da busca para os feriados do mês de janeiro e fevereiro
66
+ feriados.filtrar_mes(1, 2)
67
+ ````
68
+
69
+ A Api do site também oferece uma relação dos municípios brasileiros, que não precisa de autenticação.
70
+
71
+ ```` ruby
72
+ require 'calendario_api'
73
+
74
+ CalendarioApi.busca_cidades
75
+ ````
76
+
77
+ ## Testando a Aplicação
78
+ Os testes são feitos com [RSpec](https://github.com/rspec/rspec), [FactoryBot](https://github.com/thoughtbot/factory_bot), [WebMock](https://github.com/bblimke/webmock) e [VCR](https://github.com/vcr/vcr). Os testes que fazem requisições para a API e necessitam de API precisam possuir uma chave de API do site para que possam ser executados corretamente. Então, para executar os testes, utilize:
79
+
80
+ ````
81
+ CALENDARIO_API_TOKEN=<TOKEN_VALIDO> bundle exec rspec
82
+ ````
83
+
84
+ Que fará o VCR criar os arquivos que ele usará para executar os testes. Se você já tiver executado os testes e estiver recebendo uma exceção do VCR, verifique se o token utilizado é o mesmo que você usou para rodar os testes da primeira vez, e se ele está válido. Caso tenha feito os testes sem um token válido Remova os cassetes do seu repositório por meio de:
85
+ ````
86
+ rm spec/vcr_cassettes/ -r
87
+
88
+ ````
89
+ e rode os testes novamente com o token correto.
90
+
91
+ Se você tem uma solução para poder os cassetes dentro do repositório sem a necessidade de utilizar uma chave de API para isso, fique à vontade para dar uma contribuição.
92
+
93
+ ## Contribuindo
94
+ Reporte de Problemas e Pull Requests são bem-vindos no Github em https://github.com/MxBromelia/calendario-api-ruby.
95
+
96
+ ## Licença
97
+
98
+ A Gem é disponível em código-aberto sobre os termos da [LIcença MIT](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "calendario_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/rspec ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")
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,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'calendario_api/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'calendario_api'
9
+ spec.version = CalendarioApi::VERSION
10
+ spec.authors = ['MxBromelia']
11
+ spec.email = ['ruanmacambira@gmail.com']
12
+
13
+ spec.summary = 'Gem Wrapper da API de http://www.calendario.com.br'
14
+ spec.description = 'Gem Wrapper da API de http://www.calendario.com.br'
15
+ spec.homepage = 'https://github.com/MxBromelia/calendario-api-ruby'
16
+ spec.license = 'MIT'
17
+
18
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
19
+
20
+ spec.metadata['homepage_uri'] = spec.homepage
21
+ spec.metadata['source_code_uri'] = 'https://github.com/MxBromelia/calendario-api-ruby'
22
+ spec.metadata['changelog_uri'] = 'https://github.com/MxBromelia/calendario-api-ruby/blob/master/CHANGELOG.md'
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_development_dependency 'pry'
34
+
35
+ spec.add_development_dependency 'bundler', '~> 2.0'
36
+ spec.add_development_dependency 'rake', '~> 13.0'
37
+ spec.add_development_dependency 'rspec', '~> 3.0'
38
+
39
+ spec.add_development_dependency 'factory_bot', '~> 5.1'
40
+ spec.add_development_dependency 'simplecov', '~> 0.18'
41
+ spec.add_development_dependency 'vcr', '~> 5.1'
42
+ spec.add_development_dependency 'webmock', '~> 3.8'
43
+
44
+ spec.add_development_dependency 'github-markup'
45
+ spec.add_development_dependency 'redcarpet'
46
+ spec.add_development_dependency 'yard'
47
+
48
+ spec.add_runtime_dependency 'rest-client'
49
+ end
@@ -0,0 +1,45 @@
1
+ require 'calendario_api/version'
2
+ require 'calendario_api/cidade_consulta'
3
+ require 'calendario_api/feriado_params'
4
+ require 'calendario_api/feriado_consulta'
5
+
6
+ # Módulo Único do uso da API de Feriados/Cidades
7
+ module CalendarioApi
8
+ # Erro genérico das funções
9
+ class Error < StandardError; end
10
+
11
+ # Token de Acesso à API Inválido
12
+ class TokenInvalido < Error; end
13
+
14
+ # Limite de usos de cidade ultrapassado
15
+ class LimiteUltrapassado < Error; end
16
+
17
+ # Faz busca na API pelos feriados
18
+ #
19
+ # @param hash_params[Hash] os parâmetros da busca na API.
20
+ # token: (Obrigatório) Token de acesso a API de feriados
21
+ # ano: Ano dos feriados, padrão: ano atual
22
+ # estado: Estado em que se extrairá os feriados Estaduais
23
+ # cidade: Cidade em que se extrairá os feriados Municipais
24
+ # @return [FeriadoResposta] uma coleção de Feriados que condizem
25
+ # com os parâmetros da busca
26
+ # @raise [TokenInvalido] caso não envie um token, ou este seja inválido
27
+ # @note a busca por cidade e estado é inclusiva, isto é, se estiver
28
+ # vazia, não virá Feriados Estaduais ou Municipais.
29
+ # @todo Permitir a busca através do código IBGE da cidade
30
+ # @todo Acionar a exceção correta quando o limite de cidades foi ultrapassado
31
+ # @todo Aplicar Validação dos parâmetros antes de fazer a requisição
32
+ def self.busca_feriados(hash_params = {})
33
+ params = FeriadoParams.new hash_params
34
+ FeriadoConsulta.new(params.token).busca_por_parametros(
35
+ params.ano, params.estado, params.cidade
36
+ )
37
+ end
38
+
39
+ # Faz busca na API pelas cidades
40
+ #
41
+ # @return [CidadeResposta] uma coleção de cidades do Brasil
42
+ def self.busca_cidades
43
+ CidadeConsulta.new.busca
44
+ end
45
+ end
@@ -0,0 +1,47 @@
1
+ require 'rest-client'
2
+ require_relative 'cidade_consulta'
3
+
4
+ module CalendarioApi
5
+ # Classe que representa uma cidade
6
+ class Cidade
7
+ # @return [String] Nome da cidade
8
+ attr_reader :nome
9
+
10
+ # @return [String] Estado da Cidade
11
+ attr_reader :estado
12
+
13
+ # @return [String] Sigla do Estado da Cidade
14
+ attr_reader :sigla_estado
15
+
16
+ # Mapeamento das siglas dos estados e seus respectivos nomes em extenso
17
+ ESTADO_POR_SIGLA = {
18
+ 'AC' => 'Acre', 'AL' => 'Alagoas', 'AP' => 'Amapá', 'AM' => 'Amazonas',
19
+ 'BA' => 'Bahia', 'CE' => 'Ceará', 'DF' => 'Distrito Federal',
20
+ 'ES' => 'Espírito Santo', 'GO' => 'Goiás', 'MA' => 'Maranhão',
21
+ 'MT' => 'Mato Grosso', 'MS' => 'Mato Grosso do Sul', 'MG' => 'Minas Gerais',
22
+ 'PA' => 'Pará', 'PB' => 'Paraíba', 'PR' => 'Paraná', 'PE' => 'Pernambuco',
23
+ 'PI' => 'Piauí', 'RJ' => 'Rio de Janeiro', 'RN' => 'Rio Grande do Norte',
24
+ 'RS' => 'Rio Grande do Sul', 'RO' => 'Rondônia', 'SC' => 'Santa Catarina',
25
+ 'SP' => 'São Paulo', 'SE' => 'Sergipe', 'TO' => 'Tocantins'
26
+ }.freeze
27
+
28
+ # Retorna uma nova instância de Cidade
29
+ def initialize(nome, sigla_estado)
30
+ @nome = nome
31
+ @sigla_estado = sigla_estado
32
+ @estado = ESTADO_POR_SIGLA[sigla_estado]
33
+ end
34
+
35
+ def to_s
36
+ "#{@nome}-#{@sigla_estado}"
37
+ end
38
+
39
+ # Faz a comparação entre estados primeiro, e cidade depois
40
+ def <=>(other)
41
+ compara_estados = estado <=> other.estado
42
+ return compara_estados unless compara_estados.zero?
43
+
44
+ nome <=> other.nome
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,30 @@
1
+ require 'json'
2
+ require 'rest-client'
3
+ require_relative 'cidade'
4
+ require_relative 'cidade_resposta'
5
+
6
+ module CalendarioApi
7
+ # Classe que faz a consulta na API de Cidades
8
+ class CidadeConsulta
9
+ # URL Base da API de Cidades
10
+ URL_CIDADES = 'http://www.calendario.com.br/api/cities.json'.freeze
11
+
12
+ # Faz a busca das cidades do país
13
+ #
14
+ # Não há parâmetros pois esta página não precisa de autenticação para acessar
15
+ # nem há parâmetros a serem inseridos nela.
16
+ # @return [CidadeResposta] Cidades do País
17
+ def busca
18
+ get = RestClient.get URL_CIDADES
19
+ estados = JSON.parse(get.body)
20
+
21
+ CidadeResposta.new(
22
+ estados.map do |sigla_estado, cidades|
23
+ cidades.map do |cidade|
24
+ Cidade.new cidade, sigla_estado
25
+ end
26
+ end.flatten
27
+ )
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,25 @@
1
+ module CalendarioApi
2
+ # Coleção da Resposta da Api de cidades
3
+ class CidadeResposta
4
+ include Enumerable
5
+
6
+ def initialize(colecao)
7
+ @colecao = colecao
8
+ end
9
+
10
+ def each(&block)
11
+ @colecao.each do |member|
12
+ block.call(member)
13
+ end
14
+ end
15
+
16
+ # Filtra os resultados por sigla do estado
17
+ #
18
+ # @param estados estados a filtrar. Ex.: 'SP', 'RJ'
19
+ # @return [CidadeResposta] Coleção de Cidades filtrados por estado
20
+ # @todo Filtrar estados por Nome do Estado
21
+ def filtrar_estados(*estados)
22
+ CidadeResposta.new(@colecao.select { |cidade| estados.include? cidade.sigla_estado })
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,37 @@
1
+ module CalendarioApi
2
+ # Objeto que representa um feriado
3
+ class Feriado
4
+ # @return [String] Nome do Feriado. Ex.: Ano Novo
5
+ attr_reader :nome
6
+
7
+ # @return [String] Tipo de Data (Feriado Nacional, Feriado Estadual, etc.)
8
+ attr_reader :tipo
9
+
10
+ # @return [Integer] equivalente ao tipo de Data
11
+ attr_reader :codigo_tipo
12
+
13
+ # @return [Date] Data do Feriado
14
+ attr_reader :data
15
+
16
+ # @return [String] Link do site para o feriado
17
+ attr_reader :link
18
+
19
+ # #return [String] Descrição breve do Feriado
20
+ attr_reader :descricao
21
+
22
+ # retorna uma nova instânica de Feriado
23
+ def initialize(params = {})
24
+ @nome = params['name']
25
+ @tipo = params['type']
26
+ @codigo_tipo = params['type_code'].to_i
27
+ @data = Date.strptime(params['date'], '%d/%m/%Y')
28
+ @link = params['link']
29
+ @descricao = params['description']
30
+ end
31
+
32
+ # Faz a comparação entre as datas
33
+ def <=>(other)
34
+ date <=> other.date
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,49 @@
1
+ require 'json'
2
+ require 'rest-client'
3
+ require_relative 'feriado_resposta'
4
+ require_relative 'feriado'
5
+
6
+ module CalendarioApi
7
+ # Classe que faz a consulta Na API de Feriados
8
+ class FeriadoConsulta
9
+ # URL Base da API de Feriados
10
+ URL_FERIADOS = 'https://api.calendario.com.br'.freeze
11
+
12
+ # Inicializa o objeto de consulta
13
+ #
14
+ # @param token [String] Token de Autenticação, provido pelo site (http://www.calendario.com.br)
15
+ def initialize(token)
16
+ @token = token
17
+ end
18
+
19
+ # Faz uma busca na API de Feriados
20
+ #
21
+ # @param ano [Integer] Inclui os feriados daquele ano
22
+ # @param sigla_estado [String] Inlui os feriados estaduais daquele estado
23
+ # naquele ano (Necessário Usar Sigla)
24
+ # @param cidade [String] Inclui os feriados municipais daquela cidade
25
+ # naquele ano
26
+ def busca_por_parametros(ano, sigla_estado, cidade)
27
+ FeriadoResposta.new(
28
+ consulta_api(ano, sigla_estado, cidade).map do |feriado|
29
+ Feriado.new feriado
30
+ end
31
+ )
32
+ end
33
+
34
+ private
35
+
36
+ def consulta_api(ano, sigla_estado = '', cidade = '')
37
+ get = RestClient.get(
38
+ URL_FERIADOS,
39
+ params: { token: @token, ano: ano, estado: sigla_estado, cidade: cidade, json: true }
40
+ )
41
+
42
+ begin
43
+ JSON.parse(get.body)
44
+ rescue JSON::ParserError
45
+ raise TokenInvalido, 'Token Inválido'
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,34 @@
1
+ module CalendarioApi
2
+ # Empacota e valida os parâmetros da busca para a API de Feriados
3
+ class FeriadoParams
4
+ # @return [String] Token da API
5
+ attr_reader :token
6
+
7
+ # @return [Integer] Ano
8
+ attr_reader :ano
9
+
10
+ # @return [String] Estado
11
+ attr_reader :estado
12
+
13
+ # @return [String] Cidade
14
+ attr_reader :cidade
15
+
16
+ # Retorna uma nova instância de FeriadoParams
17
+ def initialize(params = {})
18
+ @token = (params['token'] || params[:token]).to_s
19
+ @ano = (params['ano'] || params[:ano]).to_i
20
+ @estado = (params['estado'] || params[:estado]).to_s
21
+ @cidade = (params['cidade'] || params[:cidade]).to_s
22
+ end
23
+
24
+ # Determina se os parâmetros são válidos para fazer uma requisição
25
+ def valid?
26
+ return false if @token.nil?
27
+ return false if @token.empty?
28
+ return false unless @ano.respond_to? :to_i
29
+ return false if @ano.to_i.zero?
30
+
31
+ true
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,26 @@
1
+ module CalendarioApi
2
+ # Coleção de Respostas da API de Feriados
3
+ class FeriadoResposta
4
+ include Enumerable
5
+
6
+ def initialize(colecao)
7
+ @colecao = colecao
8
+ end
9
+
10
+ def each(&block)
11
+ @colecao.each do |member|
12
+ block.call(member)
13
+ end
14
+ end
15
+
16
+ # Filtra os resultados por mês
17
+ #
18
+ # @param meses meses a filtrar, em inteiro, Ex.: 1, 2
19
+ # @return [FeriadoResposta] Coleção de Feriados filtrados por mês
20
+ # @todo Aceitar Strings do mês como parâmetro
21
+ # @todo Aceitar Symbols do mês como parâmetro
22
+ def filtrar_mes(*meses)
23
+ FeriadoResposta.new(@colecao.select { |data| meses.include? data.data.month })
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CalendarioApi
4
+ VERSION = '0.1.0b'
5
+ end
metadata ADDED
@@ -0,0 +1,241 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: calendario_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0b
5
+ platform: ruby
6
+ authors:
7
+ - MxBromelia
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
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: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: factory_bot
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.18'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.18'
97
+ - !ruby/object:Gem::Dependency
98
+ name: vcr
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '5.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '5.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.8'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.8'
125
+ - !ruby/object:Gem::Dependency
126
+ name: github-markup
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: redcarpet
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: yard
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rest-client
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: Gem Wrapper da API de http://www.calendario.com.br
182
+ email:
183
+ - ruanmacambira@gmail.com
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".gitignore"
189
+ - ".rspec"
190
+ - ".rubocop.yml"
191
+ - ".travis.yml"
192
+ - ".vscode/launch.json"
193
+ - ".yardopts"
194
+ - CHANGELOG.md
195
+ - CODE_OF_CONDUCT.md
196
+ - Gemfile
197
+ - Gemfile.lock
198
+ - LICENSE.txt
199
+ - README.md
200
+ - Rakefile
201
+ - bin/console
202
+ - bin/rspec
203
+ - bin/setup
204
+ - calendario_api.gemspec
205
+ - lib/calendario_api.rb
206
+ - lib/calendario_api/cidade.rb
207
+ - lib/calendario_api/cidade_consulta.rb
208
+ - lib/calendario_api/cidade_resposta.rb
209
+ - lib/calendario_api/feriado.rb
210
+ - lib/calendario_api/feriado_consulta.rb
211
+ - lib/calendario_api/feriado_params.rb
212
+ - lib/calendario_api/feriado_resposta.rb
213
+ - lib/calendario_api/version.rb
214
+ homepage: https://github.com/MxBromelia/calendario-api-ruby
215
+ licenses:
216
+ - MIT
217
+ metadata:
218
+ allowed_push_host: https://rubygems.org/
219
+ homepage_uri: https://github.com/MxBromelia/calendario-api-ruby
220
+ source_code_uri: https://github.com/MxBromelia/calendario-api-ruby
221
+ changelog_uri: https://github.com/MxBromelia/calendario-api-ruby/blob/master/CHANGELOG.md
222
+ post_install_message:
223
+ rdoc_options: []
224
+ require_paths:
225
+ - lib
226
+ required_ruby_version: !ruby/object:Gem::Requirement
227
+ requirements:
228
+ - - ">="
229
+ - !ruby/object:Gem::Version
230
+ version: '0'
231
+ required_rubygems_version: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - ">"
234
+ - !ruby/object:Gem::Version
235
+ version: 1.3.1
236
+ requirements: []
237
+ rubygems_version: 3.0.4
238
+ signing_key:
239
+ specification_version: 4
240
+ summary: Gem Wrapper da API de http://www.calendario.com.br
241
+ test_files: []