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
encode_meta_string(meta_string)
click to toggle source
format_gallery_name(name_string)
click to toggle source
Gallery
name cannot contain spaces. This methods formats the string by eliminating spaces.
# 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)
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