rubix-api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rubix/rubix.rb +92 -0
- metadata +95 -0
data/lib/rubix/rubix.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
class Rubix
|
2
|
+
|
3
|
+
class ResponseError < Exception ; end
|
4
|
+
class ServerError < Exception ; end
|
5
|
+
class AuthorizationError < Exception ; end
|
6
|
+
class ParseError < Exception ; end
|
7
|
+
class JSONError < Exception ; end
|
8
|
+
|
9
|
+
attr_accessor :client, :version, :access_token, :domain
|
10
|
+
|
11
|
+
def initialize(access_token, version = 'v1', domain="http://api.rubix.io")
|
12
|
+
self.access_token = access_token
|
13
|
+
self.version = version
|
14
|
+
self.client = Faraday.new(url: domain) do |f|
|
15
|
+
f.request :multipart
|
16
|
+
f.request :url_encoded
|
17
|
+
f.adapter :net_http
|
18
|
+
end
|
19
|
+
self.client.headers = {user_key: self.access_token}
|
20
|
+
end
|
21
|
+
|
22
|
+
def list_categories
|
23
|
+
error_handler do
|
24
|
+
result = client.get("/api/#{version}/categories")
|
25
|
+
process_reponse(result)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def list_patterns(page = 1)
|
30
|
+
error_handler do
|
31
|
+
result = client.get("/api/#{version}/patterns", {page: page})
|
32
|
+
process_reponse(result)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def delete_pattern(pattern_id)
|
37
|
+
error_handler do
|
38
|
+
result = client.delete("/api/#{version}/patterns/#{pattern_id}")
|
39
|
+
process_reponse(result)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
#data: {file: File, remote_file_url: "http://example.com/path/to/image", label: "uid", category_name: "matching"}
|
44
|
+
def add_pattern(data)
|
45
|
+
error_handler do
|
46
|
+
result = client.post("/api/#{version}/patterns", {pattern: data})
|
47
|
+
process_reponse(result)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
#data: {file: File, remote_file_url: "http://example.com/path/to/scene", mr: 0.9, mma: 150}
|
52
|
+
def feature_matching(data)
|
53
|
+
error_handler do
|
54
|
+
result = client.post("/api/#{version}/patterns/feature_matcher", data)
|
55
|
+
process_reponse(result)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
#data: {file: File, remote_file_url: "http://example.com/path/to/scene", rectangles: [[x1,y1.x2,y2],..,[x1,y1,x2,y2]]}
|
60
|
+
def ocr(data)
|
61
|
+
error_handler do
|
62
|
+
result = client.post("/api/#{version}/patterns/ocr", data)
|
63
|
+
process_reponse(result)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def error_handler
|
70
|
+
begin
|
71
|
+
yield
|
72
|
+
rescue JSON::ParserError => e
|
73
|
+
raise ParseError.new(e.message)
|
74
|
+
rescue JSON::JSONError => e
|
75
|
+
raise JSONError.new(e.message)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def process_reponse(response)
|
80
|
+
case response.status
|
81
|
+
when 200
|
82
|
+
JSON.parse(response.body)
|
83
|
+
when 401
|
84
|
+
raise AuthorizationError.new(JSON.parse(response.body)['error'])
|
85
|
+
when 422
|
86
|
+
raise ResponseError.new(JSON.parse(response.body)['error'])
|
87
|
+
when 500
|
88
|
+
raise ServerError.new
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubix-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Yeti Media
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-04-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
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: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
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
|
+
description: Wrapper for Rubix Api
|
63
|
+
email:
|
64
|
+
- nicolas55ar@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- lib/rubix/rubix.rb
|
70
|
+
homepage: ''
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 1.8.23
|
92
|
+
signing_key:
|
93
|
+
specification_version: 3
|
94
|
+
summary: Rubix gem
|
95
|
+
test_files: []
|