module Findface

Constants

VERSION

Attributes

api_key[W]

Public Class Methods

api_key() click to toggle source

Returns API key or raises exception

# File lib/findface.rb, line 6
def api_key
  defined? @api_key and @api_key or raise "Findface.api_key not configured"
end
base_uri() click to toggle source

Sets the API endpoint base uri. For each API request, the request specific element must be added excluding the common part of uri. An example for entities is: base_uri + 'entities'

# File lib/findface.rb, line 14
def base_uri
  @base_uri = "https://api.findface.pro/v0/"
end
encode_meta_string(meta_string) click to toggle source

Returns a string replacing a space with '%20' Findface API do not accept strings with spaces or usage of '+' in the string.

# File lib/findface.rb, line 33
def encode_meta_string meta_string
  return meta_string.gsub(" ", "%20") if meta_string
end
get_list(page_name, pages = nil) click to toggle source

Extensible method to manage & serve results considering pagination parameters supported by API.

# File lib/findface.rb, line 44
def get_list page_name, pages = nil
  next_page_url = pages[:next_page].split('?').last if !pages.nil? && !pages[:next_page].nil? && !pages[:next_page] != ''
  prev_page_url = pages[:prev_page].split('?').last if !pages.nil? && !pages[:prev_page].nil? && !pages[:prev_page] != ''
  if !next_page_url.nil? && prev_page_url.nil?
    API::request(:get, page_name + '?' +next_page_url)
  elsif next_page_url.nil? && !prev_page_url.nil?
    request_url = 
    API::request(:get, page_name + '?' + prev_page_url)
  elsif !next_page_url.nil? && !prev_page_url.nil?
    API::request(:get, page_name + '?' + next_page_url + '&' + prev_page_url)
  else
    #Regular request is executed if pages value is not present or contains invalid hash key names other than next_page & pev_page
    API::request(:get, page_name)
  end
end
token_auth() click to toggle source

Returns simple token based authentication hash. While making a request, merge this hash into options hash of request. We also need to merge request specific hash with key as body. The overall format looks as follows: {:headers => {:Authorization => 'Token YOUR_TOKEN'}}, :body => request_specific_options_hash}

# File lib/findface.rb, line 23
def token_auth
  {
    :headers => {
      :Authorization => "Token " + api_key
    }
  }
end