* Refactor iqdb response collection
This commit is contained in:
@@ -14,7 +14,7 @@ module Iqdb
|
||||
|
||||
def find_similar
|
||||
if Danbooru.config.iqdb_hostname_and_port
|
||||
@matches = Iqdb::Server.new(*Danbooru.config.iqdb_hostname_and_port).query(3, @download.file_path).matches
|
||||
@matches = Iqdb::Server.default.query(3, @download.file_path).matches
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,7 +2,8 @@ module Iqdb
|
||||
module Responses
|
||||
class Collection
|
||||
attr_reader :responses
|
||||
delegate :each, :empty?, :any?, :to => :matches
|
||||
include Enumerable
|
||||
delegate :<=>, :each, :to => :matches
|
||||
|
||||
def initialize(response_string)
|
||||
@responses = response_string.split(/\n/).map do |string|
|
||||
|
||||
@@ -49,15 +49,6 @@ module Iqdb
|
||||
end
|
||||
end
|
||||
|
||||
def similar(post_id, results, flags = FLAG_DISCARD_COMMON_COEFFS)
|
||||
request do
|
||||
hex_id = post_id.to_s(16)
|
||||
socket.puts "sim 0 #{flags} #{results} #{hex_id}"
|
||||
socket.puts "done"
|
||||
responses = Responses::Collection.new(socket.read)
|
||||
end
|
||||
end
|
||||
|
||||
def query(results, filename, flags = FLAG_DISCARD_COMMON_COEFFS)
|
||||
request do
|
||||
socket.puts "query 0 #{flags} #{results} #{filename}"
|
||||
|
||||
Reference in New Issue
Block a user