├── .gitattributes ├── .gitignore ├── .ruby-version ├── Gemfile ├── Gemfile.lock ├── README.md ├── Rakefile ├── app ├── channels │ └── application_cable │ │ ├── channel.rb │ │ └── connection.rb ├── controllers │ ├── api │ │ └── v1 │ │ │ ├── auth_controller.rb │ │ │ ├── dota_controller.rb │ │ │ └── users_controller.rb │ ├── application_controller.rb │ ├── concerns │ │ └── .keep │ └── token_controller.rb ├── jobs │ └── application_job.rb ├── lib │ └── json_web_token.rb ├── mailers │ └── application_mailer.rb ├── models │ ├── application_record.rb │ ├── concerns │ │ └── .keep │ ├── dotum.rb │ └── user.rb └── views │ └── layouts │ ├── mailer.html.erb │ └── mailer.text.erb ├── bin ├── bundle ├── bundle.cmd ├── 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 │ ├── cors.rb │ ├── filter_parameter_logging.rb │ └── inflections.rb ├── locales │ └── en.yml ├── puma.rb ├── routes.rb └── storage.yml ├── db ├── migrate │ ├── 20221123035415_create_users.rb │ └── 20221130123126_create_dota.rb ├── schema.rb └── seeds.rb ├── lib └── tasks │ └── .keep ├── log └── .keep ├── public └── robots.txt ├── storage └── .keep ├── test ├── channels │ └── application_cable │ │ └── connection_test.rb ├── controllers │ ├── .keep │ ├── api │ │ └── v1 │ │ │ └── auth_controller_test.rb │ ├── authentication_controller_test.rb │ ├── dota_controller_test.rb │ ├── token_controller_test.rb │ └── users_controller_test.rb ├── fixtures │ ├── dota.yml │ ├── files │ │ └── .keep │ └── users.yml ├── integration │ └── .keep ├── mailers │ └── .keep ├── models │ ├── .keep │ ├── dotum_test.rb │ └── user_test.rb └── test_helper.rb ├── tmp ├── .keep ├── pids │ └── .keep └── storage │ └── .keep └── vendor └── .keep /.gitattributes: -------------------------------------------------------------------------------- 1 | # See https://git-scm.com/docs/gitattributes for more about git attribute files. 2 | 3 | # Mark the database schema as having been generated. 4 | db/schema.rb linguist-generated 5 | 6 | # Mark any vendored files as having been vendored. 7 | vendor/* linguist-vendored 8 | -------------------------------------------------------------------------------- /.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 the default SQLite database. 11 | /db/*.sqlite3 12 | /db/*.sqlite3-* 13 | 14 | # Ignore all logfiles and tempfiles. 15 | /log/* 16 | /tmp/* 17 | !/log/.keep 18 | !/tmp/.keep 19 | 20 | # Ignore pidfiles, but keep the directory. 21 | /tmp/pids/* 22 | !/tmp/pids/ 23 | !/tmp/pids/.keep 24 | 25 | # Ignore uploaded files in development. 26 | /storage/* 27 | !/storage/.keep 28 | /tmp/storage/* 29 | !/tmp/storage/ 30 | !/tmp/storage/.keep 31 | 32 | # Ignore master key for decrypting credentials and more. 33 | /config/master.key 34 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | ruby-3.1.2 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 | 4 | ruby "3.1.2" 5 | 6 | # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" 7 | gem "rails", "~> 7.0.4" 8 | 9 | 10 | 11 | # Use the Puma web server [https://github.com/puma/puma] 12 | gem "puma", "~> 5.0" 13 | 14 | # Build JSON APIs with ease [https://github.com/rails/jbuilder] 15 | # gem "jbuilder" 16 | 17 | # Use Redis adapter to run Action Cable in production 18 | # gem "redis", "~> 4.0" 19 | 20 | # Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] 21 | # gem "kredis" 22 | 23 | # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] 24 | gem "bcrypt", "~> 3.1.7" 25 | gem 'jwt' 26 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem 27 | gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] 28 | 29 | # Reduces boot times through caching; required in config/boot.rb 30 | gem "bootsnap", require: false 31 | 32 | # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] 33 | # gem "image_processing", "~> 1.2" 34 | 35 | # Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible 36 | # gem "rack-cors" 37 | 38 | group :development, :test do 39 | # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem 40 | gem "debug", platforms: %i[ mri mingw x64_mingw ] 41 | end 42 | 43 | group :development do 44 | # Speed up commands on slow machines / big apps [https://github.com/rails/spring] 45 | # gem "spring" 46 | # Use sqlite3 as the database for Active Record 47 | gem "sqlite3", "~> 1.4" 48 | end 49 | 50 | group :production do 51 | gem "pg", "~> 1.4" 52 | 53 | end 54 | gem "faker", "~> 3.0" 55 | 56 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actioncable (7.0.4) 5 | actionpack (= 7.0.4) 6 | activesupport (= 7.0.4) 7 | nio4r (~> 2.0) 8 | websocket-driver (>= 0.6.1) 9 | actionmailbox (7.0.4) 10 | actionpack (= 7.0.4) 11 | activejob (= 7.0.4) 12 | activerecord (= 7.0.4) 13 | activestorage (= 7.0.4) 14 | activesupport (= 7.0.4) 15 | mail (>= 2.7.1) 16 | net-imap 17 | net-pop 18 | net-smtp 19 | actionmailer (7.0.4) 20 | actionpack (= 7.0.4) 21 | actionview (= 7.0.4) 22 | activejob (= 7.0.4) 23 | activesupport (= 7.0.4) 24 | mail (~> 2.5, >= 2.5.4) 25 | net-imap 26 | net-pop 27 | net-smtp 28 | rails-dom-testing (~> 2.0) 29 | actionpack (7.0.4) 30 | actionview (= 7.0.4) 31 | activesupport (= 7.0.4) 32 | rack (~> 2.0, >= 2.2.0) 33 | rack-test (>= 0.6.3) 34 | rails-dom-testing (~> 2.0) 35 | rails-html-sanitizer (~> 1.0, >= 1.2.0) 36 | actiontext (7.0.4) 37 | actionpack (= 7.0.4) 38 | activerecord (= 7.0.4) 39 | activestorage (= 7.0.4) 40 | activesupport (= 7.0.4) 41 | globalid (>= 0.6.0) 42 | nokogiri (>= 1.8.5) 43 | actionview (7.0.4) 44 | activesupport (= 7.0.4) 45 | builder (~> 3.1) 46 | erubi (~> 1.4) 47 | rails-dom-testing (~> 2.0) 48 | rails-html-sanitizer (~> 1.1, >= 1.2.0) 49 | activejob (7.0.4) 50 | activesupport (= 7.0.4) 51 | globalid (>= 0.3.6) 52 | activemodel (7.0.4) 53 | activesupport (= 7.0.4) 54 | activerecord (7.0.4) 55 | activemodel (= 7.0.4) 56 | activesupport (= 7.0.4) 57 | activestorage (7.0.4) 58 | actionpack (= 7.0.4) 59 | activejob (= 7.0.4) 60 | activerecord (= 7.0.4) 61 | activesupport (= 7.0.4) 62 | marcel (~> 1.0) 63 | mini_mime (>= 1.1.0) 64 | activesupport (7.0.4) 65 | concurrent-ruby (~> 1.0, >= 1.0.2) 66 | i18n (>= 1.6, < 2) 67 | minitest (>= 5.1) 68 | tzinfo (~> 2.0) 69 | bcrypt (3.1.18) 70 | bootsnap (1.14.0) 71 | msgpack (~> 1.2) 72 | builder (3.2.4) 73 | concurrent-ruby (1.1.10) 74 | crass (1.0.6) 75 | debug (1.6.3) 76 | irb (>= 1.3.6) 77 | reline (>= 0.3.1) 78 | erubi (1.11.0) 79 | faker (3.0.0) 80 | i18n (>= 1.8.11, < 2) 81 | globalid (1.0.0) 82 | activesupport (>= 5.0) 83 | i18n (1.12.0) 84 | concurrent-ruby (~> 1.0) 85 | io-console (0.5.11) 86 | irb (1.5.0) 87 | reline (>= 0.3.0) 88 | jwt (2.5.0) 89 | loofah (2.19.0) 90 | crass (~> 1.0.2) 91 | nokogiri (>= 1.5.9) 92 | mail (2.7.1) 93 | mini_mime (>= 0.1.1) 94 | marcel (1.0.2) 95 | method_source (1.0.0) 96 | mini_mime (1.1.2) 97 | minitest (5.16.3) 98 | msgpack (1.6.0) 99 | net-imap (0.3.1) 100 | net-protocol 101 | net-pop (0.1.2) 102 | net-protocol 103 | net-protocol (0.1.3) 104 | timeout 105 | net-smtp (0.3.3) 106 | net-protocol 107 | nio4r (2.5.8) 108 | nokogiri (1.13.9-x64-mingw-ucrt) 109 | racc (~> 1.4) 110 | pg (1.4.5-x64-mingw-ucrt) 111 | puma (5.6.5) 112 | nio4r (~> 2.0) 113 | racc (1.6.0) 114 | rack (2.2.4) 115 | rack-test (2.0.2) 116 | rack (>= 1.3) 117 | rails (7.0.4) 118 | actioncable (= 7.0.4) 119 | actionmailbox (= 7.0.4) 120 | actionmailer (= 7.0.4) 121 | actionpack (= 7.0.4) 122 | actiontext (= 7.0.4) 123 | actionview (= 7.0.4) 124 | activejob (= 7.0.4) 125 | activemodel (= 7.0.4) 126 | activerecord (= 7.0.4) 127 | activestorage (= 7.0.4) 128 | activesupport (= 7.0.4) 129 | bundler (>= 1.15.0) 130 | railties (= 7.0.4) 131 | rails-dom-testing (2.0.3) 132 | activesupport (>= 4.2.0) 133 | nokogiri (>= 1.6) 134 | rails-html-sanitizer (1.4.3) 135 | loofah (~> 2.3) 136 | railties (7.0.4) 137 | actionpack (= 7.0.4) 138 | activesupport (= 7.0.4) 139 | method_source 140 | rake (>= 12.2) 141 | thor (~> 1.0) 142 | zeitwerk (~> 2.5) 143 | rake (13.0.6) 144 | reline (0.3.1) 145 | io-console (~> 0.5) 146 | sqlite3 (1.5.4-x64-mingw-ucrt) 147 | thor (1.2.1) 148 | timeout (0.3.0) 149 | tzinfo (2.0.5) 150 | concurrent-ruby (~> 1.0) 151 | tzinfo-data (1.2022.6) 152 | tzinfo (>= 1.0.0) 153 | websocket-driver (0.7.5) 154 | websocket-extensions (>= 0.1.0) 155 | websocket-extensions (0.1.5) 156 | zeitwerk (2.6.6) 157 | 158 | PLATFORMS 159 | x64-mingw-ucrt 160 | 161 | DEPENDENCIES 162 | bcrypt (~> 3.1.7) 163 | bootsnap 164 | debug 165 | faker (~> 3.0) 166 | jwt 167 | pg (~> 1.4) 168 | puma (~> 5.0) 169 | rails (~> 7.0.4) 170 | sqlite3 (~> 1.4) 171 | tzinfo-data 172 | 173 | RUBY VERSION 174 | ruby 3.1.2p20 175 | 176 | BUNDLED WITH 177 | 2.3.22 178 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Welcome to My Api 2 | My Api Demo: https://api-dota.onrender.com/
3 | my Github: https://github.com/Soburjon19/API.git
4 | Documentation: https://documenter.getpostman.com/view/22473861/2s8YsnYGzB 5 | 6 | ## Task 7 | I had a lot of problems, but I didn't give up 8 | I like the Rails framework 9 | 10 | ## Description 11 | google helped me a lot 12 | 13 | ## Installation 14 | 1. bundle install 15 | 2. rails db:migrate 16 | 3. rails db:seed 17 | 4. rails server 18 | -------------------------------------------------------------------------------- /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/channels/application_cable/channel.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Channel < ActionCable::Channel::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /app/channels/application_cable/connection.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Connection < ActionCable::Connection::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /app/controllers/api/v1/auth_controller.rb: -------------------------------------------------------------------------------- 1 | class Api::V1::AuthController < TokenController 2 | def login 3 | @user = User.find_by(email: user_params[:email]) 4 | if @user && @user.authenticate(user_params[:password]) 5 | token = encode_token({user_id: @user.id}) 6 | render json: {user: @user, token: token}, status: :accepted 7 | else 8 | render json: {error: 'Username invalid cota'}, 9 | status: :unauthorized 10 | end 11 | end 12 | 13 | private 14 | 15 | def user_params 16 | params.permit(:email, :password) 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /app/controllers/api/v1/dota_controller.rb: -------------------------------------------------------------------------------- 1 | class Api::V1::DotaController < TokenController 2 | before_action :set_dotum, only: %i[ show update destroy ] 3 | before_action :auth, only: %i[ create update destroy ] 4 | # GET /dota 5 | def index 6 | @dota = Dotum.all 7 | 8 | render json: @dota 9 | end 10 | 11 | # GET /dota/1 12 | def show 13 | render json: @dotum 14 | end 15 | 16 | # POST /dota 17 | def create 18 | @dotum = Dotum.new(dotum_params) 19 | 20 | if @dotum.save 21 | render json: @dotum, status: :created 22 | else 23 | render json: @dotum.errors, status: :unprocessable_entity 24 | end 25 | end 26 | 27 | # PATCH/PUT /dota/1 28 | def update 29 | if @dotum.update(dotum_params) 30 | render json: @dotum 31 | else 32 | render json: @dotum.errors, status: :unprocessable_entity 33 | end 34 | end 35 | 36 | # DELETE /dota/1 37 | def destroy 38 | @dotum.destroy 39 | end 40 | 41 | private 42 | # Use callbacks to share common setup or constraints between actions. 43 | def set_dotum 44 | @dotum = Dotum.find(params[:id]) 45 | end 46 | 47 | # Only allow a list of trusted parameters through. 48 | def dotum_params 49 | params.require(:dotum).permit(:hero, :item, :team, :player) 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /app/controllers/api/v1/users_controller.rb: -------------------------------------------------------------------------------- 1 | class Api::V1::UsersController < TokenController 2 | def create 3 | puts "CREATING USER..." 4 | @user = User.create(user_params) 5 | if @user.valid? 6 | @token = encode_token(user_id: @user.id) 7 | render json: {user: @user, token: @token}, status: :created 8 | else 9 | render json: {error: 'Email exists'}, 10 | status: :unprocessable_entity 11 | end 12 | end 13 | 14 | def login 15 | @user = User.find_by(email: user_params[:email]) 16 | if @user && @user.authenticate(user_params[:password]) 17 | token = encode_token({user_id: @user.id}) 18 | render json: {user: @user, token: token}, status: :ok 19 | else 20 | render json: {error: 'Username invalid cota'}, 21 | status: :unprocessable_entity 22 | end 23 | end 24 | 25 | private 26 | 27 | def user_params 28 | params.permit( 29 | :first_name, :last_name, :email, :password, :password_confirmation 30 | ) 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::API 2 | 3 | end 4 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soburjon19/API/0461ac87659c1fe5445f5fdad1178a732f9c8922/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /app/controllers/token_controller.rb: -------------------------------------------------------------------------------- 1 | class TokenController < ApplicationController 2 | 3 | def encode_token(payload) 4 | JWT.encode(payload,'secret') 5 | end 6 | 7 | def decode_token 8 | auth_header = request.headers['Authorization'] 9 | if auth_header 10 | token = auth_header.split(' ').last 11 | begin 12 | JWT.decode(token, 'secret', true, algorithm: 'HS256') 13 | rescue JWT::DecodeError 14 | nil 15 | end 16 | end 17 | end 18 | 19 | def auth_user 20 | decoded_token = decode_token() 21 | if decoded_token 22 | user_id = decoded_token[0]['user_id'] 23 | @user = User.find_by(id: user_id) 24 | end 25 | end 26 | 27 | def auth 28 | render json: {message: 'Before Sign Up Or Sign In' }, status: :unauthorized unless auth_user 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | class ApplicationJob < ActiveJob::Base 2 | # Automatically retry jobs that encountered a deadlock 3 | # retry_on ActiveRecord::Deadlocked 4 | 5 | # Most jobs are safe to ignore if the underlying records are no longer available 6 | # discard_on ActiveJob::DeserializationError 7 | end 8 | -------------------------------------------------------------------------------- /app/lib/json_web_token.rb: -------------------------------------------------------------------------------- 1 | class JsonWebToken 2 | SECRET_KEY = Rails.application.secrets.secret_key_base. to_s 3 | 4 | def self.encode(payload, exp = 24.hours.from_now) 5 | payload[:exp] = exp.to_i 6 | JWT.encode(payload, SECRET_KEY) 7 | end 8 | 9 | def self.decode(token) 10 | decoded = JWT.decode(token, SECRET_KEY)[0] 11 | HashWithIndifferentAccess.new decoded 12 | end 13 | end -------------------------------------------------------------------------------- /app/mailers/application_mailer.rb: -------------------------------------------------------------------------------- 1 | class ApplicationMailer < ActionMailer::Base 2 | default from: "from@example.com" 3 | layout "mailer" 4 | end 5 | -------------------------------------------------------------------------------- /app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | primary_abstract_class 3 | end 4 | -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soburjon19/API/0461ac87659c1fe5445f5fdad1178a732f9c8922/app/models/concerns/.keep -------------------------------------------------------------------------------- /app/models/dotum.rb: -------------------------------------------------------------------------------- 1 | class Dotum < ApplicationRecord 2 | end 3 | -------------------------------------------------------------------------------- /app/models/user.rb: -------------------------------------------------------------------------------- 1 | class User < ApplicationRecord 2 | has_secure_password 3 | # mount_uploader :avatar, AvatarUploader 4 | validates :email, presence: true, uniqueness: true 5 | validates :email, format: { with: URI::MailTo::EMAIL_REGEXP } 6 | validates :password, 7 | length: { minimum: 6 }, 8 | if: -> { new_record? || !password.nil? } 9 | end 10 | -------------------------------------------------------------------------------- /app/views/layouts/mailer.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/views/layouts/mailer.text.erb: -------------------------------------------------------------------------------- 1 | <%= yield %> 2 | -------------------------------------------------------------------------------- /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", __dir__) 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_requirement 64 | @bundler_requirement ||= 65 | env_var_version || cli_arg_version || 66 | bundler_requirement_for(lockfile_version) 67 | end 68 | 69 | def bundler_requirement_for(version) 70 | return "#{Gem::Requirement.default}.a" unless version 71 | 72 | bundler_gem_version = Gem::Version.new(version) 73 | 74 | requirement = bundler_gem_version.approximate_recommendation 75 | 76 | return requirement unless Gem.rubygems_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/bundle.cmd: -------------------------------------------------------------------------------- 1 | @ruby -x "%~f0" %* 2 | @exit /b %ERRORLEVEL% 3 | 4 | #!/usr/bin/env ruby 5 | # frozen_string_literal: true 6 | 7 | # 8 | # This file was generated by Bundler. 9 | # 10 | # The application 'bundle' is installed as part of a gem, and 11 | # this file is here to facilitate running it. 12 | # 13 | 14 | require "rubygems" 15 | 16 | m = Module.new do 17 | module_function 18 | 19 | def invoked_as_script? 20 | File.expand_path($0) == File.expand_path(__FILE__) 21 | end 22 | 23 | def env_var_version 24 | ENV["BUNDLER_VERSION"] 25 | end 26 | 27 | def cli_arg_version 28 | return unless invoked_as_script? # don't want to hijack other binstubs 29 | return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` 30 | bundler_version = nil 31 | update_index = nil 32 | ARGV.each_with_index do |a, i| 33 | if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN 34 | bundler_version = a 35 | end 36 | next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ 37 | bundler_version = $1 38 | update_index = i 39 | end 40 | bundler_version 41 | end 42 | 43 | def gemfile 44 | gemfile = ENV["BUNDLE_GEMFILE"] 45 | return gemfile if gemfile && !gemfile.empty? 46 | 47 | File.expand_path("../Gemfile", __dir__) 48 | end 49 | 50 | def lockfile 51 | lockfile = 52 | case File.basename(gemfile) 53 | when "gems.rb" then gemfile.sub(/\.rb$/, gemfile) 54 | else "#{gemfile}.lock" 55 | end 56 | File.expand_path(lockfile) 57 | end 58 | 59 | def lockfile_version 60 | return unless File.file?(lockfile) 61 | lockfile_contents = File.read(lockfile) 62 | return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ 63 | Regexp.last_match(1) 64 | end 65 | 66 | def bundler_requirement 67 | @bundler_requirement ||= 68 | env_var_version || cli_arg_version || 69 | bundler_requirement_for(lockfile_version) 70 | end 71 | 72 | def bundler_requirement_for(version) 73 | return "#{Gem::Requirement.default}.a" unless version 74 | 75 | bundler_gem_version = Gem::Version.new(version) 76 | 77 | requirement = bundler_gem_version.approximate_recommendation 78 | 79 | return requirement unless Gem.rubygems_version < Gem::Version.new("2.7.0") 80 | 81 | requirement += ".a" if bundler_gem_version.prerelease? 82 | 83 | requirement 84 | end 85 | 86 | def load_bundler! 87 | ENV["BUNDLE_GEMFILE"] ||= gemfile 88 | 89 | activate_bundler 90 | end 91 | 92 | def activate_bundler 93 | gem_error = activation_error_handling do 94 | gem "bundler", bundler_requirement 95 | end 96 | return if gem_error.nil? 97 | require_error = activation_error_handling do 98 | require "bundler/version" 99 | end 100 | return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) 101 | 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}'`" 102 | exit 42 103 | end 104 | 105 | def activation_error_handling 106 | yield 107 | nil 108 | rescue StandardError, LoadError => e 109 | e 110 | end 111 | end 112 | 113 | m.load_bundler! 114 | 115 | if m.invoked_as_script? 116 | load Gem.bin_path("bundler", "bundle") 117 | end 118 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby.exe 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.exe 2 | require_relative "../config/boot" 3 | require "rake" 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby.exe 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/all" 4 | 5 | # Require the gems listed in Gemfile, including any gems 6 | # you've limited to :test, :development, or :production. 7 | Bundler.require(*Rails.groups) 8 | 9 | module RailsJwt 10 | class Application < Rails::Application 11 | # Initialize configuration defaults for originally generated Rails version. 12 | config.load_defaults 7.0 13 | 14 | # Configuration for the application, engines, and railties goes here. 15 | # 16 | # These settings can be overridden in specific environments using the files 17 | # in config/environments, which are processed later. 18 | # 19 | # config.time_zone = "Central Time (US & Canada)" 20 | # config.eager_load_paths << Rails.root.join("extras") 21 | 22 | # Only loads a smaller set of middleware suitable for API only apps. 23 | # Middleware like session, flash, cookies can be added back manually. 24 | # Skip views, helpers and assets when generating a new resource. 25 | config.api_only = true 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /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: rails_jwt_production 11 | -------------------------------------------------------------------------------- /config/credentials.yml.enc: -------------------------------------------------------------------------------- 1 | 8KXCsCuDeOlTY1fo+3ankSlt6G3bXrPsXVgpLz1n1i9KyoQ1VL+g9jlqxguiigdMIOPxWunjqdTNxruyPcFk+Yf22aBzYmdIR3dNa8CohsVKL8Ge+BWZXhzpWKHg8sc0cvl6iTXO6xJTAHthEqfMf3OOm+xt15FTGt8irqouVea8yf+iKALf2VHFun0e/8pGFY0aGpCQCKu8DEnzIhCXT3mEHj0bJD1DPWykVu+jIsQOf4DxmVrs3W0EAqygo145Gaqf+PppAb/nVZM5zWiB9lWKz+ZQWBGEtYYgh4QWQz50WB6LlVCTMOQjuyK3nHUs1frVfUeszTrDgciYVmAaPdOxDC3K1FOYcyrVCS2BL6Me1Z9n8xFS0RgjBbrNQH3B17Eiox+TF6vxFvjpzjvKBehrJmKBsT0PRvHT--k4GFXiupSSfb+L1g--NLXjcD1qtSVkWFdDDWdqsw== -------------------------------------------------------------------------------- /config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite. Versions 3.8.0 and up are supported. 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem "sqlite3" 6 | # 7 | default: &default 8 | adapter: sqlite3 9 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 10 | timeout: 5000 11 | 12 | development: 13 | <<: *default 14 | database: db/development.sqlite3 15 | 16 | # Warning: The database defined as "test" will be erased and 17 | # re-generated from your development database when you run "rake". 18 | # Do not set this db to the same as development or production. 19 | test: 20 | <<: *default 21 | database: db/test.sqlite3 22 | 23 | production: 24 | <<: *default 25 | database: db/production.sqlite3 26 | -------------------------------------------------------------------------------- /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 server timing 18 | config.server_timing = true 19 | 20 | # Enable/disable caching. By default caching is disabled. 21 | # Run rails dev:cache to toggle caching. 22 | if Rails.root.join("tmp/caching-dev.txt").exist? 23 | config.cache_store = :memory_store 24 | config.public_file_server.headers = { 25 | "Cache-Control" => "public, max-age=#{2.days.to_i}" 26 | } 27 | else 28 | config.action_controller.perform_caching = false 29 | 30 | config.cache_store = :null_store 31 | end 32 | 33 | # Store uploaded files on the local file system (see config/storage.yml for options). 34 | config.active_storage.service = :local 35 | 36 | # Don't care if the mailer can't send. 37 | config.action_mailer.raise_delivery_errors = false 38 | 39 | config.action_mailer.perform_caching = false 40 | 41 | # Print deprecation notices to the Rails logger. 42 | config.active_support.deprecation = :log 43 | 44 | # Raise exceptions for disallowed deprecations. 45 | config.active_support.disallowed_deprecation = :raise 46 | 47 | # Tell Active Support which deprecation messages to disallow. 48 | config.active_support.disallowed_deprecation_warnings = [] 49 | 50 | # Raise an error on page load if there are pending migrations. 51 | config.active_record.migration_error = :page_load 52 | 53 | # Highlight code that triggered database queries in logs. 54 | config.active_record.verbose_query_logs = true 55 | 56 | 57 | # Raises error for missing translations. 58 | # config.i18n.raise_on_missing_translations = true 59 | 60 | # Annotate rendered view with file names. 61 | # config.action_view.annotate_rendered_view_with_filenames = true 62 | 63 | # Uncomment if you wish to allow Action Cable access from any origin. 64 | # config.action_cable.disable_request_forgery_protection = true 65 | end 66 | -------------------------------------------------------------------------------- /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 | # Store uploaded files on the local file system (see config/storage.yml for options). 34 | config.active_storage.service = :local 35 | 36 | # Mount Action Cable outside main process or domain. 37 | # config.action_cable.mount_path = nil 38 | # config.action_cable.url = "wss://example.com/cable" 39 | # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ] 40 | 41 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 42 | # config.force_ssl = true 43 | 44 | # Include generic and useful information about system operation, but avoid logging too much 45 | # information to avoid inadvertent exposure of personally identifiable information (PII). 46 | config.log_level = :info 47 | 48 | # Prepend all log lines with the following tags. 49 | config.log_tags = [ :request_id ] 50 | 51 | # Use a different cache store in production. 52 | # config.cache_store = :mem_cache_store 53 | 54 | # Use a real queuing backend for Active Job (and separate queues per environment). 55 | # config.active_job.queue_adapter = :resque 56 | # config.active_job.queue_name_prefix = "rails_jwt_production" 57 | 58 | config.action_mailer.perform_caching = false 59 | 60 | # Ignore bad email addresses and do not raise email delivery errors. 61 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 62 | # config.action_mailer.raise_delivery_errors = false 63 | 64 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 65 | # the I18n.default_locale when a translation cannot be found). 66 | config.i18n.fallbacks = true 67 | 68 | # Don't log any deprecations. 69 | config.active_support.report_deprecations = false 70 | 71 | # Use default logging formatter so that PID and timestamp are not suppressed. 72 | config.log_formatter = ::Logger::Formatter.new 73 | 74 | # Use a different logger for distributed setups. 75 | # require "syslog/logger" 76 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") 77 | 78 | if ENV["RAILS_LOG_TO_STDOUT"].present? 79 | logger = ActiveSupport::Logger.new(STDOUT) 80 | logger.formatter = config.log_formatter 81 | config.logger = ActiveSupport::TaggedLogging.new(logger) 82 | end 83 | 84 | # Do not dump schema after migrations. 85 | config.active_record.dump_schema_after_migration = false 86 | end 87 | -------------------------------------------------------------------------------- /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 | # Turn false under Spring and add config.action_view.cache_template_loading = true. 12 | config.cache_classes = true 13 | 14 | # Eager loading loads your whole application. When running a single test locally, 15 | # this probably isn't necessary. It's a good idea to do in a continuous integration 16 | # system, or in some way before deploying your code. 17 | config.eager_load = ENV["CI"].present? 18 | 19 | # Configure public file server for tests with Cache-Control for performance. 20 | config.public_file_server.enabled = true 21 | config.public_file_server.headers = { 22 | "Cache-Control" => "public, max-age=#{1.hour.to_i}" 23 | } 24 | 25 | # Show full error reports and disable caching. 26 | config.consider_all_requests_local = true 27 | config.action_controller.perform_caching = false 28 | config.cache_store = :null_store 29 | 30 | # Raise exceptions instead of rendering exception templates. 31 | config.action_dispatch.show_exceptions = false 32 | 33 | # Disable request forgery protection in test environment. 34 | config.action_controller.allow_forgery_protection = false 35 | 36 | # Store uploaded files on the local file system in a temporary directory. 37 | config.active_storage.service = :test 38 | 39 | config.action_mailer.perform_caching = false 40 | 41 | # Tell Action Mailer not to deliver emails to the real world. 42 | # The :test delivery method accumulates sent emails in the 43 | # ActionMailer::Base.deliveries array. 44 | config.action_mailer.delivery_method = :test 45 | 46 | # Print deprecation notices to the stderr. 47 | config.active_support.deprecation = :stderr 48 | 49 | # Raise exceptions for disallowed deprecations. 50 | config.active_support.disallowed_deprecation = :raise 51 | 52 | # Tell Active Support which deprecation messages to disallow. 53 | config.active_support.disallowed_deprecation_warnings = [] 54 | 55 | # Raises error for missing translations. 56 | # config.i18n.raise_on_missing_translations = true 57 | 58 | # Annotate rendered view with file names. 59 | # config.action_view.annotate_rendered_view_with_filenames = true 60 | end 61 | -------------------------------------------------------------------------------- /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 "example.com" 11 | # 12 | # resource "*", 13 | # headers: :any, 14 | # methods: [:get, :post, :put, :patch, :delete, :options, :head] 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 parameters to be filtered from the log file. Use this to limit dissemination of 4 | # sensitive information. See the ActiveSupport::ParameterFilter documentation for supported 5 | # notations and behaviors. 6 | Rails.application.config.filter_parameters += [ 7 | :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn 8 | ] 9 | -------------------------------------------------------------------------------- /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/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 `bin/rails restart` command. 43 | plugin :tmp_restart 44 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | namespace :api do 3 | namespace :v1 do 4 | resources :dota 5 | post "/sign_in", to: "auth#login" 6 | post "/sign_up", to: "users#create" 7 | 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /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 bin/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-<%= Rails.env %> 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-<%= Rails.env %> 23 | 24 | # Use bin/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-<%= Rails.env %> 30 | 31 | # mirror: 32 | # service: Mirror 33 | # primary: local 34 | # mirrors: [ amazon, google, microsoft ] 35 | -------------------------------------------------------------------------------- /db/migrate/20221123035415_create_users.rb: -------------------------------------------------------------------------------- 1 | class CreateUsers < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :users do |t| 4 | t.string :first_name 5 | t.string :last_name 6 | t.string :email 7 | t.string :password_digest 8 | 9 | t.timestamps 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /db/migrate/20221130123126_create_dota.rb: -------------------------------------------------------------------------------- 1 | class CreateDota < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :dota do |t| 4 | t.string :hero 5 | t.string :item 6 | t.string :team 7 | t.string :player 8 | 9 | t.timestamps 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /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[7.0].define(version: 2022_11_30_123126) do 14 | create_table "birds", force: :cascade do |t| 15 | t.string "anatomy" 16 | t.string "color" 17 | t.string "adjective" 18 | t.datetime "created_at", null: false 19 | t.datetime "updated_at", null: false 20 | end 21 | 22 | create_table "dota", force: :cascade do |t| 23 | t.string "hero" 24 | t.string "item" 25 | t.string "team" 26 | t.string "player" 27 | t.datetime "created_at", null: false 28 | t.datetime "updated_at", null: false 29 | end 30 | 31 | create_table "users", force: :cascade do |t| 32 | t.string "first_name" 33 | t.string "last_name" 34 | t.string "email" 35 | t.string "password_digest" 36 | t.datetime "created_at", null: false 37 | t.datetime "updated_at", null: false 38 | end 39 | 40 | end 41 | -------------------------------------------------------------------------------- /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 bin/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 | require "faker" 9 | 10 | 20.times do 11 | @birds = Bird.new( 12 | anatomy: Faker::Creature::Bird.anatomy, 13 | color: Faker::Creature::Bird.color, 14 | adjective: Faker::Creature::Bird.adjective 15 | ) 16 | 17 | @birds.save 18 | end -------------------------------------------------------------------------------- /lib/tasks/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soburjon19/API/0461ac87659c1fe5445f5fdad1178a732f9c8922/lib/tasks/.keep -------------------------------------------------------------------------------- /log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soburjon19/API/0461ac87659c1fe5445f5fdad1178a732f9c8922/log/.keep -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | -------------------------------------------------------------------------------- /storage/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soburjon19/API/0461ac87659c1fe5445f5fdad1178a732f9c8922/storage/.keep -------------------------------------------------------------------------------- /test/channels/application_cable/connection_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase 4 | # test "connects with cookies" do 5 | # cookies.signed[:user_id] = 42 6 | # 7 | # connect 8 | # 9 | # assert_equal connection.user_id, "42" 10 | # end 11 | end 12 | -------------------------------------------------------------------------------- /test/controllers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soburjon19/API/0461ac87659c1fe5445f5fdad1178a732f9c8922/test/controllers/.keep -------------------------------------------------------------------------------- /test/controllers/api/v1/auth_controller_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class Api::V1::AuthControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/authentication_controller_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class AuthenticationControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/dota_controller_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class DotaControllerTest < ActionDispatch::IntegrationTest 4 | setup do 5 | @dotum = dota(:one) 6 | end 7 | 8 | test "should get index" do 9 | get dota_url, as: :json 10 | assert_response :success 11 | end 12 | 13 | test "should create dotum" do 14 | assert_difference("Dotum.count") do 15 | post dota_url, params: { dotum: { hero: @dotum.hero, item: @dotum.item, player: @dotum.player, team: @dotum.team } }, as: :json 16 | end 17 | 18 | assert_response :created 19 | end 20 | 21 | test "should show dotum" do 22 | get dotum_url(@dotum), as: :json 23 | assert_response :success 24 | end 25 | 26 | test "should update dotum" do 27 | patch dotum_url(@dotum), params: { dotum: { hero: @dotum.hero, item: @dotum.item, player: @dotum.player, team: @dotum.team } }, as: :json 28 | assert_response :success 29 | end 30 | 31 | test "should destroy dotum" do 32 | assert_difference("Dotum.count", -1) do 33 | delete dotum_url(@dotum), as: :json 34 | end 35 | 36 | assert_response :no_content 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /test/controllers/token_controller_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class TokenControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/users_controller_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class UsersControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/fixtures/dota.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | hero: MyString 5 | item: MyString 6 | team: MyString 7 | player: MyString 8 | 9 | two: 10 | hero: MyString 11 | item: MyString 12 | team: MyString 13 | player: MyString 14 | -------------------------------------------------------------------------------- /test/fixtures/files/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soburjon19/API/0461ac87659c1fe5445f5fdad1178a732f9c8922/test/fixtures/files/.keep -------------------------------------------------------------------------------- /test/fixtures/users.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | name: MyString 5 | username: MyString 6 | email: MyString 7 | password_digest: MyString 8 | 9 | two: 10 | name: MyString 11 | username: MyString 12 | email: MyString 13 | password_digest: MyString 14 | -------------------------------------------------------------------------------- /test/integration/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soburjon19/API/0461ac87659c1fe5445f5fdad1178a732f9c8922/test/integration/.keep -------------------------------------------------------------------------------- /test/mailers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soburjon19/API/0461ac87659c1fe5445f5fdad1178a732f9c8922/test/mailers/.keep -------------------------------------------------------------------------------- /test/models/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soburjon19/API/0461ac87659c1fe5445f5fdad1178a732f9c8922/test/models/.keep -------------------------------------------------------------------------------- /test/models/dotum_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class DotumTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/user_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class UserTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | ENV["RAILS_ENV"] ||= "test" 2 | require_relative "../config/environment" 3 | require "rails/test_help" 4 | 5 | class ActiveSupport::TestCase 6 | # Run tests in parallel with specified workers 7 | parallelize(workers: :number_of_processors, with: :threads) 8 | 9 | # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. 10 | fixtures :all 11 | 12 | # Add more helper methods to be used by all tests here... 13 | end 14 | -------------------------------------------------------------------------------- /tmp/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soburjon19/API/0461ac87659c1fe5445f5fdad1178a732f9c8922/tmp/.keep -------------------------------------------------------------------------------- /tmp/pids/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soburjon19/API/0461ac87659c1fe5445f5fdad1178a732f9c8922/tmp/pids/.keep -------------------------------------------------------------------------------- /tmp/storage/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soburjon19/API/0461ac87659c1fe5445f5fdad1178a732f9c8922/tmp/storage/.keep -------------------------------------------------------------------------------- /vendor/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soburjon19/API/0461ac87659c1fe5445f5fdad1178a732f9c8922/vendor/.keep --------------------------------------------------------------------------------