Class: Bubo
- Inherits:
-
Object
- Object
- Bubo
- Defined in:
- lib/bubo.rb
Class Method Summary collapse
-
.from_heroku ⇒ Object
Create a new Bubo API object.
Instance Method Summary collapse
-
#add_image(key, url) ⇒ Object
Add a new image to your searchable collection.
-
#api_verification ⇒ Object
Returns the email and api_key you specified when generating this object.
-
#failed_image_keys ⇒ Object
Retrieve an array of keys of images, which failed to import.
-
#host ⇒ Object
Returns the hostname of the currently used Bubo API provider.
-
#images_status ⇒ Object
Retrieve current system status.
-
#initialize(email, api_key, host = 'api.askbubo.com', port = 80) ⇒ Bubo
constructor
Create a new Bubo API object.
-
#inspect_image(key) ⇒ Object
Get the analysis status of an image in your collection.
-
#port ⇒ Object
Returns the port number of the currently used Bubo API provider.
-
#remove_image(key) ⇒ Object
Remove an image from your searchable collection.
-
#retrieve(url) ⇒ Object
Download the url given and search for matching images using an optical near-duplicate search algorithm.
Constructor Details
#initialize(email, api_key, host = 'api.askbubo.com', port = 80) ⇒ Bubo
Create a new Bubo API object.
You can freely generate API keys on api.askbubo.com/users/new
If you have any questions, mail Hajo Nils Krabbenhoeft.
23 24 25 |
# File 'lib/bubo.rb', line 23 def initialize(email, api_key, host='api.askbubo.com', port=80) @settings = { :email => email, :api_key => api_key, :host => host, :port => port } end |
Class Method Details
.from_heroku ⇒ Object
Create a new Bubo API object.
This version should be used with the heroku.com add-on. It will automatically read it’s configuration from ENV.
12 13 14 15 16 |
# File 'lib/bubo.rb', line 12 def self.from_heroku login_url = URI.parse(ENV["BUBO_LOGIN"]) userpass = login_url.query.split(":") Bubo.new(userpass[0], userpass[1], login_url.host, login_url.port) end |
Instance Method Details
#add_image(key, url) ⇒ Object
Add a new image to your searchable collection. Returns true or false
52 53 54 |
# File 'lib/bubo.rb', line 52 def add_image(key, url) send('images/add', {:key => key, :url => url}) == 'OK' end |
#api_verification ⇒ Object
Returns the email and api_key you specified when generating this object.
28 29 30 |
# File 'lib/bubo.rb', line 28 def api_verification { :email => @settings[:email], :api_key => @settings[:api_key] } end |
#failed_image_keys ⇒ Object
Retrieve an array of keys of images, which failed to import. Returns something like:
- “keyA”, “anotherKey”, “keyC”
78 79 80 |
# File 'lib/bubo.rb', line 78 def failed_image_keys send('images/failures').split("\n") end |
#host ⇒ Object
Returns the hostname of the currently used Bubo API provider.
33 34 35 |
# File 'lib/bubo.rb', line 33 def host @settings[:host] end |
#images_status ⇒ Object
Retrieve current system status. Return value will look like:
“OK”=>13, “TODO”=>0, “UPDATE”=>“IDLE”
46 47 48 |
# File 'lib/bubo.rb', line 46 def images_status JSON.parse( send('images') ) end |
#inspect_image(key) ⇒ Object
Get the analysis status of an image in your collection. Returns either:
“OKtNUMBER” where NUMBER is the number of feature points used for searching
or
“FAILtERROR MESSAGE”
70 71 72 |
# File 'lib/bubo.rb', line 70 def inspect_image(key) send('images/inspect', {:key => key}) end |
#port ⇒ Object
Returns the port number of the currently used Bubo API provider.
38 39 40 |
# File 'lib/bubo.rb', line 38 def port @settings[:port] end |
#remove_image(key) ⇒ Object
Remove an image from your searchable collection. Returns true or false
58 59 60 |
# File 'lib/bubo.rb', line 58 def remove_image(key) send('images/remove', {:key => key}) == 'OK' end |
#retrieve(url) ⇒ Object
Download the url given and search for matching images using an optical near-duplicate search algorithm. Returns an array of strings. Each member is either a comment line starting with # or a search result. Search result lines are formatted as:
“KEYtSCOREtMATRIX”
KEY is the key you specified when adding the image. SCORE is a confidence score from 0 to 1 with anything above 0.9 considered excellent. MATRIX is a 2x3 affine transformation matrix which can be used to transform the image specified by KEY as to cover the search image.
91 92 93 |
# File 'lib/bubo.rb', line 91 def retrieve(url) send('images/retrieve', {:url => url}).split("\n") end |