Class: Verndari::Congress

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Congress

Returns a new instance of Congress.



6
7
8
# File 'lib/verndari/congress.rb', line 6

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/verndari/congress.rb', line 16

def call(env)
  base_url = 'https://verndari.io'
  email = Verndari.configuration.email
  host = Verndari.configuration.host

  begin
    request = Rack::Request.new(env)

    res = Faraday.post "#{base_url}/api/keys/validate", { email: email, domain: host, data: request.params.to_json }
    json_body = JSON.parse(res.body)

    if json_body['is_valid'].eql?(true)
      status, headers, response = @app.call(env)
      return [status, headers, response]
    else
      return [ 500, {}, ["Internal Server Error\n"]]
    end
  rescue
    return [status, headers, response]
  end


end