rubix-api 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +12 -0
- data/Gemfile.lock +36 -0
- data/LICENSE.txt +22 -0
- data/README.md +56 -0
- data/Rakefile +7 -0
- data/lib/{rubix/rubix.rb → rubix.rb} +3 -0
- data/rubix-api.gemspec +30 -0
- data/spec/lib/rubix_spec.rb +68 -0
- data/spec/spec_helper.rb +5 -0
- metadata +79 -5
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rubix-api (0.0.2)
|
5
|
+
faraday
|
6
|
+
json
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
diff-lcs (1.2.5)
|
12
|
+
fakeweb (1.3.0)
|
13
|
+
faraday (0.9.0)
|
14
|
+
multipart-post (>= 1.2, < 3)
|
15
|
+
json (1.8.1)
|
16
|
+
multipart-post (2.0.0)
|
17
|
+
rake (10.1.1)
|
18
|
+
rspec (2.14.1)
|
19
|
+
rspec-core (~> 2.14.0)
|
20
|
+
rspec-expectations (~> 2.14.0)
|
21
|
+
rspec-mocks (~> 2.14.0)
|
22
|
+
rspec-core (2.14.7)
|
23
|
+
rspec-expectations (2.14.5)
|
24
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
25
|
+
rspec-mocks (2.14.6)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
bundler (~> 1.3)
|
32
|
+
fakeweb
|
33
|
+
faraday
|
34
|
+
rake
|
35
|
+
rspec
|
36
|
+
rubix-api!
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Salvador
|
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,56 @@
|
|
1
|
+
# Rubix::Api
|
2
|
+
Ruby wrapper for Rubix api.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
gem 'rubix-api'
|
9
|
+
|
10
|
+
And then execute:
|
11
|
+
|
12
|
+
$ bundle
|
13
|
+
|
14
|
+
Or install it yourself as:
|
15
|
+
|
16
|
+
$ gem install rubix-api
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
First you need to require the gem and you initialize the client by instantiating the Rubix class. To do this you need your _access token_ and you can **optionally** specify _api version_ and _domain_.
|
21
|
+
|
22
|
+
require 'rubix-api'
|
23
|
+
|
24
|
+
client = Rubix.new(access_token, version, domain) # Version and domain are optional
|
25
|
+
|
26
|
+
To list categories.
|
27
|
+
client.list_categories
|
28
|
+
|
29
|
+
To list patterns you need to pass _page_number_ as the only parameter.
|
30
|
+
|
31
|
+
client.list_patterns(2) #where "2" means the page number
|
32
|
+
|
33
|
+
To delete patterns you need to pass the pattern_id as the only parameter.
|
34
|
+
|
35
|
+
client.delete_pattern(100) #where "100" means the pattern_id
|
36
|
+
|
37
|
+
To add a matching pattern you need to pass the _file_ itself or an _file url_ for it, a _label_, and the _category name_ to which the pattern belongs.
|
38
|
+
|
39
|
+
client.add_pattern({file: FIle, remote_file_url: "http://example.com/path/to/scene", label: 'uid', category_name: 'matching'})
|
40
|
+
|
41
|
+
To use feature matching, a file or file url is needed, as well as a minimum ratio and a minimum matches amount.
|
42
|
+
|
43
|
+
client.feature_matching({file, remote_file_url, mr: 0.9, mma: 150})
|
44
|
+
|
45
|
+
For OCR, Rubix needs the path to image or the file itself, and optionally, the area to be scanned.
|
46
|
+
|
47
|
+
client.ocr({file, remote_file_url, rectangles: [[x1,y1.x2,y2],..,[x1,y1,x2,y2]]}
|
48
|
+
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
1. Fork it
|
53
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
54
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
55
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
56
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/rubix-api.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
#require 'rubix/api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rubix-api"
|
8
|
+
spec.version = '0.0.2'
|
9
|
+
spec.authors = ["Yeti Media"]
|
10
|
+
spec.email = ["nicolas55ar@gmail.com"]
|
11
|
+
spec.description = "Wrapper for Rubix Api"
|
12
|
+
spec.summary = "Rubix gem"
|
13
|
+
spec.homepage = "http://github.com/Yeti-Media/rubix-ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($\)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'faraday'
|
22
|
+
spec.add_dependency 'json'
|
23
|
+
|
24
|
+
spec.add_runtime_dependency 'faraday'
|
25
|
+
spec.add_runtime_dependency 'json'
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
28
|
+
spec.add_development_dependency "rake"
|
29
|
+
spec.add_development_dependency "rspec"
|
30
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rubix do
|
4
|
+
before do
|
5
|
+
@access_token = 'access_token'
|
6
|
+
@version = 'v1'
|
7
|
+
@domain = 'http://api.rubix.io'
|
8
|
+
@client = Rubix.new(@access_token)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should list categories" do
|
12
|
+
json_response = [{"id"=>72, :title => 'matching'}]
|
13
|
+
FakeWeb.register_uri(:get, "#{@domain}/api/#{@version}/categories", body: json_response.to_json, status: 200,
|
14
|
+
user_key: @access_token)
|
15
|
+
response = @client.list_categories
|
16
|
+
response[0]['title'].should == 'matching'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should list patterns" do
|
20
|
+
json_response = [{"id"=>72, :label => 'BrandId'}]
|
21
|
+
FakeWeb.register_uri(:get, "#{@domain}/api/#{@version}/patterns?page=2", body: json_response.to_json, status: 200,
|
22
|
+
user_key: @access_token)
|
23
|
+
response = @client.list_patterns(2)
|
24
|
+
response[0]['label'].should == 'BrandId'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should delete a pattern" do
|
28
|
+
json_response = {"id"=>72, :label => 'BrandId'}
|
29
|
+
FakeWeb.register_uri(:delete, "#{@domain}/api/#{@version}/patterns/2", body: json_response.to_json, status: 200,
|
30
|
+
user_key: @access_token)
|
31
|
+
response = @client.delete_pattern(2)
|
32
|
+
response['id'].should == 72
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should initialize the client" do
|
36
|
+
@client.client.url_prefix.to_s.should == "#{@domain}/"
|
37
|
+
@client.access_token.should == @access_token
|
38
|
+
@client.version.should == @version
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should correctly add a pattern" do
|
42
|
+
file_url = "http://example.com/path/to/image.png"
|
43
|
+
label = 'uid'
|
44
|
+
category = 'matching'
|
45
|
+
json_response = {"id"=>72, "file"=>{"url"=>file_url}, "label"=>label, "category_id"=>2}
|
46
|
+
FakeWeb.register_uri(:post, "#{@domain}/api/#{@version}/patterns", body: json_response.to_json, status: 200,
|
47
|
+
user_key: @access_token)
|
48
|
+
response = @client.add_pattern(remote_file_url: file_url, label: label, category_name: category)
|
49
|
+
response['label'].should == label
|
50
|
+
response['file']['url'].should == file_url
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should correctly feature match" do
|
54
|
+
json_response = {"label"=>'image.png', "values"=>[{"center"=>{"x"=>165.933654785156, "y"=>261.701690673828}}, "label"=>"uid", "pattern_url"=>"/uploads/pattern/1/matching/image.png" ]}
|
55
|
+
FakeWeb.register_uri(:post, "#{@domain}/api/#{@version}/patterns/feature_matcher", body: json_response.to_json,
|
56
|
+
status: 200, user_key: @access_token)
|
57
|
+
response = @client.add_pattern(remote_file_url: "http://example.com/path/to/image.png", mr: 0.9, mma: 150)
|
58
|
+
response['label'].should == 'uid' # don't know why reponse['label'] is matching to the 'label' insde 'values'
|
59
|
+
end
|
60
|
+
|
61
|
+
# it "should correctly ocr" do
|
62
|
+
# #json_response = {"matches"=>[{"pattern"=>"xWpvxEx6tTo4GPxTGSTm1Qz99HD9AYPBiwrr", "percentage"=>95, "scene"=>"image", "pattern_url"=>"/uploads/pattern/1/comparison/imagexzcxxzc.png", "label"=>"yeti"}], "scenario_url"=>"image.png"}
|
63
|
+
# FakeWeb.register_uri(:post, "#{@domain}/api/#{@version}/patterns/ocr", body: json_response.to_json, status: 200)
|
64
|
+
# response = @client.add_pattern(remote_file_url: "http://example.com/path/to/image.png")
|
65
|
+
# response['text'].should == 'uid'
|
66
|
+
# end
|
67
|
+
|
68
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubix-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,72 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
12
|
+
date: 2014-04-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: faraday
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: json
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
14
78
|
- !ruby/object:Gem::Dependency
|
15
79
|
name: bundler
|
16
80
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,8 +130,16 @@ executables: []
|
|
66
130
|
extensions: []
|
67
131
|
extra_rdoc_files: []
|
68
132
|
files:
|
69
|
-
-
|
70
|
-
|
133
|
+
- Gemfile
|
134
|
+
- Gemfile.lock
|
135
|
+
- LICENSE.txt
|
136
|
+
- README.md
|
137
|
+
- Rakefile
|
138
|
+
- lib/rubix.rb
|
139
|
+
- rubix-api.gemspec
|
140
|
+
- spec/lib/rubix_spec.rb
|
141
|
+
- spec/spec_helper.rb
|
142
|
+
homepage: http://github.com/Yeti-Media/rubix-ruby
|
71
143
|
licenses:
|
72
144
|
- MIT
|
73
145
|
post_install_message:
|
@@ -92,4 +164,6 @@ rubygems_version: 1.8.23
|
|
92
164
|
signing_key:
|
93
165
|
specification_version: 3
|
94
166
|
summary: Rubix gem
|
95
|
-
test_files:
|
167
|
+
test_files:
|
168
|
+
- spec/lib/rubix_spec.rb
|
169
|
+
- spec/spec_helper.rb
|