def perform(action, method = :get, payload = {})
      payload.merge!(username: self.username, password: self.password)

      headers = { 'User-Agent' => DeathByCaptcha::API_VERSION }

      if method == :post
        uri = URI("http://#{self.hostname}/api/#{action}")
        req = Net::HTTP::Post.new(uri.request_uri, headers)
        req.set_form_data(payload)

      elsif method == :post_multipart
        uri = URI("http://#{self.hostname}/api/#{action}")
        req = Net::HTTP::Post.new(uri.request_uri, headers)
        boundary, body = prepare_multipart_data(payload)
        req.content_type = "multipart/form-data; boundary=#{boundary}"
        req.body = body
      else
        uri = URI("http://#{self.hostname}/api/#{action}?#{URI.encode_www_form(payload)}")
        req = Net::HTTP::Get.new(uri.request_uri, headers)
      end

      res = Net::HTTP.start(uri.hostname, uri.port) do |http|
        http.request(req)
      end

      case res
      when Net::HTTPSuccess, Net::HTTPSeeOther
        Hash[URI.decode_www_form(res.body)]
      when Net::HTTPForbidden
        raise DeathByCaptcha::APIForbidden
      when Net::HTTPBadRequest
        raise DeathByCaptcha::APIBadRequest
      when Net::HTTPRequestEntityTooLarge
        raise DeathByCaptcha::APICaptchaTooLarge
      when Net::HTTPServiceUnavailable
        raise DeathByCaptcha::APIServiceUnavailable
      else
        raise DeathByCaptcha::APIResponseError.new(res.body)
      end
    end
def perform(action, method = :get, payload = {})
      payload.merge!(username: self.username, password: self.password)

      headers = { 'User-Agent' => DeathByCaptcha::API_VERSION }

      if method == :post
        uri = URI("http://#{self.hostname}/api/#{action}")
        req = Net::HTTP::Post.new(uri.request_uri, headers)
        req.set_form_data(payload)

      elsif method == :post_multipart
        uri = URI("http://#{self.hostname}/api/#{action}")
        req = Net::HTTP::Post.new(uri.request_uri, headers)
        boundary, body = prepare_multipart_data(payload)
        req.content_type = "multipart/form-data; boundary=#{boundary}"
        req.body = body
      else
        uri = URI("http://#{self.hostname}/api/#{action}?#{URI.encode_www_form(payload)}")
        req = Net::HTTP::Get.new(uri.request_uri, headers)
      end

      res = Net::HTTP.start(uri.hostname, uri.port) do |http|
        http.request(req)
      end

      case res
      when Net::HTTPSuccess, Net::HTTPSeeOther
        Hash[URI.decode_www_form(res.body)]
      when Net::HTTPForbidden
        raise DeathByCaptcha::APIForbidden
      when Net::HTTPBadRequest
        raise DeathByCaptcha::APIBadRequest
      when Net::HTTPRequestEntityTooLarge
        raise DeathByCaptcha::APICaptchaTooLarge
      when Net::HTTPServiceUnavailable
        raise DeathByCaptcha::APIServiceUnavailable
      else
        raise DeathByCaptcha::APIResponseError.new(res.body)
      end
    end
Perform an HTTP request to the DeathByCaptcha API.

 @param [String] action  API method name.
 @param [Symbol] method  HTTP method (:get, :post, :post_multipart).
 @param [Hash]   payload Data to be sent through the HTTP request.

 @return [Hash] Response from the DeathByCaptcha API.