Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions lib/api_2captcha/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def initialize(api_key, soft_id = 0, callback = nil)
@domain = DEFAULT_DOMAIN
end

def solve(method, params = {}, file_path = nil, return_id: false)
def solve(method, file_path = nil, return_id: false, **params)
params = params.transform_keys(&:to_s)
params["method"] = method
params["key"] = @api_key
params["soft_id"] = @soft_id
Expand Down Expand Up @@ -70,7 +71,8 @@ def get_result(captcha_id)
when Net::HTTPSuccess
response_json = JSON.parse(response.body)
if response_json["status"] == 1
return response_json["request"]
response_json["captcha_id"] = captcha_id
return response_json
elsif response_json["request"] == "CAPCHA_NOT_READY"
sleep(polling_interval)
else
Expand Down Expand Up @@ -169,12 +171,12 @@ def amazon_waf(params)
end

def audio(params)
audio = params.delete(:audio)
audio = params.delete("audio")
audio_content = File.file?(audio) ? File.binread(audio) : audio

params = params.merge(
"body" => Base64.strict_encode64(audio_content),
"lang" => params[:lang]
"lang" => params["lang"]
)
solve("audio", params)
end
Expand All @@ -198,12 +200,12 @@ def send_request(params)
end

def get_params(params)
params[:image].nil? ? params : file_params(params)
params["image"].nil? ? params : file_params(params)
end

def file_params(params)
image = params.delete(:image)
hint_image = params.delete(:hint_image)
image = params.delete("image")
hint_image = params.delete("hint_image")

image_content = get_image_content(image)
hint_image_content = get_image_content(hint_image) if hint_image
Expand Down