eyevision 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +52 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/eyevision.gemspec +29 -0
- data/lib/eyevision.rb +11 -0
- data/lib/eyevision/client.rb +82 -0
- data/lib/eyevision/version.rb +3 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 21a0c3a612ada521338711f3df8f5b6cd0ee63fb
|
4
|
+
data.tar.gz: 568a1d8f0193b1ac0e06fff3dbce69df6942edef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 816deebbe5e57923d5c33aa3b752d9f15589948311fe3d564409d6b873992fea6eb727d2857fa8cffadb2229c1256509c41b8a3515173cfca2b9ea1f4e1c9802
|
7
|
+
data.tar.gz: 4e4011a294035430a6198f38271c4e574fbcc12f24c0ff7b0cb457c4706953bdb76298f193a7d7bea7576c8016fd748182eaa32468dcecad98d254012dbb9011
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Eyevision
|
2
|
+
|
3
|
+
This gem is a client to EyeEm's Vision API. It provides functionality to analyze an imageand retrieve tags, captions and an aesthetic score.
|
4
|
+
|
5
|
+
The client handles request authentication and token refreshes.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'eyevision'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install eyevision
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Usage is fairly simple. You initialize the client with your API keys and then pass images by file, url or binary input:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'eyevision'
|
29
|
+
|
30
|
+
c = Eyevision::Client.new('CLIENT ID', 'CLIENT SECRET')
|
31
|
+
|
32
|
+
c.analyze(url: "https://cdn.eyeem.com/thumb/fa153872f1fb87d2c49f03da2e605cbdc343230d-1479466499934/1200/1200")
|
33
|
+
c.analyze(file: "image.jpg")
|
34
|
+
c.analyze(image: "binary")
|
35
|
+
```
|
36
|
+
|
37
|
+
By default it will retrieve tags, captions and aesthetic score but you can also request other combinations:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
c.analyze(image: "binary", features: ["TAGS", "AESTHETIC_SCORE"])
|
41
|
+
```
|
42
|
+
|
43
|
+
## Development
|
44
|
+
|
45
|
+
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.
|
46
|
+
|
47
|
+
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).
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tmacedo/eyevision.
|
52
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "eyevision"
|
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
data/eyevision.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'eyevision/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "eyevision"
|
8
|
+
spec.version = Eyevision::VERSION
|
9
|
+
spec.authors = ["Tiago Macedo"]
|
10
|
+
spec.email = ["tftfmacedo@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Ruby Client for the EyeEm Vision API"
|
13
|
+
spec.description = "Ruby Client for the EyeEm Vision API"
|
14
|
+
spec.homepage = "https://github.com/tmacedo/eyevision"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
26
|
+
spec.add_development_dependency "webmock", "~> 2.1.0"
|
27
|
+
|
28
|
+
spec.add_runtime_dependency "httparty", "~> 0.14.0"
|
29
|
+
end
|
data/lib/eyevision.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
module Eyevision
|
2
|
+
class Client
|
3
|
+
include HTTParty
|
4
|
+
|
5
|
+
BASE_URI = "https://vision-api.eyeem.com/v1"
|
6
|
+
base_uri BASE_URI
|
7
|
+
|
8
|
+
SUPPORTED_FEATURES = %w(TAGS CAPTIONS AESTHETIC_SCORE)
|
9
|
+
|
10
|
+
def initialize(client_id, client_secret)
|
11
|
+
@client_id = client_id
|
12
|
+
@client_secret = client_secret
|
13
|
+
end
|
14
|
+
|
15
|
+
def analyze(opts)
|
16
|
+
case
|
17
|
+
when opts[:file]
|
18
|
+
image = from_file(opts[:file])
|
19
|
+
when opts[:url]
|
20
|
+
image = from_url(opts[:url])
|
21
|
+
when opts[:image]
|
22
|
+
image = opts[:image]
|
23
|
+
else
|
24
|
+
raise "You need to supply an image, file or URL"
|
25
|
+
end
|
26
|
+
|
27
|
+
features = SUPPORTED_FEATURES & (opts[:features] || SUPPORTED_FEATURES)
|
28
|
+
|
29
|
+
resp = request('/analyze', body: body(image, features), headers: auth_headers, format: :json)
|
30
|
+
|
31
|
+
JSON.parse(resp.body)["responses"].first
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def request(url, options, retry_count=1)
|
37
|
+
resp = self.class.post(url, options)
|
38
|
+
|
39
|
+
puts url
|
40
|
+
puts resp.code
|
41
|
+
case resp.code
|
42
|
+
when 200
|
43
|
+
resp
|
44
|
+
when 401 # token refresh
|
45
|
+
if retry_count > 0
|
46
|
+
@token = nil
|
47
|
+
|
48
|
+
request(url, options.merge(headers: auth_headers), (retry_count - 1))
|
49
|
+
else
|
50
|
+
raise AuthenticationError, resp.body
|
51
|
+
end
|
52
|
+
else
|
53
|
+
raise ApiError, resp.body
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def encode(image)
|
58
|
+
Base64.strict_encode64(image)
|
59
|
+
end
|
60
|
+
|
61
|
+
def from_url(url)
|
62
|
+
encode(HTTParty.get(url).body)
|
63
|
+
end
|
64
|
+
|
65
|
+
def from_file(path)
|
66
|
+
encode(File.binread(path))
|
67
|
+
end
|
68
|
+
|
69
|
+
def body(image, features)
|
70
|
+
tasks = features.map{|f| {type: f}}
|
71
|
+
{requests: [{ tasks: tasks, image: { content: image }}]}.to_json
|
72
|
+
end
|
73
|
+
|
74
|
+
def auth_headers
|
75
|
+
{'Content-Type' => 'application/json', 'Authorization' => "Bearer #{token}"}
|
76
|
+
end
|
77
|
+
|
78
|
+
def token
|
79
|
+
@token ||= request('/token', {body: {clientId: @client_id, clientSecret: @client_secret}, headers: {'Content-Type' => 'application/x-www-form-urlencoded'}}, retry_count=0)['access_token']
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eyevision
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tiago Macedo
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-04 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.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.1.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.1.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: httparty
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.14.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.14.0
|
83
|
+
description: Ruby Client for the EyeEm Vision API
|
84
|
+
email:
|
85
|
+
- tftfmacedo@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- Gemfile
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- bin/console
|
96
|
+
- bin/setup
|
97
|
+
- eyevision.gemspec
|
98
|
+
- lib/eyevision.rb
|
99
|
+
- lib/eyevision/client.rb
|
100
|
+
- lib/eyevision/version.rb
|
101
|
+
homepage: https://github.com/tmacedo/eyevision
|
102
|
+
licenses: []
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.5.1
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: Ruby Client for the EyeEm Vision API
|
124
|
+
test_files: []
|