Class: Facehugger

Inherits:
Object
  • Object
show all
Includes:
Face::API
Defined in:
lib/facehugger.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {:api_key => "", :api_secret => ""}) ⇒ Facehugger

Returns a new instance of Facehugger.



11
12
13
14
# File 'lib/facehugger.rb', line 11

def initialize(args = {:api_key => "", :api_secret => ""})
  @api_key = args[:api_key]
  @api_secret = args[:api_secret]
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



9
10
11
# File 'lib/facehugger.rb', line 9

def api_key
  @api_key
end

#api_secretObject

Returns the value of attribute api_secret.



9
10
11
# File 'lib/facehugger.rb', line 9

def api_secret
  @api_secret
end

Class Method Details

.photos(response = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/facehugger.rb', line 21

def self.photos(response = {})
  photos = []

  if response.has_key? 'photos'
    response['photos'].each do |photo|
      photos << Face::Photo.new(photo)
    end
  end

  photos
end

Instance Method Details

#faces_detect(args = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/facehugger.rb', line 33

def faces_detect(args = {})
  response = super args
  return nil if response['status'] != 'success'

  photos = Facehugger.photos response
  return nil if photos.nil?

  photos.each do |photo|
    tags = []

    photo.tags.sort_by! do |t|
      t['attributes']['face']['confidence']
    end.reverse.each do |tag|
      tags << Face::Tag.new(tag)
    end

    photo.tags = tags
  end

  photos
end

#valid?Boolean

Returns:

  • (Boolean)


16
17
18
19
# File 'lib/facehugger.rb', line 16

def valid?
  response = 
  response['status'] == 'success'
end