ruboty-pux 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aca2f4a5e630a2c9b78619de2ac409163370afbd
4
+ data.tar.gz: defda5f6939335ff382e2ec65b20cfcf93bc24ca
5
+ SHA512:
6
+ metadata.gz: 28ad158ef22071a6cfadedcc94a5c7e18774c8f2911b0ca0ef59bbd84d49a5f0cbd354e889f2a8ad80851e76b4f1503ad000bf57a737812334abfa4615d925cc
7
+ data.tar.gz: 1e410ae298afe751cb43313aee3c4692b7090a9a1edbded60f773cab0381737632b8f12aaf7bb3ff278dbd6051a47e9dbc94065becfaecd0489a00936fdce6e6
@@ -0,0 +1,15 @@
1
+ .env
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-pux.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 yamasy1549
2
+
3
+ MIT License
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.
@@ -0,0 +1,16 @@
1
+ # Ruboty::Pux
2
+
3
+ Detect and judge the face of a photo.
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ gem 'ruboty-pux'
9
+ ```
10
+
11
+ ## ENV
12
+
13
+ ```
14
+ PUX_API_KEY - Request domain of PUX face-detection API
15
+ PUX_REQUEST_DOMAIN - Pass PUX API KEY
16
+ ```
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,79 @@
1
+ require 'mechanize'
2
+
3
+ module Ruboty
4
+ module Handlers
5
+ class Pux < Base
6
+ env :PUX_REQUEST_DOMAIN, 'Request domain of PUX face-detection API'
7
+ env :PUX_API_KEY, 'Pass PUX API KEY'
8
+
9
+ on(
10
+ /judge (?<query>.+)/,
11
+ description: 'Return judgement to 「judge <IMAGE_URL>」',
12
+ name: 'judge'
13
+ )
14
+
15
+ def judge(message)
16
+ ruboty_sorry = 'わかんない…'
17
+
18
+ p "POST #{request_url}"
19
+
20
+ response = agent.post(request_url, params(message))
21
+ face_recognition = JSON.parse(response.body)['results']['faceRecognition']
22
+
23
+ if face_recognition['errorInfo'].nil?
24
+ message.reply(ruboty_sorry)
25
+ else
26
+ face_info = face_recognition['detectionFaceInfo'][0]
27
+ gender_info = face_info['genderJudge']['genderResult']
28
+
29
+ age = face_info['ageJudge']['ageResult'] || ruboty_sorry
30
+ animal = face_info['enjoyJudge']['similarAnimal'] || ruboty_sorry
31
+ smile = face_info['smileJudge']['smileLevel'] || ruboty_sorry
32
+ doya = face_info['enjoyJudge']['doyaLevel'] || ruboty_sorry
33
+ trouble = face_info['enjoyJudge']['troubleLevel'] || ruboty_sorry
34
+
35
+ if gender_info.nil?
36
+ gender = ruboty_sorry
37
+ else
38
+ gender = gender_info == 0 ? "おとこのこ" : "おんなのこ"
39
+ end
40
+
41
+ result_message = ''
42
+ result_message << "ねんれい: #{age}さい"
43
+ result_message << "\nせいべつ: #{gender}"
44
+ result_message << "\nどうぶつ: #{animal}"
45
+ result_message << "\nえがお: #{smile}%"
46
+ result_message << "\nどやがお: #{doya}%"
47
+ result_message << "\nこまった: #{trouble}%"
48
+ end
49
+
50
+ message.reply(result_message)
51
+ rescue Exception => e
52
+ Ruboty.logger.error(%<Error: #{e.class}: #{e.message}\n#{e.backtrace.join("\n")}>)
53
+ message.reply(ruboty_sorry)
54
+ end
55
+
56
+ private
57
+
58
+ def request_url
59
+ if ENV['PUX_REQUEST_DOMAIN']
60
+ 'http://' + ENV['PUX_REQUEST_DOMAIN'] + ':8080/webapi/face.do'
61
+ end
62
+ end
63
+
64
+ def agent
65
+ @agent ||= Mechanize.new
66
+ end
67
+
68
+ def params(message)
69
+ {
70
+ apiKey: ENV['PUX_API_KEY'],
71
+ imageURL: message[:query],
72
+ enjoyJudge: 1,
73
+ response: 'json'
74
+ }
75
+ end
76
+ end
77
+ end
78
+ end
79
+
@@ -0,0 +1,2 @@
1
+ require "ruboty/handlers/pux"
2
+ require "ruboty/pux/version"
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Pux
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruboty/pux/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruboty-pux"
8
+ spec.version = Ruboty::Pux::VERSION
9
+ spec.authors = ["yamasy1549"]
10
+ spec.email = ["sanae@yamasy.info"]
11
+ spec.summary = "Detect and judge the face of a photo."
12
+ spec.homepage = "https://github.com/yamasy1549/ruboty-pux"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "mechanize", ">=2.7.3"
21
+ spec.add_dependency "ruboty", ">= 1.1.0"
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-pux
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - yamasy1549
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mechanize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.7.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.7.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruboty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description:
70
+ email:
71
+ - sanae@yamasy.info
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/ruboty/handlers/pux.rb
82
+ - lib/ruboty/pux.rb
83
+ - lib/ruboty/pux/version.rb
84
+ - ruboty-pux.gemspec
85
+ homepage: https://github.com/yamasy1549/ruboty-pux
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.4.8
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Detect and judge the face of a photo.
109
+ test_files: []
110
+ has_rdoc: