# Bancos Brasileiros 🇧🇷 🏦 📋 Brazilian commercial banks list. This gem was created to meet a need in the [Brazilian Banks Project](https://guibranco.github.io/BancosBrasileiros/), developed by [Guilherme Branco](https://github.com/guibranco). The project keeps an up-to-date list of banks in various programming languages, and I realized the need to provide support for Rails as well. ## Installation Add gem in your Gemfile: ```ruby gem 'bancos_brasileiros' ``` and run **bundle install** ## Usage Example of how to use the `bancos_brasileiros` in a rails project: Create a controller: ```ruby # app/controllers/banks_controller.rb class BanksController < ApplicationController def index @banks = BancosBrasileiros.all_banks respond_to do |format| format.html format.json { render json: @banks } end end def show @bank = BancosBrasileiros.find_bank_by_compe(params[:id]) respond_to do |format| if @bank format.html format.json { render json: @bank } else format.html { render plain: 'Bank not found.', status: :not_found } format.json { render json: { error: 'Bank not found.' }, status: :not_found } end end end def by_ispb @bank = BancosBrasileiros.find_bank_by_ispb(params[:ispb]) respond_to do |format| if @bank format.html { render :show } format.json { render json: @bank } else format.html { render plain: 'Bank not found.', status: :not_found } format.json { render json: { error: 'Bank not found.' }, status: :not_found } end end end def by_network @banks = BancosBrasileiros.find_banks_by_network(params[:network]) respond_to do |format| format.html { render :index } format.json { render json: @banks } end end def by_type @banks = BancosBrasileiros.find_banks_by_type(params[:type]) respond_to do |format| format.html { render :index } format.json { render json: @banks } end end def by_pix_type @banks = BancosBrasileiros.find_banks_by_pix_type(params[:pix_type]) respond_to do |format| format.html { render :index } format.json { render json: @banks } end end end ``` Create routes: ```ruby # config/routes.rb Rails.application.routes.draw do resources :banks, only: [:index, :show] do collection do get 'by_ispb/:ispb', to: 'banks#by_ispb' get 'by_network/:network', to: 'banks#by_network' get 'by_type/:type', to: 'banks#by_type' get 'by_pix_type/:pix_type', to: 'banks#by_pix_type' end end end ``` Create a example of view: ```html
COMPE | Nome | Tipo | Network | Ações |
---|---|---|---|---|
<%= bank['COMPE'] %> | <%= bank['LongName'] %> | <%= bank['Type'] %> | <%= bank['Network'] %> | <%= link_to 'Ver detalhes', bank_path(bank['COMPE']) %> |
COMPE: <%= @bank['COMPE'] %>
ISPB: <%= @bank['ISPB'] %>
Nome: <%= @bank['LongName'] %>
Nome Curto: <%= @bank['ShortName'] %>
Tipo: <%= @bank['Type'] %>
Network: <%= @bank['Network'] %>
Pix Type: <%= @bank['PixType'] %>
Produtos: <%= @bank['Products'].join(', ') %>
URL: <%= link_to @bank['Url'], @bank['Url'] %>
Data de Início de Operação: <%= @bank['DateOperationStarted'] %>
Data de Início do Pix: <%= @bank['DatePixStarted'] %>
Data de Registro: <%= @bank['DateRegistered'] %>
Data de Atualização: <%= @bank['DateUpdated'] %>
<%= link_to 'Voltar', banks_path %> ``` ## Requirements - Ruby >= 2.6.0 (recommended 2.7+) - Rails >= 6.0 (compatible up to Rails 7) ## Contributing to Bancos Brasileiros Fork, fix, then send a pull request. Bug reports and pull requests are welcome on GitHub at **https://github.com/eltonsantos/bancos_brasileiros**. ## License This gem is available as open-source under the terms of The MIT License (MIT). Copyright (c) 2024 **Elton Santos**. See **MIT-LICENSE** for further details.