Module: Face::Client::Utils

Included in:
Base
Defined in:
lib/face/client/utils.rb

Defined Under Namespace

Classes: FaceError

Constant Summary collapse

API_METHODS =
{
  :faces_detect => 'http://api.skybiometry.com/fc/faces/detect.json',
  :faces_group => 'http://api.skybiometry.com/fc/faces/group.json',
  :faces_recognize => 'http://api.skybiometry.com/fc/faces/recognize.json',
  :faces_train => 'http://api.skybiometry.com/fc/faces/train.json',
  :faces_status => 'http://api.skybiometry.com/fc/faces/status.json',
  :tags_get => 'http://api.skybiometry.com/fc/tags/get.json',
  :tags_add => 'http://api.skybiometry.com/fc/tags/add.json',
  :tags_save => 'http://api.skybiometry.com/fc/tags/save.json',
  :tags_remove => 'http://api.skybiometry.com/fc/tags/remove.json',
  :account_limits => 'http://api.skybiometry.com/fc/account/limits.json',
  :account_users => 'http://api.skybiometry.com/fc/account/users.json',
  :account_namespaces => 'http://api.skybiometry.com/fc/account/namespaces.json',
  :account_authenticate => 'http://api.skybiometry.com/fc/account/authenticate.json'
}

Instance Method Summary collapse

Instance Method Details

#api_crendentialObject



23
24
25
# File 'lib/face/client/utils.rb', line 23

def api_crendential
  { :api_key => api_key, :api_secret => api_secret }
end

#make_request(api_method, opts = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/face/client/utils.rb', line 27

def make_request(api_method, opts={})
  if opts[:urls].is_a? Array
    opts[:urls] = opts[:urls].join(',')
  end

  if opts[:uids].is_a? Array
    opts[:uids] = opts[:uids].join(',')
  end
  
  if opts[:tids].is_a? Array
    opts[:tids] = opts[:tids].join(',')
  end

  if opts[:pids].is_a? Array
    opts[:pids] = opts[:pids].join(',')
  end
  
  response = JSON.parse( RestClient.post(API_METHODS[ api_method ], opts.merge(api_crendential)).body )
  if %w/success partial/.include?(response['status'])
    response
  elsif response['status'] == 'failure'
    raise FaceError.new("Error: #{response['error_code']}, #{response['error_message']}")
  end
end

#user_auth_paramObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/face/client/utils.rb', line 52

def user_auth_param
  user_auth_value = []
  if twitter_credentials
    twitter_credentials.each do |k, v|
      user_auth_value << "#{k}:#{v}"
    end
  elsif twitter_oauth_credentials
    twitter_oauth_credentials.each do |k,v|
      user_auth_value << "#{k}:#{v}"
    end
  end
  if facebook_credentials
    facebook_credentials.each do |k, v|
      user_auth_value << "#{k}:#{v}"
    end
  end
  user_auth_value.size > 0 ? { :user_auth => user_auth_value.join(',') } : {}
end