Class: Andrewfun

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

Class Method Summary collapse

Class Method Details

.hi(url, request) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/andrewfun.rb', line 4

def self.hi(url, request)
  puts request
  response = HTTParty.get(url)
  authorizationResponse = JSON.parse(response.body)
  puts authorizationResponse["authorized"]
  otp = request.headers["HTTP_OTP"]
  humantoken = request.headers["HTTP_HUMANTOKEN"]
  devicetoken = request.headers["HTTP_DEVICE_TOKEN"]
  ip = request.remote_ip
  if ip == "::1" || ip == "127.0.0.1"
    puts "here"
    realIpData = HTTParty.get("https://api.ipify.org?format=json")
    puts "there"
    puts realIpData
    parsedIpData = JSON.parse(realIpData.body)
    ip = parsedIpData["ip"]
  end
  possibletoken = request.headers["HTTP_TOKEN"].split("Bearer ")
  token = request.headers["HTTP_TOKEN"] || possibletoken
  headers = { 
  "method"  => request.method,
  "ip" => ip,
  "token" => token,
  "api" => request.original_url.split(request.original_fullpath)[0],
  "action" => request.original_fullpath,
  "fullActionPath" => request.original_url 
  }

  if devicetoken != nil 
    headers["device_token"] = devicetoken
  end

  if otp != nil 
    headers["otp"] = otp
  end

  if humantoken != nil
    headers["humantoken"] = humantoken
  end


  puts token
  puts devicetoken
  puts humantoken
  puts otp
  puts ip
  puts headers
  authorizedMessage = HTTParty.get(url, :headers => headers)
  authorizationResult = JSON.parse(authorizedMessage.body)
  return authorizationResult
end