Module: Findface

Defined in:
lib/findface.rb,
lib/findface/api.rb,
lib/findface/face.rb,
lib/findface/error.rb,
lib/findface/gallery.rb,
lib/findface/utility.rb,
lib/findface/version.rb

Defined Under Namespace

Classes: API, Error, Face, Gallery, Utility

Constant Summary collapse

VERSION =
"0.0.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_keyObject

Returns API key or raises exception



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

def api_key
  defined? @api_key and @api_key or raise "Findface.api_key not configured"
end

Class Method Details

.base_uriObject

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’



14
15
16
# File 'lib/findface.rb', line 14

def base_uri
  @base_uri = "https://api.findface.pro/v0/"
end

.encode_meta_string(meta_string) ⇒ Object

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



33
34
35
# File 'lib/findface.rb', line 33

def encode_meta_string meta_string
  return meta_string.gsub(" ", "%20") if meta_string
end

Gallery name cannot contain spaces. This methods formats the string by eliminating spaces.



39
40
41
# File 'lib/findface.rb', line 39

def format_gallery_name name_string
  return name_string.gsub(" ", '') if name_string
end

.get_list(page_name, pages = nil) ⇒ Object

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



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# 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_authObject

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: => {:Authorization => ‘Token YOUR_TOKEN’}, :body => request_specific_options_hash}



23
24
25
26
27
28
29
# File 'lib/findface.rb', line 23

def token_auth
  {
    :headers => {
      :Authorization => "Token " + api_key
    }
  }
end