rekognition 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in face.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2010 {andyisnowskynet (Andy Schmidt)}[http://thisislabcoat.com]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,15 @@
1
+ Note: This gem is still under development, create issues if you meet any problem when using it https://github.com/andyisnowskynet/rekognition/issues
2
+
3
+ Rekognition is a ruby library of Rekognition Face Detection and Recognition API.
4
+
5
+ == Getting Started
6
+
7
+ sudo gem install rekognition
8
+
9
+ irb
10
+ >> require 'rekognition'
11
+ >> client = Rekognition.get_client(:api_key => 'your_api_key', :api_secret => 'your_api_secret')
12
+
13
+ More Documentation refer to https://rekognition.com/developer/docs
14
+
15
+ Author: Andy Schmidt (andy@thisislabcoat.com)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/lib/ext/hash.rb ADDED
@@ -0,0 +1,34 @@
1
+ require File.expand_path('../object', __FILE__)
2
+
3
+ class Hash
4
+
5
+ def assert_valid_keys(*valid_keys)
6
+ unknown_keys = keys - [valid_keys].flatten
7
+ raise(ArgumentError, "Unknown key(s): #{unknown_keys.join(", ")}") unless unknown_keys.empty?
8
+ end
9
+
10
+ def assert_required_keys(*required_keys)
11
+ missing_keys = []
12
+ for required_key in required_keys do
13
+ # if they required key is an array that means the request must contain
14
+ # one of the keys, but not more
15
+ if required_key.is_a?(Array)
16
+ if (keys-required_key).count < keys.count-1 # too many keys sent when they need only one
17
+ missing_keys << "must choose one of either #{required_key.join(' or ')}"
18
+ elsif (keys-required_key).count == keys.count # they didn't send any of the options
19
+ missing_keys << required_key.join(" or ")
20
+ end
21
+ else
22
+ missing_keys << required_key unless keys.include?(required_key)
23
+ end
24
+ end
25
+ raise(ArgumentError, "Missing required key(s): #{missing_keys.join(", ")}") unless missing_keys.empty?
26
+ end
27
+
28
+ def to_param(namespace = nil)
29
+ collect do |key, value|
30
+ value.to_query(namespace ? "#{namespace}[#{key}]" : key)
31
+ end.sort * '&'
32
+ end
33
+
34
+ end
data/lib/ext/object.rb ADDED
@@ -0,0 +1,12 @@
1
+ class Object
2
+
3
+ def to_param
4
+ to_s
5
+ end
6
+
7
+ def to_query(key)
8
+ require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
9
+ "#{CGI.escape(key.to_s).gsub(/%(5B|5D)/n) { [$1].pack('H*') }}=#{CGI.escape(to_param.to_s)}"
10
+ end
11
+
12
+ end
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'rest_client'
3
+ require 'json'
4
+
5
+ require File.expand_path('../rekognition/client', __FILE__)
6
+
7
+ module Rekognition
8
+
9
+ def self.get_client(opts={})
10
+ Rekognition::Client::Base.new(opts)
11
+ end
12
+
13
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../ext/hash', __FILE__)
2
+ require File.expand_path('../client/base', __FILE__)
3
+
4
+ module Rekognition
5
+ module Client
6
+ end
7
+ end
@@ -0,0 +1,41 @@
1
+ require File.expand_path('../utils', __FILE__)
2
+ require File.expand_path('../face', __FILE__)
3
+ require File.expand_path('../scene', __FILE__)
4
+
5
+ module Rekognition
6
+ module Client
7
+ class Base
8
+
9
+ attr_accessor :api_key, :api_secret, :name_space
10
+
11
+ include Rekognition::Client::Utils
12
+ include Rekognition::Client::Face
13
+ include Rekognition::Client::Scene
14
+
15
+
16
+ def initialize(opts={})
17
+ opts.assert_valid_keys(:api_key, :api_secret, :name_space)
18
+ @api_key, @api_secret, @name_space = opts[:api_key], opts[:api_secret], opts[:name_space]
19
+ end
20
+
21
+ protected
22
+ def compile_jobs_string_and_make_request(method_name, opts)
23
+ jobs_string = method_name
24
+ if opts[:jobs]
25
+ opts[:jobs].delete(method_name)
26
+ opts[:jobs].prepend(method_name)
27
+ jobs_string << opts[:jobs].join("_")
28
+ opts[:jobs] = jobs_string
29
+ else
30
+ opts = opts.merge(:jobs => method_name)
31
+ end
32
+
33
+ if opts[:tags].is_a?(Array)
34
+ opts[:tags] = opts[:tags].join(";")
35
+ end
36
+
37
+ make_request(opts)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,80 @@
1
+ module Rekognition
2
+ module Client
3
+ module Face
4
+ def face_detect(opts={})
5
+ opts.assert_valid_keys(:jobs, :urls, :base64)
6
+ opts.assert_required_keys([:urls, :base64])
7
+ compile_jobs_string_and_make_request("face", opts)
8
+ end
9
+
10
+ def face_add(opts={})
11
+ opts.assert_valid_keys(:jobs, :urls, :base64, :user_id, :tag)
12
+ opts.assert_required_keys([:urls, :base64])
13
+ compile_jobs_string_and_make_request("face_add", opts)
14
+ end
15
+
16
+
17
+ def face_train(opts={})
18
+ opts.assert_valid_keys(:jobs, :user_id, :tags)
19
+ # if they have tags we call the sync method because they must be trying to train just those tags
20
+ if opts[:tags]
21
+ compile_jobs_string_and_make_request("face_train_sync", opts)
22
+ else
23
+ compile_jobs_string_and_make_request("face_train", opts)
24
+ end
25
+ end
26
+
27
+ def face_train_sync(opts={})
28
+ opts.assert_valid_keys(:jobs, :user_id, :tags)
29
+ opts.assert_required_keys(:tags)
30
+ compile_jobs_string_and_make_request("face_train_sync", opts)
31
+ end
32
+
33
+
34
+ def face_cluster(opts={})
35
+ opts.assert_valid_keys(:jobs, :user_id, :aggressiveness)
36
+ compile_jobs_string_and_make_request("face_cluster", opts)
37
+ end
38
+
39
+
40
+ def face_crawl(opts={})
41
+ opts.assert_valid_keys(:jobs, :fb_id, :access_token, :user_id)
42
+ opts.assert_required_keys(:fb_id, :access_token)
43
+ compile_jobs_string_and_make_request("face_crawl", opts)
44
+ end
45
+
46
+ def face_recognize(opts={})
47
+ opts.assert_valid_keys(:jobs, :urls, :base64, :user_id, :num_return, :tags)
48
+ opts.assert_required_keys([:urls, :base64])
49
+ compile_jobs_string_and_make_request("face_recognize", opts)
50
+ end
51
+
52
+ def face_visualize(opts={})
53
+ opts.assert_valid_keys(:jobs, :user_id, :tags, :num_tag_return, :num_img_return_pertag)
54
+ compile_jobs_string_and_make_request("face_vizualize", opts)
55
+ end
56
+
57
+ def face_search(opts={})
58
+ opts.assert_valid_keys(:jobs, :urls, :base64, :user_id, :num_return)
59
+ opts.assert_required_keys([:urls, :base64])
60
+ compile_jobs_string_and_make_request("face_search", opts)
61
+ end
62
+
63
+ def face_delete(opts={})
64
+ opts.assert_valid_keys(:jobs, :user_id, :tag, :img_index)
65
+ compile_jobs_string_and_make_request("face_delete", opts)
66
+ end
67
+
68
+ def face_rename(opts={})
69
+ opts.assert_valid_keys(:jobs, :tag, :new_tag, :user_id, :img_index)
70
+ opts.assert_required_keys(:tag, :new_tag, :user_id)
71
+ compile_jobs_string_and_make_request("face_rename", opts)
72
+ end
73
+
74
+ def face_stats(opts={})
75
+ opts.assert_valid_keys(:jobs)
76
+ compile_jobs_string_and_make_request("face_name_space_stats", opts)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,11 @@
1
+ module Rekognition
2
+ module Client
3
+ module Scene
4
+ def scene_understanding(opts={})
5
+ opts.assert_valid_keys(:jobs, :urls, :base64)
6
+ opts.assert_required_keys([:urls, :base64])
7
+ compile_jobs_string_and_make_request("scene", opts)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ module Rekognition
2
+ module Client
3
+ module Utils
4
+
5
+ class RekognitionError < StandardError; end
6
+
7
+ API_METHOD = "http://rekognition.com/func/api/"
8
+
9
+ def api_credentials
10
+ { :api_key => api_key, :api_secret => api_secret, :name_space => name_space}
11
+ end
12
+
13
+ def make_request(opts={})
14
+ response = RestClient.post(API_METHOD, opts.merge(api_credentials), :content_type => :json, :accept => :json)
15
+ begin
16
+ JSON.parse response.body
17
+ rescue
18
+ raise(RekognitionError, "Malformed response from Rekognition API: #{response}")
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Rekognition
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rekognition/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rekognition"
7
+ s.version = Rekognition::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Andy Schmidt"]
10
+ s.email = ["andy@thisislabcoat.com"]
11
+ s.homepage = "http://thisislabcoat.com"
12
+ s.summary = %q{Ruby wrapper of Rekognition Face Detection and Recognition API}
13
+ s.description = %q{Ruby wrapper of Rekognition Face Detection and Recognition API}
14
+
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency "rest-client", ">=1.6.1"
22
+ s.add_dependency "json", ">=1.4.6"
23
+
24
+ s.licenses = 'MIT'
25
+
26
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rekognition
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andy Schmidt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.6.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.6.1
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.4.6
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.4.6
46
+ description: Ruby wrapper of Rekognition Face Detection and Recognition API
47
+ email:
48
+ - andy@thisislabcoat.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE
56
+ - README.rdoc
57
+ - Rakefile
58
+ - lib/ext/hash.rb
59
+ - lib/ext/object.rb
60
+ - lib/rekognition.rb
61
+ - lib/rekognition/client.rb
62
+ - lib/rekognition/client/base.rb
63
+ - lib/rekognition/client/face.rb
64
+ - lib/rekognition/client/scene.rb
65
+ - lib/rekognition/client/utils.rb
66
+ - lib/rekognition/version.rb
67
+ - rekognition.gemspec
68
+ homepage: http://thisislabcoat.com
69
+ licenses:
70
+ - MIT
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 1.8.25
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Ruby wrapper of Rekognition Face Detection and Recognition API
93
+ test_files: []