mirador 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/mirador/version.rb +3 -0
- data/lib/mirador.rb +91 -0
- data/mirador.gemspec +21 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NTE2NmYxMWM5NmM4NWNmMmQ4NTIzZWRmNzEyZWRhMGI0YWNhZWY5Mg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MzA0NjY0MzQzYjQxZWQ3YjkzOTBiMmFkOGQ0ZjZiMjE5ZWVkYTc5YQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YzFjY2MyY2MwNzY2OWRlYTk3ZmYzZTZmZDBkOTE5Y2U4ZDJjOWRjMjAxZTRl
|
10
|
+
MzhiMzk4YWU3ZTBmYzQxNmM3YjJiYjA5ZjEzYzA3ODJmYWNmODMwY2U3Njg1
|
11
|
+
NmFjZDNkNDgwZWRmNDMwMTRhYjIzNTA0Zjg3NTI4MTcyZTZhNmQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZDgyMjFjODRlZDJlNjI0NTI2ODE4NDU5NzBhZGYzYWQ1ZjI1Y2ExOWI1ODkz
|
14
|
+
MDAyNWNjN2NlOGRiOGNkMmQ4OTU3NzdkYzE0NjNlMjliM2JlMzUwMDdhNTk1
|
15
|
+
Y2RmYjRhMTMxNzY3YjYxYjYxNWM1OWI5YzY2M2Y2MGQ5NTBlYmQ=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Nick Jacob
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Mirador
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'mirador'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install mirador
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/mirador.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
module Mirador
|
5
|
+
|
6
|
+
API_BASE = "http://api.mirador.im/v1/"
|
7
|
+
|
8
|
+
class Result
|
9
|
+
|
10
|
+
def initialize name, data
|
11
|
+
@name = name
|
12
|
+
|
13
|
+
@safe = data['safe']
|
14
|
+
@value = data['value']
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
"<Mirador::Result; name: #{ @name }; safe: #{ @safe }; value: #{ @value }/>"
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.parse_results reqs, results
|
22
|
+
|
23
|
+
if not results
|
24
|
+
return nil
|
25
|
+
end
|
26
|
+
|
27
|
+
results.each_with_index.map do |v, i|
|
28
|
+
Result.new(reqs[i], v['result'])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
class ApiError < StandardError
|
35
|
+
end
|
36
|
+
|
37
|
+
class Client
|
38
|
+
include HTTParty
|
39
|
+
base_uri 'api.mirador.im'
|
40
|
+
|
41
|
+
def initialize(api_key)
|
42
|
+
@options = { api_key: api_key }
|
43
|
+
end
|
44
|
+
|
45
|
+
def classify_urls urls
|
46
|
+
res = self.class.get(
|
47
|
+
"/v1/classify",
|
48
|
+
{
|
49
|
+
query: @options.merge({url: urls})
|
50
|
+
}
|
51
|
+
)
|
52
|
+
|
53
|
+
if res['errors']
|
54
|
+
raise ApiError, res['errors']
|
55
|
+
elsif not res
|
56
|
+
raise ApiError, "no response: #{ res.code }"
|
57
|
+
end
|
58
|
+
|
59
|
+
Result.parse_results urls, res['results']
|
60
|
+
end
|
61
|
+
|
62
|
+
def classify_files files
|
63
|
+
processed = files.map do |f| self.process_file(f) end
|
64
|
+
|
65
|
+
res = self.class.post(
|
66
|
+
"/v1/classify",
|
67
|
+
{
|
68
|
+
body: @options.merge({image: processed}),
|
69
|
+
headers: {'User-Agent' => 'Mirador Client v1.0/Ruby'},
|
70
|
+
}
|
71
|
+
)
|
72
|
+
|
73
|
+
if res['errors']
|
74
|
+
raise ApiError, res['errors']
|
75
|
+
end
|
76
|
+
|
77
|
+
if not res
|
78
|
+
raise ApiError, "no response", res.code
|
79
|
+
end
|
80
|
+
|
81
|
+
return Result.parse_results(files, res['results'])
|
82
|
+
end
|
83
|
+
|
84
|
+
def process_file file
|
85
|
+
data = File.read(file)
|
86
|
+
Base64.encode64(data).gsub("\n", '')
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
data/mirador.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mirador/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "mirador"
|
8
|
+
gem.version = Mirador::VERSION
|
9
|
+
gem.authors = ["Nick Jacob"]
|
10
|
+
gem.email = ["nick@mirador.im"]
|
11
|
+
gem.description = %q{Interface to the Mirador Image Moderation API}
|
12
|
+
gem.summary = %q{Simple interface to mirador API }
|
13
|
+
gem.homepage = "http://github.com/mirador-cv/mirador-rb"
|
14
|
+
gem.license = "MIT"
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
gem.add_runtime_dependency 'httparty', '~> 0.13.0', '>= 0.13.0'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mirador
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Jacob
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.13.0
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.13.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.13.0
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.13.0
|
33
|
+
description: Interface to the Mirador Image Moderation API
|
34
|
+
email:
|
35
|
+
- nick@mirador.im
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- .gitignore
|
41
|
+
- Gemfile
|
42
|
+
- LICENSE.txt
|
43
|
+
- README.md
|
44
|
+
- Rakefile
|
45
|
+
- lib/mirador.rb
|
46
|
+
- lib/mirador/version.rb
|
47
|
+
- mirador.gemspec
|
48
|
+
homepage: http://github.com/mirador-cv/mirador-rb
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
metadata: {}
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 2.3.0
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: Simple interface to mirador API
|
72
|
+
test_files: []
|
73
|
+
has_rdoc:
|