├── .github └── workflows │ └── ruby.yml ├── .gitignore ├── .rspec ├── .ruby-version ├── Gemfile ├── Gemfile.lock ├── README.md ├── Rakefile ├── app ├── controllers │ ├── api │ │ ├── api_controller.rb │ │ └── v1 │ │ │ ├── previsao_controller.rb │ │ │ └── provincias_controller.rb │ ├── application_controller.rb │ └── concerns │ │ └── .keep ├── models │ ├── application_record.rb │ ├── concerns │ │ └── .keep │ └── provincia.rb └── views │ └── api │ ├── api │ └── index.json.jbuilder │ └── v1 │ ├── previsao │ ├── previsao.json.jbuilder │ └── province_not_found.json.jbuilder │ └── provincias │ ├── index.json.jbuilder │ ├── province_not_found.json.jbuilder │ └── show.json.jbuilder ├── bin ├── bundle ├── rails ├── rake └── setup ├── config.ru ├── config ├── application.rb ├── boot.rb ├── cable.yml ├── credentials.yml.enc ├── database.yml ├── environment.rb ├── environments │ ├── development.rb │ ├── production.rb │ └── test.rb ├── initializers │ ├── application_controller_renderer.rb │ ├── backtrace_silencers.rb │ ├── cors.rb │ ├── filter_parameter_logging.rb │ ├── inflections.rb │ ├── mime_types.rb │ ├── new_framework_defaults_6_1.rb │ └── wrap_parameters.rb ├── locales │ └── en.yml ├── puma.rb ├── routes.rb ├── spring.rb └── storage.yml ├── db ├── development.sqlite3 ├── migrate │ └── 20200603115236_create_provincia.rb ├── schema.rb └── seeds.rb ├── lib ├── services │ └── weather_scraper.rb └── tasks │ └── .keep ├── log └── .keep ├── public └── robots.txt ├── spec ├── rails_helper.rb └── spec_helper.rb ├── storage └── .keep ├── tmp ├── .keep └── pids │ └── .keep └── vendor └── .keep /.github/workflows/ruby.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. 2 | # They are provided by a third-party and are governed by 3 | # separate terms of service, privacy policy, and support 4 | # documentation. 5 | # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake 6 | # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby 7 | 8 | name: Ruby 9 | 10 | on: 11 | push: 12 | branches: [ main ] 13 | pull_request: 14 | branches: [ main ] 15 | 16 | jobs: 17 | build: 18 | 19 | runs-on: ubuntu-latest 20 | 21 | steps: 22 | - uses: actions/checkout@master 23 | - name: Set up Ruby 2.7 24 | uses: actions/setup-ruby@v1 25 | with: 26 | version: 2.7.x 27 | - name: Build and test with Rake 28 | run: | 29 | gem install bundler 30 | bundle install --jobs 4 --retry 3 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore all logfiles and tempfiles. 11 | /log/* 12 | /tmp/* 13 | !/log/.keep 14 | !/tmp/.keep 15 | 16 | # Ignore pidfiles, but keep the directory. 17 | /tmp/pids/* 18 | !/tmp/pids/ 19 | !/tmp/pids/.keep 20 | 21 | # Ignore uploaded files in development. 22 | /storage/* 23 | !/storage/.keep 24 | .byebug_history 25 | 26 | # Ignore master key for decrypting credentials and more. 27 | /config/master.key 28 | 29 | .env 30 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | ruby-3.2.2 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 | 4 | ruby '3.2.2' 5 | 6 | # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 7 | gem 'rails', '~> 6.1.3', '>= 6.1.3.2' 8 | 9 | # Use postgresql as the database for Active Record 10 | #gem 'pg', '~> 1.2.3' 11 | 12 | # Use sqlite3 as the database for Active Record 13 | gem 'sqlite3', '~> 1.3', '>= 1.3.11' 14 | 15 | # Use Puma as the app server 16 | gem 'puma', '~> 5.6.8' 17 | # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 18 | gem 'jbuilder', '~> 2.11.2' 19 | # Use Redis adapter to run Action Cable in production 20 | # gem 'redis', '~> 4.0' 21 | # Use Active Model has_secure_password 22 | # gem 'bcrypt', '~> 3.1.7' 23 | 24 | # Use Active Storage variant 25 | # gem 'image_processing', '~> 1.2' 26 | 27 | # Reduces boot times through caching; required in config/boot.rb 28 | gem 'bootsnap', '>= 1.7.2', require: false 29 | 30 | # Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible 31 | gem 'rack-cors', require: 'rack/cors' 32 | 33 | gem 'nokogiri', '~> 1.16.2' 34 | 35 | gem 'will_paginate', '~> 3.3.0' 36 | 37 | gem 'active_model_serializers', '~> 0.10.2' 38 | 39 | group :development, :test do 40 | # Call 'byebug' anywhere in the code to stop execution and get a debugger console 41 | gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 42 | 43 | gem 'irb' , '~> 1.3.3' 44 | gem 'pry' , '~> 0.14.2' 45 | gem 'rspec-rails', '~> 4.0', '>= 4.0.2' 46 | end 47 | 48 | group :development do 49 | # Access an interactive console on exception pages or by calling 'console' anywhere in the code. 50 | gem 'web-console', '>= 4.1.0' 51 | # Display performance information such as SQL time and flame graphs for each request in your brow> 52 | # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-> 53 | gem 'rack-mini-profiler', '~> 2.3.1' 54 | gem 'listen', '~> 3.4.1' 55 | end 56 | 57 | group :test do 58 | # Adds support for Capybara system testing and selenium driver 59 | gem 'capybara', '>= 3.35.3' 60 | gem 'selenium-webdriver' 61 | # Easy installation and use of web drivers to run system tests with browsers 62 | gem 'webdrivers' 63 | end 64 | 65 | 66 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem 67 | gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 68 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actioncable (6.1.7.4) 5 | actionpack (= 6.1.7.4) 6 | activesupport (= 6.1.7.4) 7 | nio4r (~> 2.0) 8 | websocket-driver (>= 0.6.1) 9 | actionmailbox (6.1.7.4) 10 | actionpack (= 6.1.7.4) 11 | activejob (= 6.1.7.4) 12 | activerecord (= 6.1.7.4) 13 | activestorage (= 6.1.7.4) 14 | activesupport (= 6.1.7.4) 15 | mail (>= 2.7.1) 16 | actionmailer (6.1.7.4) 17 | actionpack (= 6.1.7.4) 18 | actionview (= 6.1.7.4) 19 | activejob (= 6.1.7.4) 20 | activesupport (= 6.1.7.4) 21 | mail (~> 2.5, >= 2.5.4) 22 | rails-dom-testing (~> 2.0) 23 | actionpack (6.1.7.4) 24 | actionview (= 6.1.7.4) 25 | activesupport (= 6.1.7.4) 26 | rack (~> 2.0, >= 2.0.9) 27 | rack-test (>= 0.6.3) 28 | rails-dom-testing (~> 2.0) 29 | rails-html-sanitizer (~> 1.0, >= 1.2.0) 30 | actiontext (6.1.7.4) 31 | actionpack (= 6.1.7.4) 32 | activerecord (= 6.1.7.4) 33 | activestorage (= 6.1.7.4) 34 | activesupport (= 6.1.7.4) 35 | nokogiri (>= 1.8.5) 36 | actionview (6.1.7.4) 37 | activesupport (= 6.1.7.4) 38 | builder (~> 3.1) 39 | erubi (~> 1.4) 40 | rails-dom-testing (~> 2.0) 41 | rails-html-sanitizer (~> 1.1, >= 1.2.0) 42 | active_model_serializers (0.10.13) 43 | actionpack (>= 4.1, < 7.1) 44 | activemodel (>= 4.1, < 7.1) 45 | case_transform (>= 0.2) 46 | jsonapi-renderer (>= 0.1.1.beta1, < 0.3) 47 | activejob (6.1.7.4) 48 | activesupport (= 6.1.7.4) 49 | globalid (>= 0.3.6) 50 | activemodel (6.1.7.4) 51 | activesupport (= 6.1.7.4) 52 | activerecord (6.1.7.4) 53 | activemodel (= 6.1.7.4) 54 | activesupport (= 6.1.7.4) 55 | activestorage (6.1.7.4) 56 | actionpack (= 6.1.7.4) 57 | activejob (= 6.1.7.4) 58 | activerecord (= 6.1.7.4) 59 | activesupport (= 6.1.7.4) 60 | marcel (~> 1.0) 61 | mini_mime (>= 1.1.0) 62 | activesupport (6.1.7.4) 63 | concurrent-ruby (~> 1.0, >= 1.0.2) 64 | i18n (>= 1.6, < 2) 65 | minitest (>= 5.1) 66 | tzinfo (~> 2.0) 67 | zeitwerk (~> 2.3) 68 | addressable (2.8.4) 69 | public_suffix (>= 2.0.2, < 6.0) 70 | bindex (0.8.1) 71 | bootsnap (1.16.0) 72 | msgpack (~> 1.2) 73 | builder (3.2.4) 74 | byebug (11.1.3) 75 | capybara (3.39.2) 76 | addressable 77 | matrix 78 | mini_mime (>= 0.1.3) 79 | nokogiri (~> 1.8) 80 | rack (>= 1.6.0) 81 | rack-test (>= 0.6.3) 82 | regexp_parser (>= 1.5, < 3.0) 83 | xpath (~> 3.2) 84 | case_transform (0.2) 85 | activesupport 86 | coderay (1.1.3) 87 | concurrent-ruby (1.2.2) 88 | crass (1.0.6) 89 | date (3.3.3) 90 | diff-lcs (1.5.0) 91 | erubi (1.12.0) 92 | ffi (1.15.5) 93 | globalid (1.1.0) 94 | activesupport (>= 5.0) 95 | i18n (1.14.1) 96 | concurrent-ruby (~> 1.0) 97 | io-console (0.6.0) 98 | irb (1.3.7) 99 | reline (>= 0.2.7) 100 | jbuilder (2.11.5) 101 | actionview (>= 5.0.0) 102 | activesupport (>= 5.0.0) 103 | jsonapi-renderer (0.2.2) 104 | listen (3.4.1) 105 | rb-fsevent (~> 0.10, >= 0.10.3) 106 | rb-inotify (~> 0.9, >= 0.9.10) 107 | loofah (2.21.3) 108 | crass (~> 1.0.2) 109 | nokogiri (>= 1.12.0) 110 | mail (2.8.1) 111 | mini_mime (>= 0.1.1) 112 | net-imap 113 | net-pop 114 | net-smtp 115 | marcel (1.0.2) 116 | matrix (0.4.2) 117 | method_source (1.0.0) 118 | mini_mime (1.1.2) 119 | minitest (5.18.1) 120 | msgpack (1.7.1) 121 | net-imap (0.3.6) 122 | date 123 | net-protocol 124 | net-pop (0.1.2) 125 | net-protocol 126 | net-protocol (0.2.1) 127 | timeout 128 | net-smtp (0.3.3) 129 | net-protocol 130 | nio4r (2.7.0) 131 | nokogiri (1.16.2-x86_64-linux) 132 | racc (~> 1.4) 133 | pry (0.14.2) 134 | coderay (~> 1.1) 135 | method_source (~> 1.0) 136 | public_suffix (5.0.1) 137 | puma (5.6.8) 138 | nio4r (~> 2.0) 139 | racc (1.7.3) 140 | rack (2.2.7) 141 | rack-cors (2.0.1) 142 | rack (>= 2.0.0) 143 | rack-mini-profiler (2.3.4) 144 | rack (>= 1.2.0) 145 | rack-test (2.1.0) 146 | rack (>= 1.3) 147 | rails (6.1.7.4) 148 | actioncable (= 6.1.7.4) 149 | actionmailbox (= 6.1.7.4) 150 | actionmailer (= 6.1.7.4) 151 | actionpack (= 6.1.7.4) 152 | actiontext (= 6.1.7.4) 153 | actionview (= 6.1.7.4) 154 | activejob (= 6.1.7.4) 155 | activemodel (= 6.1.7.4) 156 | activerecord (= 6.1.7.4) 157 | activestorage (= 6.1.7.4) 158 | activesupport (= 6.1.7.4) 159 | bundler (>= 1.15.0) 160 | railties (= 6.1.7.4) 161 | sprockets-rails (>= 2.0.0) 162 | rails-dom-testing (2.0.3) 163 | activesupport (>= 4.2.0) 164 | nokogiri (>= 1.6) 165 | rails-html-sanitizer (1.6.0) 166 | loofah (~> 2.21) 167 | nokogiri (~> 1.14) 168 | railties (6.1.7.4) 169 | actionpack (= 6.1.7.4) 170 | activesupport (= 6.1.7.4) 171 | method_source 172 | rake (>= 12.2) 173 | thor (~> 1.0) 174 | rake (13.0.6) 175 | rb-fsevent (0.11.2) 176 | rb-inotify (0.10.1) 177 | ffi (~> 1.0) 178 | regexp_parser (2.8.1) 179 | reline (0.3.5) 180 | io-console (~> 0.5) 181 | rexml (3.2.5) 182 | rspec-core (3.12.2) 183 | rspec-support (~> 3.12.0) 184 | rspec-expectations (3.12.3) 185 | diff-lcs (>= 1.2.0, < 2.0) 186 | rspec-support (~> 3.12.0) 187 | rspec-mocks (3.12.5) 188 | diff-lcs (>= 1.2.0, < 2.0) 189 | rspec-support (~> 3.12.0) 190 | rspec-rails (4.1.2) 191 | actionpack (>= 4.2) 192 | activesupport (>= 4.2) 193 | railties (>= 4.2) 194 | rspec-core (~> 3.10) 195 | rspec-expectations (~> 3.10) 196 | rspec-mocks (~> 3.10) 197 | rspec-support (~> 3.10) 198 | rspec-support (3.12.1) 199 | rubyzip (2.3.2) 200 | selenium-webdriver (4.10.0) 201 | rexml (~> 3.2, >= 3.2.5) 202 | rubyzip (>= 1.2.2, < 3.0) 203 | websocket (~> 1.0) 204 | sprockets (4.2.0) 205 | concurrent-ruby (~> 1.0) 206 | rack (>= 2.2.4, < 4) 207 | sprockets-rails (3.4.2) 208 | actionpack (>= 5.2) 209 | activesupport (>= 5.2) 210 | sprockets (>= 3.0.0) 211 | sqlite3 (1.6.3-x86_64-linux) 212 | thor (1.2.2) 213 | timeout (0.4.0) 214 | tzinfo (2.0.6) 215 | concurrent-ruby (~> 1.0) 216 | web-console (4.2.0) 217 | actionview (>= 6.0.0) 218 | activemodel (>= 6.0.0) 219 | bindex (>= 0.4.0) 220 | railties (>= 6.0.0) 221 | webdrivers (5.2.0) 222 | nokogiri (~> 1.6) 223 | rubyzip (>= 1.3.0) 224 | selenium-webdriver (~> 4.0) 225 | websocket (1.2.9) 226 | websocket-driver (0.7.5) 227 | websocket-extensions (>= 0.1.0) 228 | websocket-extensions (0.1.5) 229 | will_paginate (3.3.1) 230 | xpath (3.2.0) 231 | nokogiri (~> 1.8) 232 | zeitwerk (2.6.8) 233 | 234 | PLATFORMS 235 | x86_64-linux 236 | 237 | DEPENDENCIES 238 | active_model_serializers (~> 0.10.2) 239 | bootsnap (>= 1.7.2) 240 | byebug 241 | capybara (>= 3.35.3) 242 | irb (~> 1.3.3) 243 | jbuilder (~> 2.11.2) 244 | listen (~> 3.4.1) 245 | nokogiri (~> 1.16.2) 246 | pry (~> 0.14.2) 247 | puma (~> 5.6.8) 248 | rack-cors 249 | rack-mini-profiler (~> 2.3.1) 250 | rails (~> 6.1.3, >= 6.1.3.2) 251 | rspec-rails (~> 4.0, >= 4.0.2) 252 | selenium-webdriver 253 | sqlite3 (~> 1.3, >= 1.3.11) 254 | tzinfo-data 255 | web-console (>= 4.1.0) 256 | webdrivers 257 | will_paginate (~> 3.3.0) 258 | 259 | RUBY VERSION 260 | ruby 3.2.2p53 261 | 262 | BUNDLED WITH 263 | 2.4.15 264 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | Provincias de Angola API 3 |

4 | 5 | ## :clipboard: Descrição do projeto 6 | 7 | > API desenvolvida para fornecer dados de provincias e municipios do território Angolano 8 | 9 | ## :computer: Tecnologias 10 | 11 | Esse projeto foi desenvolvido utilizando: 12 | - [Ruby on Rails](https://rubyonrails.org/) 13 | - [PostgreSQL](https://www.postgresql.org/) 14 | 15 | ## :rocket: Como Iniciar 16 | 17 | - Faça um `git clone` do repositório; 18 | - Instale todas dependências rodando no terminal o comando `bundle`;
19 | - Configure o arquivo `database.yml` no diretório `config` na raíz do projecto;
20 | - Rode os seguintes comandos 21 | - `rake db:create`; 22 | - `rake db:migrate`; 23 | - `rake db:seed`; 24 | - `rails s` 25 | - Divirta-se :) 26 | 27 | ## :warning: Aviso! 28 | 29 | Esta API não deve ser usada em aplicativos para produção enquanto estiver hospedado no heroku com um plano gratuito que pode apresentar alguma lentidão ou instabilidade. 30 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require_relative 'config/application' 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /app/controllers/api/api_controller.rb: -------------------------------------------------------------------------------- 1 | class Api::ApiController < ApplicationController 2 | def index 3 | render :index, status: :ok 4 | rescue Exception => error 5 | render json: { 6 | status: 500, 7 | message: "error => #{error}" 8 | }, status: :internal_server_error 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /app/controllers/api/v1/previsao_controller.rb: -------------------------------------------------------------------------------- 1 | class Api::V1::PrevisaoController < ApplicationController 2 | before_action :set_county, only: [:show] 3 | 4 | def show 5 | if @provincia 6 | @previsao = Services::WeatherScraper.get @provincia.id 7 | render :previsao, status: :ok 8 | else 9 | render :province_not_found, status: :not_found 10 | end 11 | rescue Exception => error 12 | render json: { 13 | status: 500, 14 | message: "error => #{error}" 15 | }, status: :internal_server_error 16 | end 17 | 18 | private 19 | def set_county 20 | @provincia = Provincia.where(nome: params[:id].titleize).first 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /app/controllers/api/v1/provincias_controller.rb: -------------------------------------------------------------------------------- 1 | class Api::V1::ProvinciasController < ApplicationController 2 | def index 3 | @provincias = Provincia.all.paginate(page: params[:page], per_page: 9) 4 | render :index, status: :ok 5 | rescue Exception => error 6 | render json: { 7 | status: 500, 8 | message: "error => #{error}" 9 | }, status: :internal_server_error 10 | end 11 | 12 | def show 13 | @provincia = Provincia.where("nome LIKE ?", "%#{get_params}%") 14 | if !@provincia.empty? 15 | render :show, status: :found 16 | else 17 | render :province_not_found, status: :not_found 18 | end 19 | rescue Exception => error 20 | render json: { 21 | status: 500, 22 | message: "error => #{error}" 23 | }, status: :internal_server_error 24 | end 25 | 26 | private 27 | def get_params 28 | params[:id].titleize 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::API 2 | end 3 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gentildpinto/provincias_de_angola_api/98b4786ab9320e5a7502a31244462be1cdc73f7d/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | self.abstract_class = true 3 | end 4 | -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gentildpinto/provincias_de_angola_api/98b4786ab9320e5a7502a31244462be1cdc73f7d/app/models/concerns/.keep -------------------------------------------------------------------------------- /app/models/provincia.rb: -------------------------------------------------------------------------------- 1 | class Provincia < ApplicationRecord 2 | end 3 | -------------------------------------------------------------------------------- /app/views/api/api/index.json.jbuilder: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | json.title "AngoProvsAPI" 4 | json.description "API desenvolvida para fornecer dados de provincias e municipios do território Angolano." 5 | json.author "Gentil Pinto" 6 | json.project do 7 | json.github_link "https://github.com/GentilPinto/provincias_de_angola_api" 8 | json.tecnologies do 9 | json.programming_language "Ruby" 10 | json.framework "Ruby on Rails" 11 | json.database "PostgreSQL" 12 | end 13 | end 14 | json.endpoints do 15 | json.index "http://angoprovsapi.herokuapp.com/" 16 | json.get_all_provinces "http://angoprovsapi.herokuapp.com/api/v1/provincias" 17 | json.get_a_single_province "http://angoprovsapi.herokuapp.com/api/v1/provincias/{provincia}" 18 | json.weather_forecast "http://angoprovsapi.herokuapp.com/api/v1/previsao/{provincia}" 19 | end 20 | -------------------------------------------------------------------------------- /app/views/api/v1/previsao/previsao.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.status 200 2 | json.provincia @provincia.nome 3 | json.previsao_de_tempo_actual @previsao -------------------------------------------------------------------------------- /app/views/api/v1/previsao/province_not_found.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.status 404 2 | json.message "provincia não encontrada" 3 | -------------------------------------------------------------------------------- /app/views/api/v1/provincias/index.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.status 200 2 | json.message "provincias de Angola" 3 | json.current_page @provincias.current_page 4 | json.provincia(@provincias) do |provincia| 5 | json.id provincia.id 6 | json.nome provincia.nome 7 | json.fundada provincia.fundada 8 | json.capital provincia.capital 9 | json.area provincia.area 10 | json.prefixo_telefonico provincia.prefixo_telefonico 11 | json.site_governo_provincial provincia.site_governo_provincial 12 | json.municipios provincia.municipios 13 | end 14 | json.per_page @provincias.per_page 15 | json.last_page @provincias.total_pages 16 | json.total_pages @provincias.total_pages 17 | json.navigate_to_other_page "http://angoprovsapi.herokuapp.com/api/v1/provincias?page={type_the_page_number_here}" 18 | -------------------------------------------------------------------------------- /app/views/api/v1/provincias/province_not_found.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.status 404 2 | json.message "provincia não encontrada" 3 | -------------------------------------------------------------------------------- /app/views/api/v1/provincias/show.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.status 302 2 | json.provincia @provincia 3 | -------------------------------------------------------------------------------- /bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'bundle' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "rubygems" 12 | 13 | m = Module.new do 14 | module_function 15 | 16 | def invoked_as_script? 17 | File.expand_path($0) == File.expand_path(__FILE__) 18 | end 19 | 20 | def env_var_version 21 | ENV["BUNDLER_VERSION"] 22 | end 23 | 24 | def cli_arg_version 25 | return unless invoked_as_script? # don't want to hijack other binstubs 26 | return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` 27 | bundler_version = nil 28 | update_index = nil 29 | ARGV.each_with_index do |a, i| 30 | if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN 31 | bundler_version = a 32 | end 33 | next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ 34 | bundler_version = $1 35 | update_index = i 36 | end 37 | bundler_version 38 | end 39 | 40 | def gemfile 41 | gemfile = ENV["BUNDLE_GEMFILE"] 42 | return gemfile if gemfile && !gemfile.empty? 43 | 44 | File.expand_path("../../Gemfile", __FILE__) 45 | end 46 | 47 | def lockfile 48 | lockfile = 49 | case File.basename(gemfile) 50 | when "gems.rb" then gemfile.sub(/\.rb$/, gemfile) 51 | else "#{gemfile}.lock" 52 | end 53 | File.expand_path(lockfile) 54 | end 55 | 56 | def lockfile_version 57 | return unless File.file?(lockfile) 58 | lockfile_contents = File.read(lockfile) 59 | return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ 60 | Regexp.last_match(1) 61 | end 62 | 63 | def bundler_version 64 | @bundler_version ||= 65 | env_var_version || cli_arg_version || 66 | lockfile_version 67 | end 68 | 69 | def bundler_requirement 70 | return "#{Gem::Requirement.default}.a" unless bundler_version 71 | 72 | bundler_gem_version = Gem::Version.new(bundler_version) 73 | 74 | requirement = bundler_gem_version.approximate_recommendation 75 | 76 | return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0") 77 | 78 | requirement += ".a" if bundler_gem_version.prerelease? 79 | 80 | requirement 81 | end 82 | 83 | def load_bundler! 84 | ENV["BUNDLE_GEMFILE"] ||= gemfile 85 | 86 | activate_bundler 87 | end 88 | 89 | def activate_bundler 90 | gem_error = activation_error_handling do 91 | gem "bundler", bundler_requirement 92 | end 93 | return if gem_error.nil? 94 | require_error = activation_error_handling do 95 | require "bundler/version" 96 | end 97 | return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) 98 | warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" 99 | exit 42 100 | end 101 | 102 | def activation_error_handling 103 | yield 104 | nil 105 | rescue StandardError, LoadError => e 106 | e 107 | end 108 | end 109 | 110 | m.load_bundler! 111 | 112 | if m.invoked_as_script? 113 | load Gem.bin_path("bundler", "bundle") 114 | end 115 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path('../config/application', __dir__) 3 | require_relative "../config/boot" 4 | require "rails/commands" 5 | -------------------------------------------------------------------------------- /bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative "../config/boot" 3 | require "rake" 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require "fileutils" 3 | 4 | # path to your application root. 5 | APP_ROOT = File.expand_path('..', __dir__) 6 | 7 | def system!(*args) 8 | system(*args) || abort("\n== Command #{args} failed ==") 9 | end 10 | 11 | FileUtils.chdir APP_ROOT do 12 | # This script is a way to set up or update your development environment automatically. 13 | # This script is idempotent, so that you can run it at any time and get an expectable outcome. 14 | # Add necessary setup steps to this file. 15 | 16 | puts '== Installing dependencies ==' 17 | system! 'gem install bundler --conservative' 18 | system('bundle check') || system!('bundle install') 19 | 20 | # puts "\n== Copying sample files ==" 21 | # unless File.exist?('config/database.yml') 22 | # FileUtils.cp 'config/database.yml.sample', 'config/database.yml' 23 | # end 24 | 25 | puts "\n== Preparing database ==" 26 | system! 'bin/rails db:prepare' 27 | 28 | puts "\n== Removing old logs and tempfiles ==" 29 | system! 'bin/rails log:clear tmp:clear' 30 | 31 | puts "\n== Restarting application server ==" 32 | system! 'bin/rails restart' 33 | end 34 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require_relative "config/environment" 4 | 5 | run Rails.application 6 | Rails.application.load_server 7 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | require_relative "boot" 2 | 3 | require "rails" 4 | # Pick the frameworks you want: 5 | require "active_model/railtie" 6 | # require "active_job/railtie" 7 | require "active_record/railtie" 8 | # require "active_storage/engine" 9 | require "action_controller/railtie" 10 | # require "action_mailer/railtie" 11 | # require "action_mailbox/engine" 12 | # require "action_text/engine" 13 | require "action_view/railtie" 14 | # require "action_cable/engine" 15 | # require "sprockets/railtie" 16 | # require "rails/test_unit/railtie" 17 | 18 | # Require the gems listed in Gemfile, including any gems 19 | # you've limited to :test, :development, or :production. 20 | Bundler.require(*Rails.groups) 21 | 22 | module ProvinciasDeAngolaAPI 23 | class Application < Rails::Application 24 | # Initialize configuration defaults for originally generated Rails version. 25 | config.load_defaults 6.1 26 | 27 | # Configuration for the application, engines, and railties goes here. 28 | # 29 | # These settings can be overridden in specific environments using the files 30 | # in config/environments, which are processed later. 31 | # 32 | # config.time_zone = "Central Time (US & Canada)" 33 | # config.eager_load_paths << Rails.root.join("extras") 34 | config.autoload_paths += Dir["#{config.root}/lib/**/"] 35 | 36 | # Only loads a smaller set of middleware suitable for API only apps. 37 | # Middleware like session, flash, cookies can be added back manually. 38 | # Skip views, helpers and assets when generating a new resource. 39 | config.api_only = true 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) 2 | 3 | require "bundler/setup" # Set up gems listed in the Gemfile. 4 | require "bootsnap/setup" # Speed up boot time by caching expensive operations. 5 | -------------------------------------------------------------------------------- /config/cable.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: async 3 | 4 | test: 5 | adapter: test 6 | 7 | production: 8 | adapter: redis 9 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> 10 | channel_prefix: provinciasDeAngolaAPI_production 11 | -------------------------------------------------------------------------------- /config/credentials.yml.enc: -------------------------------------------------------------------------------- 1 | OTYi6AjiuSlv0QjdeqpcI0JfvhO0DjC0Mvsj0o9oKxYNBv+2+cggeFdxtByJhQndYkhpvq3YSiYH3XxNkeddhrqzeu5G2xD06NlB7vgLrQnaPrQc43Np0ZLQlr9ryHMS2Bvj+t50TpInJA6yTFiLapTCnd0A2MXx5drP0DyulPMrZqsiYSoyrVTffFAf5nTlO/7bwLX5bOdCLaYCWlqcqOQUzBYTAanA0iM2fAOHSWQ9HXji3CYFdxFeYCtvQzm5SE8EcnnYopD98VbewzER7HYVfeWEQZqWSo+bnu3XBk8T9KQ9HQ0JE5nrHZ2HhlnUqsk0193j4CNwO+cUmiaE+ZmxSUTL5XHcHql1pkYW8PjSXP78Iq1jXchxaj/8pA4e1dkSC6+FpLrEwyTR3QitAXZB1xd9hvkauq7M--X86LV1+G00NVi36d--huiPyj1rKGTUySwQpptWWw== -------------------------------------------------------------------------------- /config/database.yml: -------------------------------------------------------------------------------- 1 | # PostgreSQL. Versions 9.3 and up are supported. 2 | # 3 | # Install the pg driver: 4 | # gem install pg 5 | # On macOS with Homebrew: 6 | # gem install pg -- --with-pg-config=/usr/local/bin/pg_config 7 | # On macOS with MacPorts: 8 | # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config 9 | # On Windows: 10 | # gem install pg 11 | # Choose the win32 build. 12 | # Install PostgreSQL and put its /bin directory on your path. 13 | # 14 | # Configure Using Gemfile 15 | # gem 'pg' 16 | # 17 | default: &default 18 | adapter: sqlite3 19 | timeout: 5000 20 | encoding: unicode 21 | # For details on connection pooling, see Rails configuration guide 22 | # https://guides.rubyonrails.org/configuring.html#database-pooling 23 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 24 | # username: <%= ENV['PROVINCIASDEANGOLAAPI_DATABASE_USER'] %> 25 | # password: <%= ENV['PROVINCIASDEANGOLAAPI_DATABASE_PASSWORD'] %> 26 | 27 | development: 28 | <<: *default 29 | database: db/development.sqlite3 30 | 31 | # The specified database role being used to connect to postgres. 32 | # To create additional roles in postgres see `$ createuser --help`. 33 | # When left blank, postgres will use the default role. This is 34 | # the same name as the operating system user that initialized the database. 35 | #username: provinciasDeAngolaAPI 36 | 37 | # The password associated with the postgres role (username). 38 | #password: 39 | 40 | # Connect on a TCP socket. Omitted by default since the client uses a 41 | # domain socket that doesn't need configuration. Windows does not have 42 | # domain sockets, so uncomment these lines. 43 | #host: localhost 44 | 45 | # The TCP port the server listens on. Defaults to 5432. 46 | # If your server runs on a different port number, change accordingly. 47 | #port: 5432 48 | 49 | # Schema search path. The server defaults to $user,public 50 | #schema_search_path: myapp,sharedapp,public 51 | 52 | # Minimum log levels, in increasing order: 53 | # debug5, debug4, debug3, debug2, debug1, 54 | # log, notice, warning, error, fatal, and panic 55 | # Defaults to warning. 56 | #min_messages: notice 57 | 58 | # Warning: The database defined as "test" will be erased and 59 | # re-generated from your development database when you run "rake". 60 | # Do not set this db to the same as development or production. 61 | test: 62 | <<: *default 63 | database: db/test.sqlite3 64 | 65 | # As with config/credentials.yml, you never want to store sensitive information, 66 | # like your database password, in your source code. If your source code is 67 | # ever seen by anyone, they now have access to your database. 68 | # 69 | # Instead, provide the password as a unix environment variable when you boot 70 | # the app. Read https://guides.rubyonrails.org/configuring.html#configuring-a-database 71 | # for a full rundown on how to provide these environment variables in a 72 | # production deployment. 73 | # 74 | # On Heroku and other platform providers, you may have a full connection URL 75 | # available as an environment variable. For example: 76 | # 77 | # DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" 78 | # 79 | # You can use this database configuration with: 80 | # 81 | # production: 82 | # url: <%= ENV['DATABASE_URL'] %> 83 | # 84 | production: 85 | <<: *default 86 | database: db/production.sqlite3 87 | 88 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative "application" 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /config/environments/development.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | # In the development environment your application's code is reloaded any time 7 | # it changes. This slows down response time but is perfect for development 8 | # since you don't have to restart the web server when you make code changes. 9 | config.cache_classes = false 10 | 11 | # Do not eager load code on boot. 12 | config.eager_load = false 13 | 14 | # Show full error reports. 15 | config.consider_all_requests_local = true 16 | 17 | # Enable/disable caching. By default caching is disabled. 18 | # Run rails dev:cache to toggle caching. 19 | if Rails.root.join('tmp', 'caching-dev.txt').exist? 20 | config.cache_store = :memory_store 21 | config.public_file_server.headers = { 22 | 'Cache-Control' => "public, max-age=#{2.days.to_i}" 23 | } 24 | else 25 | config.action_controller.perform_caching = false 26 | 27 | config.cache_store = :null_store 28 | end 29 | 30 | # Print deprecation notices to the Rails logger. 31 | config.active_support.deprecation = :log 32 | 33 | # Raise exceptions for disallowed deprecations. 34 | config.active_support.disallowed_deprecation = :raise 35 | 36 | # Tell Active Support which deprecation messages to disallow. 37 | config.active_support.disallowed_deprecation_warnings = [] 38 | 39 | # Raise an error on page load if there are pending migrations. 40 | config.active_record.migration_error = :page_load 41 | 42 | # Highlight code that triggered database queries in logs. 43 | config.active_record.verbose_query_logs = true 44 | 45 | 46 | # Raises error for missing translations. 47 | # config.i18n.raise_on_missing_translations = true 48 | 49 | # Annotate rendered view with file names. 50 | # config.action_view.annotate_rendered_view_with_filenames = true 51 | 52 | # Use an evented file watcher to asynchronously detect changes in source code, 53 | # routes, locales, etc. This feature depends on the listen gem. 54 | config.file_watcher = ActiveSupport::EventedFileUpdateChecker 55 | 56 | # Uncomment if you wish to allow Action Cable access from any origin. 57 | # config.action_cable.disable_request_forgery_protection = true 58 | end 59 | -------------------------------------------------------------------------------- /config/environments/production.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | # Code is not reloaded between requests. 7 | config.cache_classes = true 8 | 9 | # Eager load code on boot. This eager loads most of Rails and 10 | # your application in memory, allowing both threaded web servers 11 | # and those relying on copy on write to perform better. 12 | # Rake tasks automatically ignore this option for performance. 13 | config.eager_load = true 14 | 15 | # Full error reports are disabled and caching is turned on. 16 | config.consider_all_requests_local = false 17 | 18 | # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] 19 | # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). 20 | # config.require_master_key = true 21 | 22 | # Disable serving static files from the `/public` folder by default since 23 | # Apache or NGINX already handles this. 24 | config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? 25 | 26 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 27 | # config.asset_host = 'http://assets.example.com' 28 | 29 | # Specifies the header that your server uses for sending files. 30 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 31 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 32 | 33 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 34 | # config.force_ssl = true 35 | 36 | # Include generic and useful information about system operation, but avoid logging too much 37 | # information to avoid inadvertent exposure of personally identifiable information (PII). 38 | config.log_level = :info 39 | 40 | # Prepend all log lines with the following tags. 41 | config.log_tags = [ :request_id ] 42 | 43 | # Use a different cache store in production. 44 | # config.cache_store = :mem_cache_store 45 | 46 | # Use a real queuing backend for Active Job (and separate queues per environment). 47 | # config.active_job.queue_adapter = :resque 48 | # config.active_job.queue_name_prefix = "provincias_de_angola_api_production" 49 | 50 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 51 | # the I18n.default_locale when a translation cannot be found). 52 | config.i18n.fallbacks = true 53 | 54 | # Send deprecation notices to registered listeners. 55 | config.active_support.deprecation = :notify 56 | 57 | # Log disallowed deprecations. 58 | config.active_support.disallowed_deprecation = :log 59 | 60 | # Tell Active Support which deprecation messages to disallow. 61 | config.active_support.disallowed_deprecation_warnings = [] 62 | 63 | # Use default logging formatter so that PID and timestamp are not suppressed. 64 | config.log_formatter = ::Logger::Formatter.new 65 | 66 | # Use a different logger for distributed setups. 67 | # require "syslog/logger" 68 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') 69 | 70 | if ENV["RAILS_LOG_TO_STDOUT"].present? 71 | logger = ActiveSupport::Logger.new(STDOUT) 72 | logger.formatter = config.log_formatter 73 | config.logger = ActiveSupport::TaggedLogging.new(logger) 74 | end 75 | 76 | # Do not dump schema after migrations. 77 | config.active_record.dump_schema_after_migration = false 78 | 79 | # Inserts middleware to perform automatic connection switching. 80 | # The `database_selector` hash is used to pass options to the DatabaseSelector 81 | # middleware. The `delay` is used to determine how long to wait after a write 82 | # to send a subsequent read to the primary. 83 | # 84 | # The `database_resolver` class is used by the middleware to determine which 85 | # database is appropriate to use based on the time delay. 86 | # 87 | # The `database_resolver_context` class is used by the middleware to set 88 | # timestamps for the last write to the primary. The resolver uses the context 89 | # class timestamps to determine how long to wait before reading from the 90 | # replica. 91 | # 92 | # By default Rails will store a last write timestamp in the session. The 93 | # DatabaseSelector middleware is designed as such you can define your own 94 | # strategy for connection switching and pass that into the middleware through 95 | # these configuration options. 96 | # config.active_record.database_selector = { delay: 2.seconds } 97 | # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver 98 | # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session 99 | end 100 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | # The test environment is used exclusively to run your application's 4 | # test suite. You never need to work with it otherwise. Remember that 5 | # your test database is "scratch space" for the test suite and is wiped 6 | # and recreated between test runs. Don't rely on the data there! 7 | 8 | Rails.application.configure do 9 | # Settings specified here will take precedence over those in config/application.rb. 10 | 11 | config.cache_classes = true 12 | 13 | # Do not eager load code on boot. This avoids loading your whole application 14 | # just for the purpose of running a single test. If you are using a tool that 15 | # preloads Rails for running tests, you may have to set it to true. 16 | config.eager_load = false 17 | 18 | # Configure public file server for tests with Cache-Control for performance. 19 | config.public_file_server.enabled = true 20 | config.public_file_server.headers = { 21 | 'Cache-Control' => "public, max-age=#{1.hour.to_i}" 22 | } 23 | 24 | # Show full error reports and disable caching. 25 | config.consider_all_requests_local = true 26 | config.action_controller.perform_caching = false 27 | config.cache_store = :null_store 28 | 29 | # Raise exceptions instead of rendering exception templates. 30 | config.action_dispatch.show_exceptions = false 31 | 32 | # Disable request forgery protection in test environment. 33 | config.action_controller.allow_forgery_protection = false 34 | 35 | # Print deprecation notices to the stderr. 36 | config.active_support.deprecation = :stderr 37 | 38 | # Raise exceptions for disallowed deprecations. 39 | config.active_support.disallowed_deprecation = :raise 40 | 41 | # Tell Active Support which deprecation messages to disallow. 42 | config.active_support.disallowed_deprecation_warnings = [] 43 | 44 | # Raises error for missing translations. 45 | # config.i18n.raise_on_missing_translations = true 46 | 47 | # Annotate rendered view with file names. 48 | # config.action_view.annotate_rendered_view_with_filenames = true 49 | end 50 | -------------------------------------------------------------------------------- /config/initializers/application_controller_renderer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # ActiveSupport::Reloader.to_prepare do 4 | # ApplicationController.renderer.defaults.merge!( 5 | # http_host: 'example.org', 6 | # https: false 7 | # ) 8 | # end 9 | -------------------------------------------------------------------------------- /config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| /my_noisy_library/.match?(line) } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code 7 | # by setting BACKTRACE=1 before calling your invocation, like "BACKTRACE=1 ./bin/rails runner 'MyClass.perform'". 8 | Rails.backtrace_cleaner.remove_silencers! if ENV["BACKTRACE"] 9 | -------------------------------------------------------------------------------- /config/initializers/cors.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Avoid CORS issues when API is called from the frontend app. 4 | # Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests. 5 | 6 | # Read more: https://github.com/cyu/rack-cors 7 | 8 | Rails.application.config.middleware.insert_before 0, Rack::Cors do 9 | allow do 10 | origins '*' 11 | 12 | resource '*', 13 | headers: :any, 14 | methods: [:get] 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [ 5 | :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn 6 | ] 7 | -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, '\1en' 8 | # inflect.singular /^(ox)en/i, '\1' 9 | # inflect.irregular 'person', 'people' 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym 'RESTful' 16 | # end 17 | -------------------------------------------------------------------------------- /config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | -------------------------------------------------------------------------------- /config/initializers/new_framework_defaults_6_1.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | # 3 | # This file contains migration options to ease your Rails 6.1 upgrade. 4 | # 5 | # Once upgraded flip defaults one by one to migrate to the new default. 6 | # 7 | # Read the Guide for Upgrading Ruby on Rails for more info on each option. 8 | 9 | # Support for inversing belongs_to -> has_many Active Record associations. 10 | # Rails.application.config.active_record.has_many_inversing = true 11 | 12 | # Track Active Storage variants in the database. 13 | # Rails.application.config.active_storage.track_variants = true 14 | 15 | # Apply random variation to the delay when retrying failed jobs. 16 | # Rails.application.config.active_job.retry_jitter = 0.15 17 | 18 | # Stop executing `after_enqueue`/`after_perform` callbacks if 19 | # `before_enqueue`/`before_perform` respectively halts with `throw :abort`. 20 | # Rails.application.config.active_job.skip_after_callbacks_if_terminated = true 21 | 22 | # Specify cookies SameSite protection level: either :none, :lax, or :strict. 23 | # 24 | # This change is not backwards compatible with earlier Rails versions. 25 | # It's best enabled when your entire app is migrated and stable on 6.1. 26 | # Rails.application.config.action_dispatch.cookies_same_site_protection = :lax 27 | 28 | # Generate CSRF tokens that are encoded in URL-safe Base64. 29 | # 30 | # This change is not backwards compatible with earlier Rails versions. 31 | # It's best enabled when your entire app is migrated and stable on 6.1. 32 | # Rails.application.config.action_controller.urlsafe_csrf_tokens = true 33 | 34 | # Specify whether `ActiveSupport::TimeZone.utc_to_local` returns a time with an 35 | # UTC offset or a UTC time. 36 | # ActiveSupport.utc_to_local_returns_utc_offset_times = true 37 | 38 | # Change the default HTTP status code to `308` when redirecting non-GET/HEAD 39 | # requests to HTTPS in `ActionDispatch::SSL` middleware. 40 | # Rails.application.config.action_dispatch.ssl_default_redirect_status = 308 41 | 42 | # Use new connection handling API. For most applications this won't have any 43 | # effect. For applications using multiple databases, this new API provides 44 | # support for granular connection swapping. 45 | # Rails.application.config.active_record.legacy_connection_handling = false 46 | 47 | # Make `form_with` generate non-remote forms by default. 48 | # Rails.application.config.action_view.form_with_generates_remote_forms = false 49 | 50 | # Set the default queue name for the analysis job to the queue adapter default. 51 | # Rails.application.config.active_storage.queues.analysis = nil 52 | 53 | # Set the default queue name for the purge job to the queue adapter default. 54 | # Rails.application.config.active_storage.queues.purge = nil 55 | 56 | # Set the default queue name for the incineration job to the queue adapter default. 57 | # Rails.application.config.action_mailbox.queues.incineration = nil 58 | 59 | # Set the default queue name for the routing job to the queue adapter default. 60 | # Rails.application.config.action_mailbox.queues.routing = nil 61 | 62 | # Set the default queue name for the mail deliver job to the queue adapter default. 63 | # Rails.application.config.action_mailer.deliver_later_queue_name = nil 64 | 65 | # Generate a `Link` header that gives a hint to modern browsers about 66 | # preloading assets when using `javascript_include_tag` and `stylesheet_link_tag`. 67 | # Rails.application.config.action_view.preload_links_header = true 68 | -------------------------------------------------------------------------------- /config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] 9 | end 10 | 11 | # To enable root element in JSON for ActiveRecord objects. 12 | # ActiveSupport.on_load(:active_record) do 13 | # self.include_root_in_json = true 14 | # end 15 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # The following keys must be escaped otherwise they will not be retrieved by 20 | # the default I18n backend: 21 | # 22 | # true, false, on, off, yes, no 23 | # 24 | # Instead, surround them with single quotes. 25 | # 26 | # en: 27 | # 'true': 'foo' 28 | # 29 | # To learn more, please read the Rails Internationalization guide 30 | # available at https://guides.rubyonrails.org/i18n.html. 31 | 32 | en: 33 | hello: "Hello world" 34 | -------------------------------------------------------------------------------- /config/puma.rb: -------------------------------------------------------------------------------- 1 | # Puma can serve each request in a thread from an internal thread pool. 2 | # The `threads` method setting takes two numbers: a minimum and maximum. 3 | # Any libraries that use thread pools should be configured to match 4 | # the maximum value specified for Puma. Default is set to 5 threads for minimum 5 | # and maximum; this matches the default thread size of Active Record. 6 | # 7 | max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } 8 | min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } 9 | threads min_threads_count, max_threads_count 10 | 11 | # Specifies the `worker_timeout` threshold that Puma will use to wait before 12 | # terminating a worker in development environments. 13 | # 14 | worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" 15 | 16 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000. 17 | # 18 | port ENV.fetch("PORT") { 3000 } 19 | 20 | # Specifies the `environment` that Puma will run in. 21 | # 22 | environment ENV.fetch("RAILS_ENV") { "development" } 23 | 24 | # Specifies the `pidfile` that Puma will use. 25 | pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } 26 | 27 | # Specifies the number of `workers` to boot in clustered mode. 28 | # Workers are forked web server processes. If using threads and workers together 29 | # the concurrency of the application would be max `threads` * `workers`. 30 | # Workers do not work on JRuby or Windows (both of which do not support 31 | # processes). 32 | # 33 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 } 34 | 35 | # Use the `preload_app!` method when specifying a `workers` number. 36 | # This directive tells Puma to first boot the application and load code 37 | # before forking the application. This takes advantage of Copy On Write 38 | # process behavior so workers use less memory. 39 | # 40 | # preload_app! 41 | 42 | # Allow puma to be restarted by `rails restart` command. 43 | plugin :tmp_restart 44 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html 3 | root 'api/api#index', defaults: {format: :json} 4 | namespace :api, defaults: {format: :json} do 5 | namespace :v1, defaults: {format: :json} do 6 | resources :provincias, only: [:index, :show] 7 | resources :previsao, only: [:show] 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /config/spring.rb: -------------------------------------------------------------------------------- 1 | Spring.watch( 2 | ".ruby-version", 3 | ".rbenv-vars", 4 | "tmp/restart.txt", 5 | "tmp/caching-dev.txt" 6 | ) 7 | -------------------------------------------------------------------------------- /config/storage.yml: -------------------------------------------------------------------------------- 1 | test: 2 | service: Disk 3 | root: <%= Rails.root.join("tmp/storage") %> 4 | 5 | local: 6 | service: Disk 7 | root: <%= Rails.root.join("storage") %> 8 | 9 | # Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) 10 | # amazon: 11 | # service: S3 12 | # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> 13 | # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> 14 | # region: us-east-1 15 | # bucket: your_own_bucket 16 | 17 | # Remember not to checkin your GCS keyfile to a repository 18 | # google: 19 | # service: GCS 20 | # project: your_project 21 | # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> 22 | # bucket: your_own_bucket 23 | 24 | # Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) 25 | # microsoft: 26 | # service: AzureStorage 27 | # storage_account_name: your_account_name 28 | # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> 29 | # container: your_container_name 30 | 31 | # mirror: 32 | # service: Mirror 33 | # primary: local 34 | # mirrors: [ amazon, google, microsoft ] 35 | -------------------------------------------------------------------------------- /db/development.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gentildpinto/provincias_de_angola_api/98b4786ab9320e5a7502a31244462be1cdc73f7d/db/development.sqlite3 -------------------------------------------------------------------------------- /db/migrate/20200603115236_create_provincia.rb: -------------------------------------------------------------------------------- 1 | class CreateProvincia < ActiveRecord::Migration[6.0] 2 | def change 3 | create_table :provincia do |t| 4 | t.string :nome 5 | t.string :capital 6 | t.string :fundada 7 | t.string :area 8 | t.string :prefixo_telefonico 9 | t.string :site_governo_provincial 10 | t.string :municipios, array: true, default: [].to_yaml 11 | 12 | # t.timestamps 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /db/schema.rb: -------------------------------------------------------------------------------- 1 | # This file is auto-generated from the current state of the database. Instead 2 | # of editing this file, please use the migrations feature of Active Record to 3 | # incrementally modify your database, and then regenerate this schema definition. 4 | # 5 | # This file is the source Rails uses to define your schema when running `bin/rails 6 | # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to 7 | # be faster and is potentially less error prone than running all of your 8 | # migrations from scratch. Old migrations may fail to apply correctly if those 9 | # migrations use external dependencies or application code. 10 | # 11 | # It's strongly recommended that you check this file into your version control system. 12 | 13 | ActiveRecord::Schema.define(version: 2020_06_03_115236) do 14 | 15 | create_table "provincia", force: :cascade do |t| 16 | t.string "nome" 17 | t.string "capital" 18 | t.string "fundada" 19 | t.string "area" 20 | t.string "prefixo_telefonico" 21 | t.string "site_governo_provincial" 22 | t.string "municipios", default: "--- []\n" 23 | end 24 | 25 | end 26 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) 7 | # Character.create(name: 'Luke', movie: movies.first) 8 | 9 | Provincia.create([ 10 | { 11 | nome: 'Bengo', 12 | fundada: '26 de Abril de 1980', 13 | capital: 'Caxito', 14 | area: '31.371 km²', 15 | prefixo_telefonico: '034', 16 | site_governo_provincial: 'https://www.bengo.gov.ao', 17 | municipios: [ 18 | 'Ambriz', 19 | 'Bula Atumba', 20 | 'Dande', 21 | 'Dembos', 22 | 'Nambuangongo', 23 | 'Pango Aluquém' 24 | ] 25 | }, 26 | { 27 | nome: 'Benguela', 28 | fundada: '1617', 29 | capital: 'Benguela', 30 | area: '39.827 km²', 31 | prefixo_telefonico: '+244', 32 | site_governo_provincial: 'https://www.benguela.gov.ao', 33 | municipios: [ 34 | 'Balombo', 35 | 'Baía Farta', 36 | 'Benguela', 37 | 'Bocoio', 38 | 'Caimbambo', 39 | 'Catumbela', 40 | 'Chongorói', 41 | 'Cubal', 42 | 'Ganda', 43 | 'Lobito' 44 | ] 45 | }, 46 | { 47 | nome: 'Bié', 48 | fundada: '1 de Maio de 1922', 49 | capital: 'Cuíto', 50 | area: '70.314 km²', 51 | prefixo_telefonico: '+244', 52 | site_governo_provincial: 'https://www.bie.gov.ao', 53 | municipios: [ 54 | 'Andulo', 55 | 'Camacupa', 56 | 'Catabola', 57 | 'Chinguar', 58 | 'Chitembo', 59 | 'Cuemba', 60 | 'Cunhinga', 61 | 'Cuíto', 62 | 'Nharea' 63 | ] 64 | }, 65 | { 66 | nome: 'Cabinda', 67 | fundada: '28 de Fevereiro de 1919', 68 | capital: 'Cabinda', 69 | area: '7.283 km²', 70 | prefixo_telefonico: '+244', 71 | site_governo_provincial: 'https://www.cabinda.gov.ao', 72 | municipios: [ 73 | 'Belize', 74 | 'Buco-Zau', 75 | 'Cabinda', 76 | 'Cacongo' 77 | ] 78 | }, 79 | { 80 | nome: 'Cuando Cubango', 81 | fundada: '21 de Outubro de 1961', 82 | capital: 'Menongue', 83 | area: '199.049 km²', 84 | prefixo_telefonico: '049', 85 | site_governo_provincial: 'https://www.cuandocubango.gov.ao', 86 | municipios: [ 87 | 'Calai', 88 | 'Cuangar', 89 | 'Cuchi', 90 | 'Cuito Cuanavale', 91 | 'Dirico', 92 | 'Mavinga', 93 | 'Menongue', 94 | 'Nancova', 95 | 'Rivungo' 96 | ] 97 | }, 98 | { 99 | nome: 'Cuanza Norte', 100 | fundada: '15 de Agosto de 1914', 101 | capital: 'Ndalatando', 102 | area: '24.110 km²', 103 | prefixo_telefonico: '035', 104 | site_governo_provincial: 'https://www.cuanzanorte.gov.ao', 105 | municipios: [ 106 | 'Ambaca', 107 | 'Banga', 108 | 'Bolongongo', 109 | 'Cambambe', 110 | 'Cazengo', 111 | 'Golungo Alto', 112 | 'Gonguembo', 113 | 'Lucala', 114 | 'Quiculungo', 115 | 'Samba Caju' 116 | ] 117 | }, 118 | { 119 | nome: 'Cuanza Sul', 120 | fundada: '15 de Setembro de 1917', 121 | capital: 'Sumbe', 122 | area: '55.660 km²', 123 | prefixo_telefonico: '+244', 124 | site_governo_provincial: 'https://www.cuanzasul.gov.ao', 125 | municipios: [ 126 | 'Amboim', 127 | 'Cassongue', 128 | 'Cela', 129 | 'Conda', 130 | 'Ebo', 131 | 'Libolo', 132 | 'Mussende', 133 | 'Porto Amboim', 134 | 'Quibala', 135 | 'Quilenda', 136 | 'Seles', 137 | 'Sumbe' 138 | ] 139 | }, 140 | { 141 | nome: 'Cunene', 142 | fundada: '10 de Julho de 1970', 143 | capital: 'Ondjiva', 144 | area: '78.342 km²', 145 | prefixo_telefonico: '035', 146 | site_governo_provincial: 'https://www.cunene.gov.ao', 147 | municipios: [ 148 | 'Cahama', 149 | 'Cuanhama', 150 | 'Curoca', 151 | 'Cuvelai', 152 | 'Namacunde', 153 | 'Ombadja' 154 | ] 155 | }, 156 | { 157 | nome: 'Huambo', 158 | fundada: '21 de Setembro de 1912', 159 | capital: 'Huambo', 160 | area: '35.771 km²', 161 | prefixo_telefonico: '+244', 162 | site_governo_provincial: 'https://www.huambo.gov.ao', 163 | municipios: [ 164 | 'Bailundo', 165 | 'Cachiungo', 166 | 'Caála', 167 | 'Ecunha', 168 | 'Huambo', 169 | 'Londuimbali', 170 | 'Longonjo', 171 | 'Mungo', 172 | 'Chicala-Choloanga', 173 | 'Chinjenje', 174 | 'Ucuma' 175 | ] 176 | }, 177 | { 178 | nome: 'Huíla', 179 | fundada: '2 de Setembro de 1901', 180 | capital: 'Lubango', 181 | area: '79.022 km²', 182 | prefixo_telefonico: '+244', 183 | site_governo_provincial: 'https://www.huila.gov.ao', 184 | municipios: [ 185 | 'Caconda', 186 | 'Cacula', 187 | 'Caluquembe', 188 | 'Chiange', 189 | 'Chibia', 190 | 'Chicomba', 191 | 'Chipindo', 192 | 'Cuvango', 193 | 'Humpata', 194 | 'Jamba', 195 | 'Lubango', 196 | 'Matala', 197 | 'Quilengues', 198 | 'Quipungo' 199 | ] 200 | }, 201 | { 202 | nome: 'Luanda', 203 | fundada: '1605', 204 | capital: 'Luanda', 205 | area: '18.826 km²', 206 | prefixo_telefonico: '222', 207 | site_governo_provincial: 'https://www.luanda.gov.ao', 208 | municipios: [ 209 | 'Belas', 210 | 'Cacuaco', 211 | 'Cazenga', 212 | 'Ícolo e Bengo', 213 | 'Luanda', 214 | 'Quilamba Quiaxi', 215 | 'Quissama', 216 | 'Talatona', 217 | 'Viana' 218 | ] 219 | }, 220 | { 221 | nome: 'Lunda Norte', 222 | fundada: '4 de Julho de 1978', 223 | capital: 'Dundo', 224 | area: '103.760 km²', 225 | prefixo_telefonico: '+244', 226 | site_governo_provincial: 'https://www.lundanorte.gov.ao', 227 | municipios: [ 228 | 'Cambulo', 229 | 'Capenda-Camulemba', 230 | 'Caungula', 231 | 'Chitato', 232 | 'Cuango', 233 | 'Cuílo', 234 | 'Lóvua', 235 | 'Lubalo', 236 | 'Lucapa', 237 | 'Xá-Muteba' 238 | ] 239 | }, 240 | { 241 | nome: 'Lunda Sul', 242 | fundada: '13 de Julho de 1895', 243 | capital: 'Saurimo', 244 | area: '77.636 km²', 245 | prefixo_telefonico: '+244', 246 | site_governo_provincial: 'https://www.lundasul.gov.ao', 247 | municipios: [ 248 | 'Cacolo', 249 | 'Dala', 250 | 'Muconda', 251 | 'Saurimo' 252 | ] 253 | }, 254 | { 255 | nome: 'Malanje', 256 | fundada: '1921', 257 | capital: 'Malanje', 258 | area: '98.302 km²', 259 | prefixo_telefonico: '+244', 260 | site_governo_provincial: 'https://www.malanje.gov.ao', 261 | municipios: [ 262 | 'Cacuso', 263 | 'Calandula', 264 | 'Cambundi-Catembo', 265 | 'Cangandala', 266 | 'Caombo', 267 | 'Cuaba Nzoji', 268 | 'Cunda-Dia-Baze', 269 | 'Luquembo', 270 | 'Malanje', 271 | 'Marimba', 272 | 'Massango', 273 | 'Mucari', 274 | 'Quela', 275 | 'Quirima' 276 | ] 277 | }, 278 | { 279 | nome: 'Moxico', 280 | fundada: '15 de Setembro de 1917', 281 | capital: 'Luena', 282 | area: '223.023 km²', 283 | prefixo_telefonico: '+244', 284 | site_governo_provincial: 'https://www.moxico.gov.ao', 285 | municipios: [ 286 | 'Alto Zambeze', 287 | 'Bundas', 288 | 'Camanongue', 289 | 'Léua', 290 | 'Luau', 291 | 'Luacano', 292 | 'Luchazes', 293 | 'Cameia', 294 | 'Moxico' 295 | ] 296 | }, 297 | { 298 | nome: 'Namibe', 299 | fundada: '19 de Abril de 1849', 300 | capital: 'Moçâmedes', 301 | area: '57.091 km²', 302 | prefixo_telefonico: '+244', 303 | site_governo_provincial: 'https://www.namibe.gov.ao', 304 | municipios: [ 305 | 'Bibala', 306 | 'Camucuio', 307 | 'Moçâmedes', 308 | 'Tômbua', 309 | 'Virei' 310 | ] 311 | }, 312 | { 313 | nome: 'Uíge', 314 | fundada: '31 de Maio de 1887', 315 | capital: 'Uíge', 316 | area: '58.698 km²', 317 | prefixo_telefonico: '+244', 318 | site_governo_provincial: 'https://www.uige.gov.ao', 319 | municipios: [ 320 | 'Alto Cauale', 321 | 'Ambuíla', 322 | 'Bembe', 323 | 'Buengas', 324 | 'Bungo', 325 | 'Damba', 326 | 'Milunga', 327 | 'Mucaba', 328 | 'Negage', 329 | 'Puri', 330 | 'Quimbele', 331 | 'Quitexe', 332 | 'Sanza Pombo', 333 | 'Songo', 334 | 'Uíge', 335 | 'Zombo' 336 | ] 337 | }, 338 | { 339 | nome: 'Zaire', 340 | fundada: '1 de Abril de 1961', 341 | capital: 'Mbanza Congo', 342 | area: '40.138 km²', 343 | prefixo_telefonico: '+232', 344 | site_governo_provincial: 'https://www.zaire.gov.ao', 345 | municipios: [ 346 | 'Cuimba', 347 | 'Mabanza Congo', 348 | 'Nóqui', 349 | 'Nezeto', 350 | 'Soio', 351 | 'Tomboco' 352 | ] 353 | }, 354 | ]) -------------------------------------------------------------------------------- /lib/services/weather_scraper.rb: -------------------------------------------------------------------------------- 1 | require 'nokogiri' 2 | require 'open-uri' 3 | 4 | class Services::WeatherScraper 5 | SITE = "http://inamet.gov.ao/ao/previsao/?p=" 6 | 7 | def self.get county_number 8 | county_number = county_number.to_s if county_number.class.eql? Integer 9 | prevision = Hash.new 10 | source = Nokogiri::HTML(URI(SITE + county_number).open()) 11 | 12 | source.search("div.previsoes div.row div.col-sm-5 fieldset").each do |weather_container| 13 | prevision["weather_image_url"] = weather_container.children.search("img").attr("src").value 14 | weather_container.children.search("p").each do |description| 15 | weather = description.text.split(":").collect(&:strip) 16 | prevision[weather[0]] = weather[1] 17 | end 18 | end 19 | 20 | prevision 21 | end 22 | end -------------------------------------------------------------------------------- /lib/tasks/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gentildpinto/provincias_de_angola_api/98b4786ab9320e5a7502a31244462be1cdc73f7d/lib/tasks/.keep -------------------------------------------------------------------------------- /log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gentildpinto/provincias_de_angola_api/98b4786ab9320e5a7502a31244462be1cdc73f7d/log/.keep -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | -------------------------------------------------------------------------------- /spec/rails_helper.rb: -------------------------------------------------------------------------------- 1 | # This file is copied to spec/ when you run 'rails generate rspec:install' 2 | require 'spec_helper' 3 | ENV['RAILS_ENV'] ||= 'test' 4 | require File.expand_path('../config/environment', __dir__) 5 | # Prevent database truncation if the environment is production 6 | abort("The Rails environment is running in production mode!") if Rails.env.production? 7 | require 'rspec/rails' 8 | # Add additional requires below this line. Rails is not loaded until this point! 9 | 10 | # Requires supporting ruby files with custom matchers and macros, etc, in 11 | # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are 12 | # run as spec files by default. This means that files in spec/support that end 13 | # in _spec.rb will both be required and run as specs, causing the specs to be 14 | # run twice. It is recommended that you do not name files matching this glob to 15 | # end with _spec.rb. You can configure this pattern with the --pattern 16 | # option on the command line or in ~/.rspec, .rspec or `.rspec-local`. 17 | # 18 | # The following line is provided for convenience purposes. It has the downside 19 | # of increasing the boot-up time by auto-requiring all files in the support 20 | # directory. Alternatively, in the individual `*_spec.rb` files, manually 21 | # require only the support files necessary. 22 | # 23 | # Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f } 24 | 25 | # Checks for pending migrations and applies them before tests are run. 26 | # If you are not using ActiveRecord, you can remove these lines. 27 | begin 28 | ActiveRecord::Migration.maintain_test_schema! 29 | rescue ActiveRecord::PendingMigrationError => e 30 | puts e.to_s.strip 31 | exit 1 32 | end 33 | RSpec.configure do |config| 34 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 35 | config.fixture_path = "#{::Rails.root}/spec/fixtures" 36 | 37 | # If you're not using ActiveRecord, or you'd prefer not to run each of your 38 | # examples within a transaction, remove the following line or assign false 39 | # instead of true. 40 | config.use_transactional_fixtures = true 41 | 42 | # You can uncomment this line to turn off ActiveRecord support entirely. 43 | # config.use_active_record = false 44 | 45 | # RSpec Rails can automatically mix in different behaviours to your tests 46 | # based on their file location, for example enabling you to call `get` and 47 | # `post` in specs under `spec/controllers`. 48 | # 49 | # You can disable this behaviour by removing the line below, and instead 50 | # explicitly tag your specs with their type, e.g.: 51 | # 52 | # RSpec.describe UsersController, type: :controller do 53 | # # ... 54 | # end 55 | # 56 | # The different available types are documented in the features, such as in 57 | # https://relishapp.com/rspec/rspec-rails/docs 58 | config.infer_spec_type_from_file_location! 59 | 60 | # Filter lines from Rails gems in backtraces. 61 | config.filter_rails_from_backtrace! 62 | # arbitrary gems may also be filtered via: 63 | # config.filter_gems_from_backtrace("gem name") 64 | end 65 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # This file was generated by the `rails generate rspec:install` command. Conventionally, all 2 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 3 | # The generated `.rspec` file contains `--require spec_helper` which will cause 4 | # this file to always be loaded, without a need to explicitly require it in any 5 | # files. 6 | # 7 | # Given that it is always loaded, you are encouraged to keep this file as 8 | # light-weight as possible. Requiring heavyweight dependencies from this file 9 | # will add to the boot time of your test suite on EVERY test run, even for an 10 | # individual file that may not need all of that loaded. Instead, consider making 11 | # a separate helper file that requires the additional dependencies and performs 12 | # the additional setup, and require it from the spec files that actually need 13 | # it. 14 | # 15 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 16 | RSpec.configure do |config| 17 | # rspec-expectations config goes here. You can use an alternate 18 | # assertion/expectation library such as wrong or the stdlib/minitest 19 | # assertions if you prefer. 20 | config.expect_with :rspec do |expectations| 21 | # This option will default to `true` in RSpec 4. It makes the `description` 22 | # and `failure_message` of custom matchers include text for helper methods 23 | # defined using `chain`, e.g.: 24 | # be_bigger_than(2).and_smaller_than(4).description 25 | # # => "be bigger than 2 and smaller than 4" 26 | # ...rather than: 27 | # # => "be bigger than 2" 28 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 29 | end 30 | 31 | # rspec-mocks config goes here. You can use an alternate test double 32 | # library (such as bogus or mocha) by changing the `mock_with` option here. 33 | config.mock_with :rspec do |mocks| 34 | # Prevents you from mocking or stubbing a method that does not exist on 35 | # a real object. This is generally recommended, and will default to 36 | # `true` in RSpec 4. 37 | mocks.verify_partial_doubles = true 38 | end 39 | 40 | # This option will default to `:apply_to_host_groups` in RSpec 4 (and will 41 | # have no way to turn it off -- the option exists only for backwards 42 | # compatibility in RSpec 3). It causes shared context metadata to be 43 | # inherited by the metadata hash of host groups and examples, rather than 44 | # triggering implicit auto-inclusion in groups with matching metadata. 45 | config.shared_context_metadata_behavior = :apply_to_host_groups 46 | 47 | # The settings below are suggested to provide a good initial experience 48 | # with RSpec, but feel free to customize to your heart's content. 49 | =begin 50 | # This allows you to limit a spec run to individual examples or groups 51 | # you care about by tagging them with `:focus` metadata. When nothing 52 | # is tagged with `:focus`, all examples get run. RSpec also provides 53 | # aliases for `it`, `describe`, and `context` that include `:focus` 54 | # metadata: `fit`, `fdescribe` and `fcontext`, respectively. 55 | config.filter_run_when_matching :focus 56 | 57 | # Allows RSpec to persist some state between runs in order to support 58 | # the `--only-failures` and `--next-failure` CLI options. We recommend 59 | # you configure your source control system to ignore this file. 60 | config.example_status_persistence_file_path = "spec/examples.txt" 61 | 62 | # Limits the available syntax to the non-monkey patched syntax that is 63 | # recommended. For more details, see: 64 | # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ 65 | # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ 66 | # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode 67 | config.disable_monkey_patching! 68 | 69 | # Many RSpec users commonly either run the entire suite or an individual 70 | # file, and it's useful to allow more verbose output when running an 71 | # individual spec file. 72 | if config.files_to_run.one? 73 | # Use the documentation formatter for detailed output, 74 | # unless a formatter has already been configured 75 | # (e.g. via a command-line flag). 76 | config.default_formatter = "doc" 77 | end 78 | 79 | # Print the 10 slowest examples and example groups at the 80 | # end of the spec run, to help surface which specs are running 81 | # particularly slow. 82 | config.profile_examples = 10 83 | 84 | # Run specs in random order to surface order dependencies. If you find an 85 | # order dependency and want to debug it, you can fix the order by providing 86 | # the seed, which is printed after each run. 87 | # --seed 1234 88 | config.order = :random 89 | 90 | # Seed global randomization in this process using the `--seed` CLI option. 91 | # Setting this allows you to use `--seed` to deterministically reproduce 92 | # test failures related to randomization by passing the same `--seed` value 93 | # as the one that triggered the failure. 94 | Kernel.srand config.seed 95 | =end 96 | end 97 | -------------------------------------------------------------------------------- /storage/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gentildpinto/provincias_de_angola_api/98b4786ab9320e5a7502a31244462be1cdc73f7d/storage/.keep -------------------------------------------------------------------------------- /tmp/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gentildpinto/provincias_de_angola_api/98b4786ab9320e5a7502a31244462be1cdc73f7d/tmp/.keep -------------------------------------------------------------------------------- /tmp/pids/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gentildpinto/provincias_de_angola_api/98b4786ab9320e5a7502a31244462be1cdc73f7d/tmp/pids/.keep -------------------------------------------------------------------------------- /vendor/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gentildpinto/provincias_de_angola_api/98b4786ab9320e5a7502a31244462be1cdc73f7d/vendor/.keep --------------------------------------------------------------------------------