aliyun-facebody 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7a8537dd9824cc15b0e578ab9f1510ce33b4e50e1ff7f60afcba066c3c9dc371
4
+ data.tar.gz: 195d7d3412c96c5874349d3b585adfc9f18e2b8eb4d5da897a00925ea4384e76
5
+ SHA512:
6
+ metadata.gz: 6c189667705b8a429c93b29f5256e7f4c76b8692b9636253c26877d98ee7ecb78c846569528d80b5d2e0bb3512e2f259a9ddd518c4302df24fcb374fe66e0612
7
+ data.tar.gz: a456e78e7775146de0560f64e4b5465c52440816a1e0ad0c7a25efb9580e22021e15e294281171d22be987f4424e43680d490a8d9a7db948e2048e13a249dfa1
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-09-07
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at leepood@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in aliyun-facebody.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem "rubocop", "~> 1.21"
13
+
14
+ gem "faraday"
data/Gemfile.lock ADDED
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ aliyun-facebody (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ base64 (0.1.1)
11
+ faraday (2.7.4)
12
+ faraday-net_http (>= 2.0, < 3.1)
13
+ ruby2_keywords (>= 0.0.4)
14
+ faraday-net_http (3.0.2)
15
+ json (2.6.3)
16
+ language_server-protocol (3.17.0.3)
17
+ minitest (5.20.0)
18
+ parallel (1.23.0)
19
+ parser (3.2.2.3)
20
+ ast (~> 2.4.1)
21
+ racc
22
+ racc (1.7.1)
23
+ rainbow (3.1.1)
24
+ rake (13.0.6)
25
+ regexp_parser (2.8.1)
26
+ rexml (3.2.6)
27
+ rubocop (1.56.2)
28
+ base64 (~> 0.1.1)
29
+ json (~> 2.3)
30
+ language_server-protocol (>= 3.17.0)
31
+ parallel (~> 1.10)
32
+ parser (>= 3.2.2.3)
33
+ rainbow (>= 2.2.2, < 4.0)
34
+ regexp_parser (>= 1.8, < 3.0)
35
+ rexml (>= 3.2.5, < 4.0)
36
+ rubocop-ast (>= 1.28.1, < 2.0)
37
+ ruby-progressbar (~> 1.7)
38
+ unicode-display_width (>= 2.4.0, < 3.0)
39
+ rubocop-ast (1.29.0)
40
+ parser (>= 3.2.1.0)
41
+ ruby-progressbar (1.13.0)
42
+ ruby2_keywords (0.0.5)
43
+ unicode-display_width (2.4.2)
44
+
45
+ PLATFORMS
46
+ arm64-darwin-22
47
+
48
+ DEPENDENCIES
49
+ aliyun-facebody!
50
+ faraday
51
+ minitest (~> 5.0)
52
+ rake (~> 13.0)
53
+ rubocop (~> 1.21)
54
+
55
+ BUNDLED WITH
56
+ 2.4.12
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 leepood
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Aliyun::Facebody
2
+
3
+ 阿里云视觉API Ruby实现
4
+
5
+ ## Installation
6
+
7
+ `bundle install aliyun-facebody`
8
+
9
+ 或者在Gemfile中
10
+
11
+ gem 'aliyun-facebody'
12
+
13
+ ## Usage
14
+
15
+ ```ruby
16
+ Aliyun::Facebody.configure do |config|
17
+ config.access_key_secret = ENV.fetch("ALIYUN_ACCESS_KEY_SECRET")
18
+ config.access_key_id = ENV.fetch("ALIYUN_ACCESS_KEY_ID")
19
+ config.is_vpc = false # 如果同为阿里云服务器可以直接使用vpc节点加快访问速度
20
+ end
21
+
22
+ result = Aliyun::Facebody.detect_face(ENV.fetch("ALIYUN_FACE_TEST_URL"))
23
+
24
+ ```
25
+
26
+ 目前实现的接口有:
27
+
28
+ 1. `DetectFace` 人脸检测与五官定位
29
+
30
+
31
+
32
+ ## Development
33
+
34
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
35
+
36
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/leepood/aliyun-facebody. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/aliyun-facebody/blob/master/CODE_OF_CONDUCT.md).
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
45
+
46
+ ## Code of Conduct
47
+
48
+ Everyone interacting in the Aliyun::Facebody project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/aliyun-facebody/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/aliyun/facebody/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "aliyun-facebody"
7
+ spec.version = Aliyun::Facebody::VERSION
8
+ spec.authors = ["leepood"]
9
+ spec.email = ["leepood@gmail.com"]
10
+
11
+ spec.summary = "Ruby Implements For Aliyun FaceBody API"
12
+ spec.description = "Ruby Implements For Aliyun FaceBody API"
13
+ spec.homepage = "https://github.com/leepood/aliyun-facebody"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
21
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
28
+ end
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ # Uncomment to register a new dependency of your gem
35
+ # spec.add_dependency "example-gem", "~> 1.0"
36
+
37
+ # For more information and examples about making a new gem, check out our
38
+ # guide at: https://bundler.io/guides/creating_gem.html
39
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aliyun
4
+ module Facebody
5
+ VERSION = "1.0.0"
6
+ end
7
+ end
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "aliyun/facebody/version"
4
+ require "openssl"
5
+ require "base64"
6
+ require "faraday"
7
+ require "cgi/util"
8
+
9
+ module Aliyun
10
+
11
+ module Facebody
12
+
13
+ ENDPOINT = "https://facebody.cn-shanghai.aliyuncs.com"
14
+ ENDPOINT_VPC = "https://facebody-vpc.cn-shanghai.aliyuncs.com"
15
+
16
+ class Configuration
17
+ attr_accessor :access_key_secret, :access_key_id, :format, :region_id,
18
+ :signature_method, :signature_version, :version,
19
+ :is_vpc
20
+
21
+ def initialize
22
+ @access_key_secret = ""
23
+ @access_key_id = ""
24
+ @format = "JSON"
25
+ @region_id = "cn-shanghai"
26
+ @signature_version = "1.0"
27
+ @version = "2019-12-30"
28
+ @signature_method = "HMAC-SHA1"
29
+ @is_vpc = false
30
+ end
31
+ end
32
+
33
+ class << self
34
+ attr_writer :configuration
35
+ attr_reader :client
36
+
37
+ def configuration
38
+ @configuration ||= Configuration.new
39
+ end
40
+
41
+ def configure
42
+ yield(configuration) if block_given?
43
+ end
44
+
45
+ def detect_face(image_url, **options)
46
+ url = build_url({ Action: "DetectFace", ImageURL: image_url }.merge(options))
47
+ resp = http_client.post url
48
+ resp.body
49
+ end
50
+
51
+ private
52
+
53
+ def http_client
54
+ @client ||= Faraday.new(headers: { "Content-Type": "application/json" }) do |f|
55
+ f.response :json
56
+ end
57
+ end
58
+
59
+ def build_url(user_params)
60
+ params = {
61
+ "SignatureMethod" => configuration.signature_method,
62
+ "SignatureNonce" => seed_signature_nonce,
63
+ "AccessKeyId" => configuration.access_key_id,
64
+ "SignatureVersion" => configuration.signature_version,
65
+ "Timestamp" => seed_timestamp,
66
+ "Format" => configuration.format,
67
+ "RegionId" => configuration.region_id,
68
+ "Version" => configuration.version
69
+ }.merge(user_params)
70
+ coded_params = canonicalized_query_string(params)
71
+ key_secret = configuration.access_key_secret
72
+ "#{configuration.is_vpc ? ENDPOINT_VPC : ENDPOINT}/?Signature=#{sign(key_secret, coded_params)}&#{coded_params}"
73
+ end
74
+
75
+ def canonicalized_query_string(params)
76
+ params.sort_by { |key, _| key.to_s }
77
+ .map { |key, value| "#{encode(key)}=#{encode(value)}" }
78
+ .join("&")
79
+ end
80
+
81
+ # 生成数字签名
82
+ def sign(key_secret, coded_params)
83
+ key = "#{key_secret}&"
84
+ signature = "POST&#{encode("/")}&#{encode(coded_params)}"
85
+ sign = Base64.encode64(OpenSSL::HMAC.digest("sha1", key, signature).to_s)
86
+ encode(sign.chomp)
87
+ end
88
+
89
+ # 对字符串进行 PERCENT 编码
90
+ def encode(input)
91
+ CGI.escape(input.to_s).gsub("+", "%20")
92
+ .gsub("*", "%2A")
93
+ .gsub("~", "%7E")
94
+ end
95
+
96
+ # 生成短信时间戳
97
+ def seed_timestamp
98
+ Time.now.utc.strftime("%FT%TZ")
99
+ end
100
+
101
+ # 生成短信唯一标识码,采用到微秒的时间戳
102
+ def seed_signature_nonce
103
+ Time.now.utc.strftime("%Y%m%d%H%M%S%L")
104
+ end
105
+
106
+ end
107
+
108
+ end
109
+ end
@@ -0,0 +1,9 @@
1
+ module Aliyun
2
+ module Facebody
3
+ VERSION: String
4
+
5
+ private
6
+
7
+ def self.sign: -> string
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aliyun-facebody
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - leepood
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-09-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ruby Implements For Aliyun FaceBody API
14
+ email:
15
+ - leepood@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rubocop.yml"
21
+ - CHANGELOG.md
22
+ - CODE_OF_CONDUCT.md
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - aliyun-facebody.gemspec
29
+ - lib/aliyun/facebody.rb
30
+ - lib/aliyun/facebody/version.rb
31
+ - sig/aliyun/facebody.rbs
32
+ homepage: https://github.com/leepood/aliyun-facebody
33
+ licenses:
34
+ - MIT
35
+ metadata:
36
+ homepage_uri: https://github.com/leepood/aliyun-facebody
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 2.6.0
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubygems_version: 3.4.19
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: Ruby Implements For Aliyun FaceBody API
56
+ test_files: []