cognitive_vision 0.2.1 → 0.3.0
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.
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDI3ZDdhODY3MDVmNTY0ZmU0Zjc3OGQ2N2Y0NGU2ZmViZDZkOTFjMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGUzMjVhODc0YzY1YjNhYjc4YmNmMmI1ZGQ0ZDZhOTUwYjk1MjAwMA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OGFmMzFmMDVjMjkyYTE2MjcwZjdmMWY0OWI5NmYyODU4Y2JkYzEyOTA0YjU3
|
10
|
+
YjljOWQ2ODg5N2RmYjE1OWQ3OWJiZTU2YTkzYjY4OWMyZGI5MWI1ZTFlODdh
|
11
|
+
Mjc5NmQ3YTg3MmM0NDkyYWU0NTc1NjBjMzk4Mzk1MzVmZDQwOWE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzdmYzFkNGYzYjVlMzRiZGQ5ZmI2OTVjMTQwZmQzYTJlNTYxNGNkMjM4MjAx
|
14
|
+
OWU5ZDdjN2UwZDliN2MyZDk3ZDMwNjQ1MDE5MWUwMzI2YTgyZDZiZTU5ZDY1
|
15
|
+
NWM0YTgyZjE4ZjIxYzEwNTkzZjM2NWY0ZDdlNGQ2ZWY2ZmE5OTY=
|
data/lib/cognitive_vision.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'cognitive_vision/version'
|
2
2
|
require 'cognitive_vision/configuration'
|
3
3
|
require 'cognitive_vision/connection'
|
4
|
+
require 'cognitive_vision/adult'
|
4
5
|
require 'cognitive_vision/face'
|
5
6
|
require 'cognitive_vision/analyze_response'
|
6
7
|
require 'cognitive_vision/analyze_image'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module CognitiveVision
|
2
|
+
class Adult
|
3
|
+
attr_reader :adult_score, :racy_score
|
4
|
+
|
5
|
+
def initialize(options = {})
|
6
|
+
@adult_content = options.fetch(:adult_content)
|
7
|
+
@adult_score = options.fetch(:adult_score)
|
8
|
+
@racy_content = options.fetch(:racy_content)
|
9
|
+
@racy_score = options.fetch(:racy_score)
|
10
|
+
end
|
11
|
+
|
12
|
+
def adult_content?
|
13
|
+
@adult_content
|
14
|
+
end
|
15
|
+
|
16
|
+
def racy_content?
|
17
|
+
@racy_content
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -7,9 +7,10 @@ module CognitiveVision
|
|
7
7
|
class InvalidImageUrlError < StandardError; end
|
8
8
|
class UnknownError < StandardError; end
|
9
9
|
|
10
|
-
def self.analyze_image(image_url)
|
10
|
+
def self.analyze_image(image_url, types = [:faces])
|
11
|
+
types = [types] unless types.is_a?(Array)
|
11
12
|
body = { 'url' => image_url }
|
12
|
-
params = { 'visualFeatures' => '
|
13
|
+
params = { 'visualFeatures' => types.join(',') }
|
13
14
|
response = Connection.new.post('/analyze', params, body)
|
14
15
|
|
15
16
|
treat_errors(response) if response.code != 200
|
@@ -1,14 +1,21 @@
|
|
1
1
|
module CognitiveVision
|
2
2
|
class AnalyzeResponse
|
3
|
-
attr_reader :faces
|
3
|
+
attr_reader :adult, :faces
|
4
4
|
|
5
5
|
def initialize(options = {})
|
6
|
+
@adult = options.fetch(:adult, {})
|
6
7
|
@faces = options.fetch(:faces, [])
|
7
8
|
end
|
8
9
|
|
9
10
|
def self.parse(response_hash)
|
10
|
-
faces = response_hash['faces'].map { |face| Face.new(gender: face['gender'], age: face['age']) }
|
11
|
-
|
11
|
+
faces = (response_hash['faces'] || []).map { |face| Face.new(gender: face['gender'], age: face['age']) }
|
12
|
+
adult = if response_hash['adult']
|
13
|
+
adult_response = response_hash['adult']
|
14
|
+
Adult.new(adult_content: adult_response['isAdultContent'],
|
15
|
+
racy_content: adult_response['isRacyContent'], adult_score: adult_response['adultScore'],
|
16
|
+
racy_score: adult_response['racyScore'])
|
17
|
+
end
|
18
|
+
new(faces: faces, adult: adult)
|
12
19
|
end
|
13
20
|
end
|
14
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cognitive_vision
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Ribeiro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -170,6 +170,7 @@ files:
|
|
170
170
|
- bin/setup
|
171
171
|
- cognitive_vision.gemspec
|
172
172
|
- lib/cognitive_vision.rb
|
173
|
+
- lib/cognitive_vision/adult.rb
|
173
174
|
- lib/cognitive_vision/analyze_image.rb
|
174
175
|
- lib/cognitive_vision/analyze_response.rb
|
175
176
|
- lib/cognitive_vision/configuration.rb
|