class Registrar::Middleware::ConvertOmniAuthHashToRegistrarHash::RegistrarHash

Constants

GEOIP
GEOIP_DATA
MOBILE_USER_AGENTS

Public Class Methods

build(env, time) click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 23
def self.build(env, time)
  new(env, time).build
end
new(env, time) click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 27
def initialize(env, time)
  @env = env
  @time = time
end

Public Instance Methods

build() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 32
def build
  Hash.new.tap do |schema|
    schema['provider'] = provider
    schema['profile'] = profile
    schema['trace'] = trace
  end
end

Private Instance Methods

action_dispatch_remote_ip() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 121
def action_dispatch_remote_ip
  if remote_ip = env['action_dispatch.remote_ip']
    remote_ip.to_s
  end
end
auth() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 167
def auth
  @auth ||= env['omniauth.auth']
end
country() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 163
def country
  GEOIP.country(ip).country_code2
end
env() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 171
def env
  @env
end
extra() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 97
def extra
  auth['extra'].to_hash
end
info() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 101
def info
  auth['info'].to_hash
end
ip() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 116
def ip
  action_dispatch_remote_ip || env['HTTP_CLIENT_IP'] ||
    env['HTTP_X_REMOTE_ADDR'] || env['REMOTE_ADDR']
end
locale() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 155
def locale
  env['X-Locale']
end
mobile_user_agent?() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 139
def mobile_user_agent?
  !!mobile_user_agents.match(user_agent)
end
mobile_user_agents() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 143
def mobile_user_agents
  Regexp.new(MOBILE_USER_AGENTS, true)
end
now() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 131
def now
  @time.now.to_i.to_s
end
opt_in() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 93
def opt_in
  extra['opt_in'] || false
end
platform() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 135
def platform
  mobile_user_agent? ? 'mobile' : 'desktop'
end
profile() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 62
def profile
  {
    'name' => profile_name,
    'email' => profile_email,
    'location' => profile_location,
    'image' => profile_image,
    'terms_accepted' => terms_accepted,
    'opt_in' => opt_in
  }
end
profile_email() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 77
def profile_email
  info['email']
end
profile_image() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 85
def profile_image
  info['image']
end
profile_location() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 81
def profile_location
  info['location']
end
profile_name() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 73
def profile_name
  info['name']
end
provider() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 42
def provider
  {
    'name' => provider_name,
    'uid' => provider_uid,
    'access_token' => provider_access_token
  }
end
provider_access_token() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 58
def provider_access_token
  auth['credentials']['token']
end
provider_name() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 50
def provider_name
  auth['provider']
end
provider_uid() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 54
def provider_uid
  auth['uid']
end
terms_accepted() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 89
def terms_accepted
  extra['terms_accepted'] || false
end
trace() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 105
def trace
  {
    'ip' => ip,
    'user_agent' => user_agent,
    'timestamp' => now,
    'platform' => platform,
    'locale' => locale,
    'country' => country
  }
end
user_agent() click to toggle source
# File lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb, line 127
def user_agent
  env['HTTP_USER_AGENT']
end