cognitive_vision 0.1.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
+ SHA1:
3
+ metadata.gz: 256eb40f75f611d365e674c7cf7d800b9f6224df
4
+ data.tar.gz: e2998ad93f1cec636b384c7c0920c60edddccb6a
5
+ SHA512:
6
+ metadata.gz: 5dce377700abe323afc88b22eac686456bf777410bf6341464f896b4a55de4821b7476fc5553b100c750e94c51a6d955019a8628d072ae963fb5422faf42ec78
7
+ data.tar.gz: a5fc6f97beaad505095dab8745f732f3216f72388b082789f0f9ffc77a08cf32202040cfec2eb7acc37449f2f45689d002d1abb7be5d19032208ebcc0e1fd3e2
data/.env.sample ADDED
@@ -0,0 +1 @@
1
+ VISION_API_KEY=MYCOGNITIVEVISIONAPIKEY
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .env
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ Metrics/LineLength:
2
+ Max: 120
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.0.0
5
+ - 2.1.10
6
+ - 2.2.5
7
+ - 2.3.1
8
+ before_install: gem install bundler -v 1.12.4
9
+
10
+ addons:
11
+ code_climate:
12
+ secure: "TyyZWLEFr9D5qLdImL12YBIDN8vOAnPcG1Hg2lgtfoPEQUK4HbF97IHcbQ/c1GYK1BlXWuIdX2BqFI386/z7hCpVEeJBFE0FeTPmEYn3Rg8aehoioyAsvo8euN8nxm8iM+/McYzVdKSPuWmM2TJAAFrqpZOZDTsANx51z3Q4jgunVfNxqZTF5c+8wLs4ELodZixrwZz0sEpjpbW49PQ8O4XbZqXhhfN5J8RXj1JKeQZSupnipqQXsCNSthv8tmWaedeXBwmfxqFtQYNZ6JwoBWOpPu3fitH2I8KU18OAhrrdZYD02JEjkTyxReR25s5w+OVFwlDtU3aHqDOtAaOa29wprz3zHT2o/e7lhRuUGmXK4X15UwJ7wUAIvmAjBGFAEojm0gQQdYWuZYD5ExP94lu6T659yKX5SQJZrTp73pJ5ltZUx5WWgP2x8z/9jV/j+AzM/wF25GY5WxjeMqq190z5fvc2Lq92YOcH+yZ8/n9troz+/l5UXaXvzX5s1e4lBfIoxZPH2u7yyvN6AXCfclZzPEByccizfFTSzjIUm7vsP0iAttBOcE5Q4iIiiHCqDAuGbYumg6oD/roq16PJ2uF/vY9XPr5Iefhwk5UEU/f16/KYfz1i3hsR+CGhaiulLeDeSx8b3cxlOO38KiTdXAtHeCvRV58pT4Dkx6RFBGY="
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cognitive_vision.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Carlos Ribeiro
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,44 @@
1
+ # CognitiveVision
2
+ [![Build Status](https://travis-ci.org/mattr-co/cognitive_vision.svg?branch=master)](https://travis-ci.org/mattr-co/cognitive_vision)
3
+ [![Code Climate](https://codeclimate.com/github/mattr-co/cognitive_vision/badges/gpa.svg)](https://codeclimate.com/github/mattr-co/cognitive_vision)
4
+ [![Test Coverage](https://codeclimate.com/github/mattr-co/cognitive_vision/badges/coverage.svg)](https://codeclimate.com/github/mattr-co/cognitive_vision/coverage)
5
+
6
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cognitive_vision`. To experiment with that code, run `bin/console` for an interactive prompt.
7
+
8
+ TODO: Delete this and the text above, and describe your gem
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'cognitive_vision'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install cognitive_vision
25
+
26
+ ## Usage
27
+
28
+ TODO: Write usage instructions here
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
33
+
34
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mattr-co/cognitive_vision.
39
+
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
44
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'cognitive_vision'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+ cp .env.sample .env
6
+
7
+ bundle install
8
+
9
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cognitive_vision/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'cognitive_vision'
8
+ spec.version = CognitiveVision::VERSION
9
+ spec.authors = ['Carlos Ribeiro']
10
+ spec.email = ['mail@carlosribeiro.me']
11
+
12
+ spec.summary = 'Client to integrate with Microsoft Cognitive - Computer Vision API'
13
+ spec.description = 'Client to integrate with Microsoft Cognitive - Computer Vision API'
14
+ spec.homepage = 'https://github.com/mattr/cognitive_vision'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
20
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.12'
26
+ spec.add_development_dependency 'codeclimate-test-reporter'
27
+ spec.add_development_dependency 'dotenv', '~> 2.1.1'
28
+ spec.add_development_dependency 'pry'
29
+ spec.add_development_dependency 'pry-nav'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rspec', '~> 3.0'
32
+ spec.add_development_dependency 'simplecov'
33
+ spec.add_development_dependency 'webmock', '~> 2.1.0'
34
+ spec.add_development_dependency 'vcr', '~> 3.0.3'
35
+ end
@@ -0,0 +1,16 @@
1
+ require 'cognitive_vision/version'
2
+ require 'cognitive_vision/configuration'
3
+ require 'cognitive_vision/connection'
4
+ require 'cognitive_vision/face'
5
+ require 'cognitive_vision/analyze_response'
6
+ require 'cognitive_vision/analyze_image'
7
+
8
+ module CognitiveVision
9
+ def self.configuration
10
+ @configuration ||= Configuration.new
11
+ end
12
+
13
+ def self.configure
14
+ yield(configuration)
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ require 'json'
2
+ require 'net/http'
3
+
4
+ module CognitiveVision
5
+ class AnalyzeImage
6
+ def self.analyze_image(image_url)
7
+ body = { 'url' => image_url }
8
+ params = { 'visualFeatures' => 'Faces' }
9
+ response = Connection.new.post('/analyze', params, body)
10
+
11
+ AnalyzeResponse.parse(response.body)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module CognitiveVision
2
+ class AnalyzeResponse
3
+ attr_reader :faces
4
+
5
+ def initialize(options = {})
6
+ @faces = options.fetch(:faces, [])
7
+ end
8
+
9
+ def self.parse(response_hash)
10
+ faces = response_hash['faces'].map { |face| Face.new(gender: face['gender'], age: face['age']) }
11
+ new(faces: faces)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module CognitiveVision
2
+ class Configuration
3
+ attr_accessor :key
4
+ end
5
+ end
@@ -0,0 +1,38 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+
4
+ module CognitiveVision
5
+ class Connection
6
+ ENDPOINT = 'https://api.projectoxford.ai/vision/v1.0/'.freeze
7
+
8
+ def initialize
9
+ @uri = URI(ENDPOINT)
10
+ @http = Net::HTTP.new(@uri.host, @uri.port)
11
+ @http.use_ssl = @uri.scheme == 'https'
12
+ end
13
+
14
+ def post(path, params, body)
15
+ uri = prepare_uri(path, params)
16
+ request = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json')
17
+ request['Ocp-Apim-Subscription-Key'] = CognitiveVision.configuration.key
18
+ request.body = body.to_json
19
+ request_json(request)
20
+ end
21
+
22
+ private
23
+
24
+ def prepare_uri(path, query_params)
25
+ uri = @uri.dup
26
+ uri.path += path
27
+ uri.query = URI.encode_www_form(query_params)
28
+ uri
29
+ end
30
+
31
+ def request_json(request)
32
+ response = @http.request(request)
33
+ body = JSON.parse(response.body)
34
+
35
+ OpenStruct.new(code: response.code, body: body)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,10 @@
1
+ module CognitiveVision
2
+ class Face
3
+ attr_reader :age, :gender
4
+
5
+ def initialize(options = {})
6
+ @age = options.fetch(:age)
7
+ @gender = options.fetch(:gender)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module CognitiveVision
2
+ VERSION = '0.1.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,203 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cognitive_vision
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Carlos Ribeiro
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: codeclimate-test-reporter
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dotenv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.1.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.1.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-nav
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 2.1.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 2.1.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: vcr
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 3.0.3
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 3.0.3
153
+ description: Client to integrate with Microsoft Cognitive - Computer Vision API
154
+ email:
155
+ - mail@carlosribeiro.me
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".env.sample"
161
+ - ".gitignore"
162
+ - ".rspec"
163
+ - ".rubocop.yml"
164
+ - ".travis.yml"
165
+ - Gemfile
166
+ - LICENSE.txt
167
+ - README.md
168
+ - Rakefile
169
+ - bin/console
170
+ - bin/setup
171
+ - cognitive_vision.gemspec
172
+ - lib/cognitive_vision.rb
173
+ - lib/cognitive_vision/analyze_image.rb
174
+ - lib/cognitive_vision/analyze_response.rb
175
+ - lib/cognitive_vision/configuration.rb
176
+ - lib/cognitive_vision/connection.rb
177
+ - lib/cognitive_vision/face.rb
178
+ - lib/cognitive_vision/version.rb
179
+ homepage: https://github.com/mattr/cognitive_vision
180
+ licenses:
181
+ - MIT
182
+ metadata: {}
183
+ post_install_message:
184
+ rdoc_options: []
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ requirements: []
198
+ rubyforge_project:
199
+ rubygems_version: 2.4.6
200
+ signing_key:
201
+ specification_version: 4
202
+ summary: Client to integrate with Microsoft Cognitive - Computer Vision API
203
+ test_files: []