Method: TwoCaptcha::Client#upload

Defined in:
lib/two_captcha/client.rb

#upload(options = {}) ⇒ TwoCaptcha::Captcha

Upload a captcha to 2Captcha.

This method will not return the solution. It helps on separating concerns.

Returns:



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/two_captcha/client.rb', line 86

def upload(options = {})
  args = {}
  args[:body]   = options[:raw64]
  args[:method] = 'base64'
  [:phrase, :regsense, :numeric, :calc, :min_len, :max_len, :language,
   :header_acao, :id_constructor].each do |key|
    args[key] = options[key] if options[key]
  end
  response = request('in', :multipart, args)

  unless response.match(/\AOK\|/)
    fail(TwoCaptcha::Error, 'Unexpected API Response')
  end

  TwoCaptcha::Captcha.new(
    id: response.split('|', 2)[1],
    api_response: response
  )
end