macruby-face 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 {rociiu (Roc Yu)}[http://rociiu.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,28 @@
1
+ Note: This gem is still under development , create issues if you meet any problem when using it https://github.com/rociiu/face/issues
2
+
3
+ Face is a ruby library of http://developers.face.com/.
4
+
5
+ == Getting Started
6
+
7
+ sudo gem install face
8
+
9
+ irb
10
+ >> require 'face'
11
+ >> client = Face.get_client(:api_key => 'your_api_key', :api_secret => 'your_api_secret')
12
+
13
+ Detect Faces with Urls:
14
+
15
+ >> client.faces_detect(:urls => ['http://farm6.static.flickr.com/5220/5431220348_fbdf80ae9.jpg'])
16
+
17
+ Detect Faces with Raw image data:
18
+
19
+ >> client.faces_detect(:file => File.new('image.jpg', 'rb'))
20
+
21
+ With user auth:
22
+
23
+ >> client.twitter_credentials = { :twitter_username => 'twitter_screen_name', :twitter_password => 'twitter_password' }
24
+ >> client.faces_recognize(:urls => ['http://test.com/1.jpg'], :uids => ['uiicor']) # will make request with twitter credentials
25
+
26
+ More Documentation refer to http://developers.face.com/.
27
+
28
+ Author: Roc Yu (rociiu.yu@gmail.com), Haris Amin (aminharis7@gmail.com)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/face.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "face/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "macruby-face"
7
+ s.version = Face::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Roc Yu", "Haris Amin"]
10
+ s.email = ["rociiu.yu@gmail.com", "aminharis7@gmail.com"]
11
+ s.homepage = "http://rubygems.org/gems/face"
12
+ s.summary = %q{Ruby wraper of face.com api (MacRuby compliant)}
13
+ s.description = %q{}
14
+
15
+ s.rubyforge_project = "face"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "rest-client", ">=1.6.1"
23
+
24
+ end
data/lib/ext/hash.rb ADDED
@@ -0,0 +1,16 @@
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 to_param(namespace = nil)
11
+ collect do |key, value|
12
+ value.to_query(namespace ? "#{namespace}[#{key}]" : key)
13
+ end.sort * '&'
14
+ end
15
+
16
+ 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
+ module Face
2
+ module Client
3
+ module Accounts
4
+ def account_limits(opts={})
5
+ make_request(:tags_remove, opts.merge(user_auth_param))
6
+ end
7
+
8
+ def account_users(opts={})
9
+ make_request(:account_users, opts.merge(user_auth_param))
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path('../utils', __FILE__)
2
+ require File.expand_path('../recognition', __FILE__)
3
+ require File.expand_path('../tags', __FILE__)
4
+ require File.expand_path('../accounts', __FILE__)
5
+
6
+ module Face
7
+ module Client
8
+ class Base
9
+
10
+ attr_accessor :api_key, :api_secret
11
+
12
+ #{
13
+ # twitter_username => [twitter screen name]
14
+ # twitter_password => [twitter password]
15
+ #}
16
+ attr_accessor :twitter_credentials
17
+
18
+ #{
19
+ # twitter_oauth_user => [twitter OAuth user]
20
+ # twitter_oauth_secret => [twitter OAuth secret]
21
+ # twitter_oauth_token => [twitter OAuth token]
22
+ #}
23
+ attr_accessor :twitter_oauth_credentials
24
+
25
+ #{
26
+ # fb_user => [facebook user id]
27
+ # fb_session => [facebook session id]
28
+ # fb_oauth_token => [facebook oauth 2.0 access token]
29
+ #}
30
+ attr_accessor :facebook_credentials
31
+
32
+ include Face::Client::Utils
33
+ include Face::Client::Recognition
34
+ include Face::Client::Tags
35
+ include Face::Client::Accounts
36
+
37
+
38
+ def initialize(opts={})
39
+ opts.assert_valid_keys(:api_key, :api_secret)
40
+ @api_key, @api_secret = opts[:api_key], opts[:api_secret]
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,26 @@
1
+ module Face
2
+ module Client
3
+ module Recognition
4
+ # http://api.face.com/faces/detect.json
5
+ def faces_detect(opts={})
6
+ opts.assert_valid_keys(:urls, :file, :detector, :attributes, :callback, :callback_url)
7
+ make_request(:faces_detect, opts)
8
+ end
9
+
10
+ def faces_recognize(opts={})
11
+ opts.assert_valid_keys(:uids, :urls, :namespace, :detector, :attributes, :callback, :callback_url)
12
+ make_request(:faces_recognize, opts.merge(user_auth_param))
13
+ end
14
+
15
+ def faces_train(opts={})
16
+ opts.assert_valid_keys(:uids, :namespace, :callback, :callback_url)
17
+ make_request(:faces_train, opts.merge(user_auth_param))
18
+ end
19
+
20
+ def faces_status(opts={})
21
+ opts.assert_valid_keys(:uids, :namespace, :callback, :callback_url)
22
+ make_request(:faces_status, opts.merge(user_auth_param))
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ module Face
2
+ module Client
3
+ module Tags
4
+ def tags_get(opts={})
5
+ make_request(:tags_get, opts.merge(user_auth_param))
6
+ end
7
+
8
+ def tags_add(opts={})
9
+ make_request(:tags_add, opts.merge(user_auth_param))
10
+ end
11
+
12
+ def tags_save(opts={})
13
+ make_request(:tags_save, opts.merge(user_auth_param))
14
+ end
15
+
16
+ def tags_remove(opts={})
17
+ make_request(:tags_remove, opts.merge(user_auth_param))
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,61 @@
1
+ module Face
2
+ module Client
3
+ module Utils
4
+
5
+ class FaceError < StandardError; end
6
+
7
+ API_METHODS = {
8
+ :faces_detect => 'http://api.face.com/faces/detect.json',
9
+ :faces_recognize => 'http://api.face.com/faces/recognize.json',
10
+ :faces_train => 'http://api.face.com/faces/train.json',
11
+ :faces_status => 'http://api.face.com/faces/status.json',
12
+ :tags_get => 'http://api.face.com/tags/get.json',
13
+ :tags_add => 'http://api.face.com/tags/add.json',
14
+ :tags_save => 'http://api.face.com/tags/save.json',
15
+ :tags_remove => 'http://api.face.com/tags/remove.json',
16
+ :account_limits => 'http://api.face.com/account/limits.json',
17
+ :account_users => 'http://api.face.com/account/users.json'
18
+ }
19
+
20
+ def api_crendential
21
+ { :api_key => api_key, :api_secret => api_secret }
22
+ end
23
+
24
+ def make_request(api_method, opts={})
25
+ if opts[:urls].is_a? Array
26
+ opts[:urls] = opts[:urls].join(',')
27
+ end
28
+
29
+ if opts[:uids].is_a? Array
30
+ opts[:uids] = opts[:uids].join(',')
31
+ end
32
+ response = JSON.parse( RestClient.post(API_METHODS[ api_method ], opts.merge(api_crendential)).body )
33
+ if %w/success partial/.include?(response['status'])
34
+ response
35
+ elsif response['status'] == 'failure'
36
+ raise FaceError.new("Error: #{response['error_code']}, #{response['error_message']}")
37
+ end
38
+ end
39
+
40
+ def user_auth_param
41
+ user_auth_value = []
42
+ if twitter_credentials
43
+ twitter_credentials.each do |k, v|
44
+ user_auth_value << "#{k}:#{v}"
45
+ end
46
+ elsif twitter_oauth_credentials
47
+ twitter_oauth_credentials.each do |k,v|
48
+ user_auth_value << "#{k}:#{v}"
49
+ end
50
+ end
51
+ if facebook_credentials
52
+ facebook_credentials.each do |k, v|
53
+ user_auth_value << "#{k}:#{v}"
54
+ end
55
+ end
56
+ user_auth_value.size > 0 ? { :user_auth => user_auth_value.join(',') } : {}
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path('../../ext/hash', __FILE__)
2
+ require File.expand_path('../client/base', __FILE__)
3
+
4
+ module Face
5
+ module Client
6
+
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Face
2
+ VERSION = "0.0.6"
3
+ end
data/lib/face.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'rest_client'
3
+ require 'json'
4
+
5
+ require File.expand_path('../face/client', __FILE__)
6
+
7
+ module Face
8
+
9
+ def self.get_client(opts={})
10
+ Face::Client::Base.new(opts)
11
+ end
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: macruby-face
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Roc Yu
9
+ - Haris Amin
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-06-21 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rest-client
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 1.6.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: 1.6.1
31
+ description: ''
32
+ email:
33
+ - rociiu.yu@gmail.com
34
+ - aminharis7@gmail.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - .gitignore
40
+ - Gemfile
41
+ - LICENSE
42
+ - README.rdoc
43
+ - Rakefile
44
+ - face.gemspec
45
+ - lib/ext/hash.rb
46
+ - lib/ext/object.rb
47
+ - lib/face.rb
48
+ - lib/face/client.rb
49
+ - lib/face/client/accounts.rb
50
+ - lib/face/client/base.rb
51
+ - lib/face/client/recognition.rb
52
+ - lib/face/client/tags.rb
53
+ - lib/face/client/utils.rb
54
+ - lib/face/version.rb
55
+ homepage: http://rubygems.org/gems/face
56
+ licenses: []
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project: face
75
+ rubygems_version: 1.8.24
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Ruby wraper of face.com api (MacRuby compliant)
79
+ test_files: []