Class: Rubix

Inherits:
Object
  • Object
show all
Defined in:
lib/rubix.rb

Defined Under Namespace

Classes: AuthorizationError, JSONError, ParseError, ResponseError, ServerError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token, version = 'v1', domain = "http://api.rubix.io") ⇒ Rubix

Returns a new instance of Rubix.



14
15
16
17
18
19
20
21
22
23
# File 'lib/rubix.rb', line 14

def initialize(access_token, version = 'v1', domain="http://api.rubix.io")
  self.access_token = access_token
  self.version = version
  self.client = Faraday.new(url: domain) do |f|
    f.request :multipart
    f.request :url_encoded
    f.adapter :net_http
  end
  self.client.headers = {user_key: self.access_token}
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



12
13
14
# File 'lib/rubix.rb', line 12

def access_token
  @access_token
end

#clientObject

Returns the value of attribute client.



12
13
14
# File 'lib/rubix.rb', line 12

def client
  @client
end

#domainObject

Returns the value of attribute domain.



12
13
14
# File 'lib/rubix.rb', line 12

def domain
  @domain
end

#versionObject

Returns the value of attribute version.



12
13
14
# File 'lib/rubix.rb', line 12

def version
  @version
end

Instance Method Details

#add_pattern(data) ⇒ Object

data: File, remote_file_url: “example.com/path/to/image”, label: “uid”, category_name: “matching”



47
48
49
50
51
52
# File 'lib/rubix.rb', line 47

def add_pattern(data)
  error_handler do
    result = client.post("/api/#{version}/patterns", {pattern: data})
    process_reponse(result)
  end
end

#delete_pattern(pattern_id) ⇒ Object



39
40
41
42
43
44
# File 'lib/rubix.rb', line 39

def delete_pattern(pattern_id)
  error_handler do
    result = client.delete("/api/#{version}/patterns/#{pattern_id}")
    process_reponse(result)
  end
end

#feature_matching(data) ⇒ Object

data: File, remote_file_url: “example.com/path/to/scene”, mr: 0.9, mma: 150



55
56
57
58
59
60
# File 'lib/rubix.rb', line 55

def feature_matching(data)
  error_handler do
    result = client.post("/api/#{version}/patterns/feature_matcher", data)
    process_reponse(result)
  end
end

#list_categoriesObject



25
26
27
28
29
30
# File 'lib/rubix.rb', line 25

def list_categories
  error_handler do
    result = client.get("/api/#{version}/categories")
    process_reponse(result)
  end
end

#list_patterns(page = 1) ⇒ Object



32
33
34
35
36
37
# File 'lib/rubix.rb', line 32

def list_patterns(page = 1)
  error_handler do
    result = client.get("/api/#{version}/patterns", {page: page})
    process_reponse(result)
  end
end

#ocr(data) ⇒ Object

data: File, remote_file_url: “example.com/path/to/scene”, rectangles: [[x1,y1.x2,y2],..,]



63
64
65
66
67
68
# File 'lib/rubix.rb', line 63

def ocr(data)
  error_handler do
    result = client.post("/api/#{version}/patterns/ocr", data)
    process_reponse(result)
  end
end