Class: CognitiveVision::AnalyzeImage
- Inherits:
-
Object
- Object
- CognitiveVision::AnalyzeImage
show all
- Defined in:
- lib/cognitive_vision/analyze_image.rb
Defined Under Namespace
Classes: InvalidImageSizeError, InvalidImageUrlError, UnknownError
Class Method Summary
collapse
Class Method Details
.analyze_image(image_url, types = [:faces]) ⇒ Object
10
11
12
13
14
15
16
17
18
|
# File 'lib/cognitive_vision/analyze_image.rb', line 10
def self.analyze_image(image_url, types = [:faces])
features = ImageFeatures.new(types)
body = { 'url' => image_url }
params = { 'visualFeatures' => features.features_string }
response = Connection.new.post('/analyze', params, body)
treat_errors(response) if response.code != 200
AnalyzeResponse.parse(response.body, features)
end
|
.treat_errors(response) ⇒ Object
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/cognitive_vision/analyze_image.rb', line 20
def self.treat_errors(response)
case response.body['code']
when 'InvalidImageSize'
raise(InvalidImageSizeError, response.body['message'])
when 'InvalidImageUrl'
raise(InvalidImageUrlError, response.body['message'])
else
raise(UnknownError, response.body['message'])
end
end
|