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.face.com/faces/detect.json',
  :faces_recognize => 'http://api.face.com/faces/recognize.json',
  :faces_train => 'http://api.face.com/faces/train.json',
  :faces_status => 'http://api.face.com/faces/status.json',
  :tags_get => 'http://api.face.com/tags/get.json',
  :tags_add => 'http://api.face.com/tags/add.json',
  :tags_save => 'http://api.face.com/tags/save.json',
  :tags_remove => 'http://api.face.com/tags/remove.json',
  :account_limits => 'http://api.face.com/account/limits.json',
  :account_users => 'http://api.face.com/account/users.json'
}

Instance Method Summary collapse

Instance Method Details

#api_crendentialObject



20
21
22
# File 'lib/face/client/utils.rb', line 20

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

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



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/face/client/utils.rb', line 24

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
  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



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/face/client/utils.rb', line 40

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