# frozen_string_literal: true class DataController < ApplicationController respond_to :json caches_page :countries, :feedback_reasons, :languages, :rates def countries @countries = TranslationCms::Country.all json_responce! end def country_code respond_to do |format| format.json { render json: { country_code: request_country_code.upcase } } format.all { render text: request_country_code } end end def feedback_reasons @reasons = FeedbackReason.sorted json_responce! end def languages @languages = TranslationCms::Api::Language.all! @language_rates = TranslationCms::Api::Rates::Language.all! json_responce! end def check_discount @discount = TranslationCms::Api::Discounts::Ticket.find(params[:code]).first json_responce! end def payment_rates @payment_types = PaymentType.visible @exchange_rates = TranslationCms::Api::Rates::Currency.all! end def rates @service_types = ServiceType.all @urgency_types = UrgencyType.all @feature_types = FeatureType.all @payment_types = PaymentType.visible @services = TranslationCms::Api::Service.all! @languages = TranslationCms::Api::Language.all! # @categories = TranslationCms::Api::Category.all! @industry_expertises = TranslationCms::Api::IndustryExpertise.all! @certificates = TranslationCms::Api::Certificate.all! @packages = TranslationCms::Api::OrderPackage.all! @service_rates = TranslationCms::Api::Rates::Service.all! @language_rates = TranslationCms::Api::Rates::Language.all! @feature_rates = TranslationCms::Api::Rates::Feature.all! @certificate_rates = TranslationCms::Api::Rates::Certificate.all! @exchange_rates = TranslationCms::Api::Rates::Currency.all! @countries = TranslationCms::Country.all @work_capacity_rates = TranslationCms::Api::Rates::WorkCapacity.all! @urgency_rates = TranslationCms::Api::Rates::Urgency.all! @urgency_rates.push(TranslationCms::Api::Rates::Urgency.new(id: 0, urgency_division: 999_999, price: 0)) @settings = TranslationCms::Api::Setting.all!.first json_responce! end def check_ip # render request geocoder result data = request.location.try(:data).try(:as_json) || {} data[:redirect] = Settings.blacklist_redirect_url if blacklisted? render json: data end protected def blacklisted_by_country?(country_code) return false if country_code.blank? return false if Settings.blacklist_country_codes.blank? return false if Settings.blacklist_country_codes.reject(&:blank?).blank? Settings.blacklist_country_codes.include?(country_code.downcase) end def blacklisted? return false if Settings.blacklist_redirect_url.blank? ip = request.location.try(:data).try(:fetch, 'ip') Rails.cache.fetch("blacklisted_cache@#{ip}", expire_in: 10.minutes) do blacklisted_by_country?(request.location.try(:country_code)) end end def json_responce! respond_to do |format| format.json { render } format.all { render_404 } end end end