diff --git a/.gitignore b/.gitignore index dcc5b36..1765970 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,31 @@ !/log/.keep !/tmp/.keep +# Ignore uploaded files in development +/storage/* +!/storage/.keep + /node_modules /yarn-error.log +/public/assets +/public/visitors +/public/temp/ .byebug_history + +# Ignore master key for decrypting credentials and more. +/config/master.key + +/public/packs +/public/packs-test +/node_modules +/yarn-error.log +yarn-debug.log* +.yarn-integrity + +# Ignore env files +.env + +# Ignore mac .DS_Store files +.DS_Store +*/.DS_Store diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..aedc15b --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.5.3 diff --git a/Gemfile b/Gemfile index 900a104..6463d63 100644 --- a/Gemfile +++ b/Gemfile @@ -43,6 +43,7 @@ group :development, :test do # Adds support for Capybara system testing and selenium driver gem 'capybara', '~> 2.13' gem 'selenium-webdriver' + gem 'dotenv-rails' end group :development do @@ -88,7 +89,7 @@ gem 'prawn-print' # Environment variables gem 'figaro' gem 'elastic-apm' - gem 'letter_opener' +gem 'letter_opener' gem 'pry-rails' gem 'rails-pry' -gem "jquery-fileupload-rails" \ No newline at end of file +gem "jquery-fileupload-rails" diff --git a/Gemfile.lock b/Gemfile.lock index 33812b8..29c4c37 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -16,62 +16,63 @@ GIT GEM remote: https://rubygems.org/ specs: - actioncable (5.2.3) - actionpack (= 5.2.3) + actioncable (5.2.5) + actionpack (= 5.2.5) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.3) - actionpack (= 5.2.3) - actionview (= 5.2.3) - activejob (= 5.2.3) + actionmailer (5.2.5) + actionpack (= 5.2.5) + actionview (= 5.2.5) + activejob (= 5.2.5) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.3) - actionview (= 5.2.3) - activesupport (= 5.2.3) - rack (~> 2.0) + actionpack (5.2.5) + actionview (= 5.2.5) + activesupport (= 5.2.5) + rack (~> 2.0, >= 2.0.8) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.3) - activesupport (= 5.2.3) + actionview (5.2.5) + activesupport (= 5.2.5) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.3) - activesupport (= 5.2.3) + activejob (5.2.5) + activesupport (= 5.2.5) globalid (>= 0.3.6) - activemodel (5.2.3) - activesupport (= 5.2.3) - activerecord (5.2.3) - activemodel (= 5.2.3) - activesupport (= 5.2.3) + activemodel (5.2.5) + activesupport (= 5.2.5) + activerecord (5.2.5) + activemodel (= 5.2.5) + activesupport (= 5.2.5) arel (>= 9.0) - activestorage (5.2.3) - actionpack (= 5.2.3) - activerecord (= 5.2.3) - marcel (~> 0.3.1) - activesupport (5.2.3) + activestorage (5.2.5) + actionpack (= 5.2.5) + activerecord (= 5.2.5) + marcel (~> 1.0.0) + activesupport (5.2.5) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) addressable (2.7.0) public_suffix (>= 2.0.2, < 5.0) - ajax-datatables-rails (1.0.0) - railties (>= 4.2) - annotate (2.7.5) + ajax-datatables-rails (1.3.1) + zeitwerk + annotate (3.1.1) activerecord (>= 3.2, < 7.0) - rake (>= 10.4, < 13.0) + rake (>= 10.4, < 14.0) arel (9.0.0) - bcrypt (3.1.13) + bcrypt (3.1.16) bindex (0.8.1) bootstrap3-datetimepicker-rails (4.17.47) momentjs-rails (>= 2.8.1) - breadcrumbs_on_rails (3.0.1) - builder (3.2.3) - byebug (11.0.1) + breadcrumbs_on_rails (4.1.0) + railties (>= 5.0) + builder (3.2.4) + byebug (11.1.3) capybara (2.18.0) addressable mini_mime (>= 0.1.3) @@ -79,16 +80,16 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (>= 2.0, < 4.0) - carrierwave (2.0.1) + carrierwave (2.2.1) activemodel (>= 5.0.0) activesupport (>= 5.0.0) addressable (~> 2.6) image_processing (~> 1.1) - mimemagic (>= 0.3.0) + marcel (~> 1.0.0) mini_mime (>= 0.1.3) - childprocess (2.0.0) - rake (< 13.0) - coderay (1.1.2) + ssrf_filter (~> 1.0) + childprocess (3.0.0) + coderay (1.1.3) coffee-rails (5.0.0) coffee-script (>= 2.2.0) railties (>= 5.2.0) @@ -96,9 +97,9 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.1.5) - crass (1.0.5) - devise (4.7.1) + concurrent-ruby (1.1.8) + crass (1.0.6) + devise (4.7.3) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0) @@ -106,36 +107,51 @@ GEM warden (~> 1.2.3) domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) - elastic-apm (2.10.1) + dotenv (2.7.6) + dotenv-rails (2.7.6) + dotenv (= 2.7.6) + railties (>= 3.2) + elastic-apm (3.15.1) concurrent-ruby (~> 1.0) http (>= 3.0) - erubi (1.8.0) + erubi (1.10.0) execjs (2.7.0) - faraday (0.15.4) + faraday (1.4.1) + faraday-excon (~> 1.1) + faraday-net_http (~> 1.0) + faraday-net_http_persistent (~> 1.1) multipart-post (>= 1.2, < 3) - ffi (1.11.1) - figaro (1.1.1) - thor (~> 0.14) + ruby2_keywords (>= 0.0.4) + faraday-excon (1.1.0) + faraday-net_http (1.0.1) + faraday-net_http_persistent (1.1.0) + ffi (1.15.0) + ffi-compiler (1.0.1) + ffi (>= 1.0.0) + rake + figaro (1.2.0) + thor (>= 0.14.0, < 2) globalid (0.4.2) activesupport (>= 4.2.0) - hashie (3.6.0) - http (4.1.1) + hashie (4.1.0) + http (4.4.1) addressable (~> 2.3) http-cookie (~> 1.0) - http-form_data (~> 2.0) - http_parser.rb (~> 0.6.0) + http-form_data (~> 2.2) + http-parser (~> 1.2.0) http-cookie (1.0.3) domain_name (~> 0.5) - http-form_data (2.1.1) - http_parser.rb (0.6.0) - i18n (1.6.0) + http-form_data (2.3.0) + http-parser (1.2.3) + ffi-compiler (>= 1.0, < 2.0) + i18n (1.8.10) concurrent-ruby (~> 1.0) - image_processing (1.9.3) + image_processing (1.12.1) mini_magick (>= 4.9.5, < 5) - ruby-vips (>= 2.0.13, < 3) + ruby-vips (>= 2.0.17, < 3) jSignature (0.0.6) - jbuilder (2.9.1) - activesupport (>= 4.2.0) + jbuilder (2.11.2) + activesupport (>= 5.0.0) jpeg_camera (1.3.2) railties (>= 3.1) jquery-datatables-rails (3.4.0) @@ -147,50 +163,47 @@ GEM actionpack (>= 3.1) railties (>= 3.1) sassc - jquery-rails (4.3.5) + jquery-rails (4.4.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) jwt (1.5.6) - launchy (2.4.3) - addressable (~> 2.3) + launchy (2.5.0) + addressable (~> 2.7) letter_opener (1.7.0) launchy (~> 2.2) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) ruby_dep (~> 1.2) - loofah (2.3.1) + loofah (2.9.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) - marcel (0.3.3) - mimemagic (~> 0.3.2) - method_source (0.9.2) - mimemagic (0.3.3) - mini_magick (4.9.5) - mini_mime (1.0.2) - mini_portile2 (2.4.0) - minitest (5.11.3) + marcel (1.0.1) + method_source (1.0.0) + mini_magick (4.11.0) + mini_mime (1.1.0) + minitest (5.14.4) momentjs-rails (2.20.1) railties (>= 3.1) - multi_json (1.13.1) + multi_json (1.15.0) multi_xml (0.6.0) multipart-post (2.1.1) - mysql2 (0.5.2) - nio4r (2.5.2) - nokogiri (1.10.8) - mini_portile2 (~> 2.4.0) - oauth (0.5.4) - oauth2 (1.4.1) - faraday (>= 0.8, < 0.16.0) + mysql2 (0.5.3) + nio4r (2.5.7) + nokogiri (1.11.3-x86_64-darwin) + racc (~> 1.4) + oauth (0.5.6) + oauth2 (1.4.7) + faraday (>= 0.8, < 2.0) jwt (>= 1.0, < 3.0) multi_json (~> 1.3) multi_xml (~> 0.5) rack (>= 1.2, < 3) - omniauth (1.9.0) - hashie (>= 3.4.6, < 3.7.0) + omniauth (1.9.1) + hashie (>= 3.4.6) rack (>= 1.6.2, < 3) omniauth-facebook (4.0.0) omniauth-oauth2 (~> 1.2) @@ -204,9 +217,9 @@ GEM omniauth-oauth2 (>= 1.3.1) omniauth-linkedin-oauth2 (1.0.0) omniauth-oauth2 - omniauth-oauth (1.1.0) + omniauth-oauth (1.2.0) oauth - omniauth (~> 1.0) + omniauth (>= 1.0, < 3) omniauth-oauth2 (1.3.1) oauth2 (~> 1.0) omniauth (~> 1.2) @@ -214,71 +227,73 @@ GEM omniauth-oauth (~> 1.1) rack orm_adapter (0.5.0) - pdf-core (0.7.0) - prawn (2.2.2) - pdf-core (~> 0.7.0) - ttfunk (~> 1.5) + pdf-core (0.9.0) + prawn (2.4.0) + pdf-core (~> 0.9.0) + ttfunk (~> 1.7) prawn-print (0.0.3) prawn (>= 0.12.0) - prawn-rails (1.3.0) + prawn-rails (1.4.0) prawn prawn-table - rails (>= 3.1.0) + railties (>= 3.1.0) prawn-table (0.2.2) prawn (>= 1.3.0, < 3.0.0) - pry (0.12.2) - coderay (~> 1.1.0) - method_source (~> 0.9.0) + pry (0.14.1) + coderay (~> 1.1) + method_source (~> 1.0) pry-rails (0.3.9) pry (>= 0.10.4) - public_suffix (4.0.1) - puma (4.3.3) + public_suffix (4.0.6) + puma (5.2.2) nio4r (~> 2.0) - rack (2.0.8) + racc (1.5.2) + rack (2.2.3) rack-test (1.1.0) rack (>= 1.0, < 3) - rails (5.2.3) - actioncable (= 5.2.3) - actionmailer (= 5.2.3) - actionpack (= 5.2.3) - actionview (= 5.2.3) - activejob (= 5.2.3) - activemodel (= 5.2.3) - activerecord (= 5.2.3) - activestorage (= 5.2.3) - activesupport (= 5.2.3) + rails (5.2.5) + actioncable (= 5.2.5) + actionmailer (= 5.2.5) + actionpack (= 5.2.5) + actionview (= 5.2.5) + activejob (= 5.2.5) + activemodel (= 5.2.5) + activerecord (= 5.2.5) + activestorage (= 5.2.5) + activesupport (= 5.2.5) bundler (>= 1.3.0) - railties (= 5.2.3) + railties (= 5.2.5) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.2.0) - loofah (~> 2.2, >= 2.2.2) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) rails-pry (0.0.1) - railties (5.2.3) - actionpack (= 5.2.3) - activesupport (= 5.2.3) + railties (5.2.5) + actionpack (= 5.2.5) + activesupport (= 5.2.5) method_source rake (>= 0.8.7) thor (>= 0.19.0, < 2.0) - rake (12.3.3) - rb-fsevent (0.10.3) - rb-inotify (0.10.0) + rake (13.0.3) + rb-fsevent (0.10.4) + rb-inotify (0.10.1) ffi (~> 1.0) - redis (4.1.3) - request_store (1.4.1) + redis (4.2.5) + request_store (1.5.0) rack (>= 1.4) - responders (3.0.0) + responders (3.0.1) actionpack (>= 5.0) railties (>= 5.0) - ruby-vips (2.0.15) - ffi (~> 1.9) + ruby-vips (2.1.0) + ffi (~> 1.12) + ruby2_keywords (0.0.4) ruby_dep (1.5.0) - rubyzip (1.3.0) + rubyzip (2.3.0) sass-rails (6.0.0) sassc-rails (~> 2.1, >= 2.1.1) - sassc (2.2.1) + sassc (2.4.0) ffi (~> 1.9) sassc-rails (2.1.2) railties (>= 4.0.0) @@ -286,52 +301,54 @@ GEM sprockets (> 3.0) sprockets-rails tilt - selenium-webdriver (3.142.4) - childprocess (>= 0.5, < 3.0) - rubyzip (~> 1.2, >= 1.2.2) - spring (2.1.0) + selenium-webdriver (3.142.7) + childprocess (>= 0.5, < 4.0) + rubyzip (>= 1.2.2) + spring (2.1.1) spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) spring (>= 1.2, < 3.0) - sprockets (3.7.2) + sprockets (4.0.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.1) + sprockets-rails (3.2.2) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - thor (0.20.3) + ssrf_filter (1.0.7) + thor (1.1.0) thread_safe (0.3.6) - tilt (2.0.9) - ttfunk (1.5.1) + tilt (2.0.10) + ttfunk (1.7.0) turbolinks (5.2.1) turbolinks-source (~> 5.2) turbolinks-source (5.2.0) - tzinfo (1.2.5) + tzinfo (1.2.9) thread_safe (~> 0.1) - uglifier (4.1.20) + uglifier (4.2.0) execjs (>= 0.3.0, < 3) unf (0.1.4) unf_ext - unf_ext (0.0.7.6) - warden (1.2.8) - rack (>= 2.0.6) + unf_ext (0.0.7.7) + warden (1.2.9) + rack (>= 2.0.9) web-console (3.7.0) actionview (>= 5.0) activemodel (>= 5.0) bindex (>= 0.4.0) railties (>= 5.0) - websocket-driver (0.7.1) + websocket-driver (0.7.3) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.4) - will_paginate (3.1.8) + websocket-extensions (0.1.5) + will_paginate (3.3.0) will_paginate-bootstrap (1.0.2) will_paginate (>= 3.0.3) xpath (3.2.0) nokogiri (~> 1.8) + zeitwerk (2.4.2) PLATFORMS - ruby + x86_64-darwin-20 DEPENDENCIES ajax-datatables-rails @@ -344,6 +361,7 @@ DEPENDENCIES coffee-rails devise devise_security_extension! + dotenv-rails elastic-apm figaro jSignature @@ -387,4 +405,4 @@ RUBY VERSION ruby 2.5.3p105 BUNDLED WITH - 2.0.1 + 2.2.16 diff --git a/app/assets/javascripts/visitors.coffee b/app/assets/javascripts/visitors.coffee deleted file mode 100644 index 24f83d1..0000000 --- a/app/assets/javascripts/visitors.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/admin/font-awesome.scss b/app/assets/stylesheets/admin/font-awesome.scss index f7e1447..afd73e1 100644 --- a/app/assets/stylesheets/admin/font-awesome.scss +++ b/app/assets/stylesheets/admin/font-awesome.scss @@ -1,6 +1,6 @@ /*! * SmartAdmin v1.8.2 () - * Copyright 2011-2016 + * Copyright 2011-2016 */ /*! * Font Awesome 4.2.0 by @davegandy - http://fontawesome.io - @fontawesome @@ -8,8 +8,8 @@ */ @font-face { font-family: 'FontAwesome'; - src: asset-url('font-awesome/fontawesome-webfont.eot?v=4.5.0'); - src: asset-url('font-awesome/fontawesome-webfont.eot?v=4.5.0#iefix') format('embedded-opentype'), asset-url('font-awesome/fontawesome-webfont.woff2?v=4.5.0') format('woff2'), asset-url('font-awesome/fontawesome-webfont.woff?v=4.5.0') format('woff'), asset-url('font-awesome/fontawesome-webfont.ttf?v=4.5.0') format('truetype'), asset-url('font-awesome/fontawesome-webfont.svg?v=4.5.0#fontawesomeregular') format('svg'); + src: font-url('font-awesome/fontawesome-webfont.eot?v=4.5.0'); + src: font-url('font-awesome/fontawesome-webfont.eot?v=4.5.0#iefix') format('embedded-opentype'), font-url('font-awesome/fontawesome-webfont.woff2?v=4.5.0') format('woff2'), font-url('font-awesome/fontawesome-webfont.woff?v=4.5.0') format('woff'), font-url('font-awesome/fontawesome-webfont.ttf?v=4.5.0') format('truetype'), font-url('font-awesome/fontawesome-webfont.svg?v=4.5.0#fontawesomeregular') format('svg'); font-weight: normal; font-style: normal; } diff --git a/app/controllers/devise/sessions_controller.rb b/app/controllers/devise/sessions_controller.rb index d65e468..79bef82 100644 --- a/app/controllers/devise/sessions_controller.rb +++ b/app/controllers/devise/sessions_controller.rb @@ -12,13 +12,13 @@ class Devise::SessionsController < DeviseController # GET /resource/sign_in def new @page_content = AdminLoginPage.first - + self.resource = resource_class.new(sign_in_params) clean_up_passwords(resource) yield resource if block_given? respond_with(resource, serialize_options(resource)) end - + # POST /resource/sign_in def create self.resource = warden.authenticate!(auth_options) @@ -27,7 +27,7 @@ def create yield resource if block_given? respond_with resource, location: after_sign_in_path_for(resource) end - + # DELETE /resource/sign_out def destroy signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)) @@ -35,30 +35,30 @@ def destroy yield if block_given? respond_to_on_destroy end - + protected - + def sign_in_params devise_parameter_sanitizer.sanitize(:sign_in) end - + def serialize_options(resource) methods = resource_class.authentication_keys.dup methods = methods.keys if methods.is_a?(Hash) methods << :password if resource.respond_to?(:password) { methods: methods, only: [:password] } end - + def auth_options { scope: resource_name, recall: "#{controller_path}#new" } end - + def translation_scope 'devise.sessions' end - + private - + # Check if there is no signed in user before doing the sign out. # # If there is no signed in user, it will set the flash message and redirect @@ -66,17 +66,17 @@ def translation_scope def verify_signed_out_user if all_signed_out? set_flash_message! :notice, :already_signed_out - + respond_to_on_destroy end end - + def all_signed_out? users = Devise.mappings.keys.map { |s| warden.user(scope: s, run_callbacks: false) } - + users.all?(&:blank?) end - + def respond_to_on_destroy # We actually need to hardcode this as Rails default responder doesn't # support returning empty response on GET request @@ -115,4 +115,4 @@ def regexp_match?(list, remote_ip, b = true) end false end -end \ No newline at end of file +end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index b820eb1..efb15be 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -250,4 +250,31 @@ def check_email } end end + + def recognize_visitor + save_temp_image + result = LuxandCloudFaceRecognitionService.new.recognize("#{ENV["BASE_URL"]}/temp/temp_img.jpg") + File.delete(File.join(Rails.root, 'public', 'temp', "temp_img.jpg")) + if result.present? + visitor = Visitor.find_by(luxand_cloud_person_id: result[0]["id"]) + render json: {success: true, visitor: visitor } + else + render json: {success: false, errors: 'Visitor Not found or no missed visit found' } + end + end + + private + + def save_temp_image + storage_path = File.join(Rails.root, "public") + path = storage_path + "/temp" + FileUtils.mkdir_p(path) unless File.directory?(path) + image = path + "/temp_img.jpg" + unless FileTest.exist?(image) + if params["person_image_url"] + data = StringIO.new( Base64.decode64(params["person_image_url"].sub('data:image/jpeg;base64', '') )) + File.open(File.join(Rails.root, 'public', 'temp', "temp_img.jpg"), 'wb') { |f| f.write data.read } + end + end + end end diff --git a/app/models/visitor.rb b/app/models/visitor.rb index 9d40b59..cfe6bcf 100644 --- a/app/models/visitor.rb +++ b/app/models/visitor.rb @@ -75,6 +75,7 @@ class Visitor < ApplicationRecord after_create do save_image_avatar + create_luxand_cloud_person end def name @@ -203,4 +204,9 @@ def save_image_avatar end end + def create_luxand_cloud_person + person = LuxandCloudFaceRecognitionService.new.create_person(self.name) + self.update(luxand_cloud_person_id: person["id"]) + face_details = LuxandCloudFaceRecognitionService.new.add_face_to_person(self.luxand_cloud_person_id, "#{ENV["BASE_URL"]}/visitors/visitor_#{self.id}.jpg") + end end diff --git a/app/services/luxand_cloud_face_recognition_service.rb b/app/services/luxand_cloud_face_recognition_service.rb new file mode 100644 index 0000000..465fad8 --- /dev/null +++ b/app/services/luxand_cloud_face_recognition_service.rb @@ -0,0 +1,67 @@ +require 'uri' +require 'net/http' +require 'openssl' + +class LuxandCloudFaceRecognitionService + + def initialize + end + + def recognize(image_url) + begin + url = URI("https://luxand-cloud-face-recognition.p.rapidapi.com/photo/search") + + http = Net::HTTP.new(url.host, url.port) + http.use_ssl = true + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + + request = Net::HTTP::Post.new(url) + request["content-type"] = 'application/x-www-form-urlencoded' + request["x-rapidapi-key"] = ENV['RAPID_API_KEY'] + request["x-rapidapi-host"] = 'luxand-cloud-face-recognition.p.rapidapi.com' + request.body = "photo=#{image_url}" + + response = http.request(request) + puts response.read_body + JSON.parse(response.read_body) + rescue StandardError => e + puts e + end + end + + def create_person(name) + url = URI("https://luxand-cloud-face-recognition.p.rapidapi.com/subject") + + http = Net::HTTP.new(url.host, url.port) + http.use_ssl = true + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + + request = Net::HTTP::Post.new(url) + request["content-type"] = 'application/x-www-form-urlencoded' + request["x-rapidapi-key"] = ENV['RAPID_API_KEY'] + request["x-rapidapi-host"] = 'luxand-cloud-face-recognition.p.rapidapi.com' + request.body = "name=#{name}" + + response = http.request(request) + puts response.read_body + JSON.parse(response.read_body) + end + + def add_face_to_person(person_id, image_url) + url = URI("https://luxand-cloud-face-recognition.p.rapidapi.com/subject/#{person_id}") + + http = Net::HTTP.new(url.host, url.port) + http.use_ssl = true + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + + request = Net::HTTP::Post.new(url) + request["content-type"] = 'application/x-www-form-urlencoded' + request["x-rapidapi-key"] = ENV['RAPID_API_KEY'] + request["x-rapidapi-host"] = 'luxand-cloud-face-recognition.p.rapidapi.com' + request.body = "photo=#{image_url}" + + response = http.request(request) + puts response.read_body + JSON.parse(response.read_body) + end +end diff --git a/app/views/shared/_head.html.erb b/app/views/shared/_head.html.erb index 02fca84..bfc9778 100644 --- a/app/views/shared/_head.html.erb +++ b/app/views/shared/_head.html.erb @@ -10,8 +10,7 @@ - - <%= stylesheet_link_tag 'admin/application', media: 'all', 'data-turbolinks-track'=> 'reload' %> + <%= stylesheet_link_tag 'admin/application', media: 'all', 'data-turbolinks-track'=> 'reload' %> <%= javascript_include_tag 'admin/application', 'data-turbolinks-track'=> 'reload' %> @@ -20,7 +19,7 @@