class Towise::API
Attributes
BASE_URL[RW]
DETECT[RW]
FACES[RW]
PERSONS[RW]
RECOGNIZE[RW]
headers[RW]
Public Class Methods
new(config)
click to toggle source
# File lib/towise.rb, line 8 def initialize(config) config['Content-Type'] = 'application/x-www-form-urlencoded' @headers = config @BASE_URL = "https://api.towise.io" @DETECT = { "face" => "/detect/face", "body" => "/detect/person", "emotion" => "/detect/emotion" } @RECOGNIZE = { "face" => "/recognize/face" } @PERSONS = "/persons/" @FACES = "/faces/" end
Public Instance Methods
addFace(image, personId,imageSave="no")
click to toggle source
# File lib/towise.rb, line 140 def addFace(image, personId,imageSave="no") data = checkImage?(image) data['person_id'] = personId data['save_image'] = imageSave conn = Faraday.new(:url => @BASE_URL) do |f| f.headers = @headers f.request :url_encoded f.adapter Faraday.default_adapter end response = conn.post(@FACES,data) return JSON.parse(response.body) end
addPerson(name)
click to toggle source
# File lib/towise.rb, line 95 def addPerson(name) data = { "name" => name } conn = Faraday.new(:url => @BASE_URL) do |f| f.headers = @headers f.request :url_encoded f.adapter Faraday.default_adapter end response = conn.post(@PERSONS,data) return JSON.parse(response.body) end
bodyDetect(image=nil)
click to toggle source
# File lib/towise.rb, line 45 def bodyDetect(image=nil) conn = Faraday.new(:url => @BASE_URL) do |f| f.headers = @headers f.request :url_encoded f.adapter Faraday.default_adapter end response = conn.post(@DETECT['body'],checkImage?(image)) return JSON.parse(response.body) end
checkImage?(image)
click to toggle source
# File lib/towise.rb, line 25 def checkImage?(image) isBase64 = !!image.match(/(data:image\/jpeg;base63)/) if(isBase64) return { "image_base64" => image} else return {"image_url" => image} end end
emotionDetect(image=nil)
click to toggle source
# File lib/towise.rb, line 56 def emotionDetect(image=nil) conn = Faraday.new(:url => @BASE_URL) do |f| f.headers = @headers f.request :url_encoded f.adapter Faraday.default_adapter end response = conn.post(@DETECT['emotion'],checkImage?(image)) return JSON.parse(response.body) end
faceComparing(image=nil)
click to toggle source
# File lib/towise.rb, line 66 def faceComparing(image=nil) conn = Faraday.new(:url => @BASE_URL) do |f| f.headers = @headers f.request :url_encoded f.adapter Faraday.default_adapter end response = conn.post(@RECOGNIZE['face'],checkImage?(image)) return JSON.parse(response.body) end
faceDetect(image=nil)
click to toggle source
# File lib/towise.rb, line 34 def faceDetect(image=nil) conn = Faraday.new(:url => @BASE_URL) do |f| f.headers = @headers f.request :url_encoded f.adapter Faraday.default_adapter end response = conn.post(@DETECT['face'],checkImage?(image)) return JSON.parse(response.body) end
getAllFace(personId)
click to toggle source
# File lib/towise.rb, line 120 def getAllFace(personId) conn = Faraday.new(:url => @BASE_URL) do |f| f.headers = @headers f.params['person_id'] = personId f.adapter Faraday.default_adapter end response = conn.get(@FACES) return JSON.parse(response.body) end
getAllPerson()
click to toggle source
# File lib/towise.rb, line 76 def getAllPerson() conn = Faraday.new(:url => @BASE_URL) do |f| f.headers = @headers f.adapter Faraday.default_adapter end response = conn.get(@PERSONS) return JSON.parse(response.body) end
getFace(faceId)
click to toggle source
# File lib/towise.rb, line 130 def getFace(faceId) conn = Faraday.new(:url => @BASE_URL) do |f| f.headers = @headers f.params['face_id'] = faceId f.adapter Faraday.default_adapter end response = conn.get(@FACES) return JSON.parse(response.body) end
getPerson(personId)
click to toggle source
# File lib/towise.rb, line 85 def getPerson(personId) conn = Faraday.new(:url => @BASE_URL) do |f| f.headers = @headers f.params['person_id'] = personId f.adapter Faraday.default_adapter end response = conn.get(@PERSONS) return JSON.parse(response.body) end
removeFace(faceId)
click to toggle source
# File lib/towise.rb, line 154 def removeFace(faceId) data = { "face_id" => faceId } conn = Faraday.new(:url => @BASE_URL) do |f| f.request :url_encoded f.adapter Faraday.default_adapter end response = conn.run_request(:delete,@FACES,data,@headers) return JSON.parse(response.body) end
removePerson(personId)
click to toggle source
# File lib/towise.rb, line 108 def removePerson(personId) data = { "person_id":personId } conn = Faraday.new(:url => @BASE_URL) do |f| f.request :url_encoded f.adapter Faraday.default_adapter end response = conn.run_request(:delete,@PERSONS,data,@headers) return JSON.parse(response.body) end