module FlyAdmin class ConnectionApi def self.check_user(user) valid = true begin api_url = SiteConfig['wap_click_addr'] + "/api/check" api_url = 'http://0.0.0.0:3000/api/check' if Rails.env.eql? 'development' request = RestClient.get(api_url, :params => {:pass => user.customer_key}) hash = JSON.parse request hash = hash.with_indifferent_access VALIDATION_LOG.info "status for user #{user.id}: #{hash.inspect}" valid = false unless hash[:status].eql? true rescue Exception => e VALIDATION_LOG.error "error check status for user #{user.id}: #{e.message}" end valid end def self.get_customer_params(params, request) if ENV["RAILS_ENV"] == 'test' || ENV['TEST'].present? || Rails.env.eql?('test') { key: 'fun_key', alias: 'imbs_domain.com', action_type: 'wap', 'status' => 'ok', country: 'az'} else url = SiteConfig['wap_click_addr'] + '/api/handle_customer' # if Rails.env.eql? 'development' # url = 'http://0.0.0.0:3000' + '/api/handle_customer' # request.env['REMOTE_ADDR'] = '83.149.34.187' # end request_params = self.make_customer_request_params(request, params) if ENV['TEST'] request_params[:remote_addr] = '83.149.9.19' end API_LOG.info "HTTP_USER_AGENT: #{request.env['HTTP_USER_AGENT']}" API_LOG.info "URL TO IMBS: #{url}?#{request_params.to_query}" begin response = RestClient.get(url, :params => request_params) API_LOG.info "RESPONSE FROM IMBS: #{response.inspect}" out_hash = JSON.parse(response) out_hash.with_indifferent_access rescue Exception => e API_LOG.error "response: #{response.inspect}" {status: 'error'} end end # end end def self.make_customer_request_params(request, params) p = {} p[:customer_key] = params[:key] p[:sid] = params[:sid] if p[:customer_key].blank? p[:remote_addr] = request.env['REMOTE_ADDR'] p[:x_forwarded_for] = request.env['HTTP_X_FORWARDED_FOR'] end p[:service_code] = SiteConfig['wc_service_code'] p = p.delete_if { |k,v| v.blank? } concat = p[:customer_key].to_s + p[:sid].to_s + p[:remote_addr].to_s + p[:x_forwarded_for].to_s + p[:service_code].to_s + SiteConfig['wc_service_salt'].to_s p[:hash] = Digest::MD5.hexdigest(concat) p end end end