Skip to content

Instantly share code, notes, and snippets.

@john45
Last active December 19, 2018 10:32
Show Gist options
  • Save john45/91cddd0e2acda4d15f55a48a9e15f9c6 to your computer and use it in GitHub Desktop.
Save john45/91cddd0e2acda4d15f55a48a9e15f9c6 to your computer and use it in GitHub Desktop.
check clients emails and add to correct or incorrect. Last two parts from one system
require_relative 'log_to_db'
require_relative '../models/log_record'
require_relative '../models/report'
class ClientCheck
attr_accessor :users, :correct_users, :incorrect_users
def initialize(users)
@users = users
@report = Report.last
@correct_users, @incorrect_users = Array.new, Array.new
check_users
end
private
def check_users
return false if @users[:envelope][:body][:get_list_of_clients_response][:get_list_of_clients_result][:list_of_clients].nil?
if get_users.is_a?(Hash)
check_for_correct_user(get_users)
else
get_users.each do |user|
check_for_correct_user(user)
end
end
@correct_users = without_dup(@correct_users)
@incorrect_users = without_dup(@incorrect_users)
rescue => e
LogToDb.log!(:check_users, :critical, e)
raise e
else
LogToDb.log!(:check_users, :success)
end
def without_dup(users)
return users if users.is_a?(Hash)
users_without_duplicate = []
memo = []
users.each do |user|
unless memo.include?(user[:client_id])
memo << user[:client_id]
users_without_duplicate << user
end
end
end
def check_for_correct_user(user)
if (user[:email] =~ /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i).nil? || user[:email] == '[email protected]'
@incorrect_users << user
add_client_to_incorrect_sync(user)
else
@correct_users << user
end
end
def get_users
@users[:envelope][:body][:get_list_of_clients_response][:get_list_of_clients_result][:list_of_clients][:client_record]
end
def add_client_to_incorrect_sync(user)
ClientSyncLog.create(status: "not sent", description: "wrong email address format: " + user[:email], report: @report, client_id: user[:client_id].to_i)
@report.add_incorrect(1)
@report.add_list_incorrect_clients(user[:client_id].to_i)
end
end
==================================================================================================================
class ApplicationController < ActionController::Base
require 'net/http'
include Pundit
include SessionsHelper
include RedisHelper
include PredictionsHelper
include LoggerHelper
protect_from_forgery with: :exception
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
rescue_from Pundit::NotDefinedError, with: :user_not_authorized
rescue_from NoMethodError, with: :no_method_error
private
def current_user_admin
current_user
end
def user_not_authorized
redirect_to root_path
flash[:danger] = t('flash.denied')
end
def active_admin_not_authorized(_error = nil)
redirect_to root_path
flash[:danger] = t('flash.denied')
end
def no_method_error(exception = nil)
if exception
log = logger('not_found')
log.error "Exception"
log.error StandardError.new(request.url)
log.error StandardError.new(exception)
log.error exception.backtrace.join("\n")
redirect_to root_path
flash[:danger] = t('error.in_this_time') + " #{request.url} " + t('error.not_available')
end
end
end
============================================================================================================
class PredictionsController < ApplicationController
def predictions
skip_authorization
@leagues = League.where(is_active: true)
end
def league
league = params[:league]
@league = League.find_by(alias: "#{league}")
@leagues = League.where(is_active: true)
@id = @league.league_id
case @id
when 10
@show_group = true
when 12
@show_group = true
else
@show_group = false
end
end
def match
@league_params = params[:league]
@match_params = params[:match]
result = ShowMatch.call(league_params: @league_params, match_params: @match_params)
@league = result.league
@match = result.match
@odds = result.odds
@picks = result.picks
@show = result.show
end
def cup;end
def landing;end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment