Class: FlyAdmin::ConnectionApi

Inherits:
Object
  • Object
show all
Defined in:
lib/fly_admin/connection_api.rb

Class Method Summary collapse

Class Method Details

.check_user(user) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/fly_admin/connection_api.rb', line 4

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

.get_customer_params(params, request) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fly_admin/connection_api.rb', line 20

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'
    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
      API_LOG.error "response: #{response.inspect}"
      {status: 'error'}
    end
 end
end

.make_customer_request_params(request, params) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/fly_admin/connection_api.rb', line 43

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