moduleTyphoeusclassEasyattr_reader:response_body,:response_header,:method,:headers,:urlattr_accessor:start_timeCURLINFO_STRING=1048576OPTION_VALUES={:CURLOPT_URL=>10002,:CURLOPT_HTTPGET=>80,:CURLOPT_HTTPPOST=>10024,:CURLOPT_UPLOAD=>46,:CURLOPT_CUSTOMREQUEST=>10036,:CURLOPT_POSTFIELDS=>10015,:CURLOPT_POSTFIELDSIZE=>60,:CURLOPT_USERAGENT=>10018,:CURLOPT_TIMEOUT_MS=>155,:CURLOPT_NOSIGNAL=>99,:CURLOPT_HTTPHEADER=>10023,:CURLOPT_FOLLOWLOCATION=>52,:CURLOPT_MAXREDIRS=>68,:CURLOPT_HTTPAUTH=>107,:CURLOPT_USERPWD=>10000+5,:CURLOPT_VERBOSE=>41}INFO_VALUES={:CURLINFO_RESPONSE_CODE=>2097154,:CURLINFO_TOTAL_TIME=>3145731,:CURLINFO_HTTPAUTH_AVAIL=>0x200000+23}AUTH_TYPES={:CURLAUTH_BASIC=>1,:CURLAUTH_DIGEST=>2,:CURLAUTH_GSSNEGOTIATE=>4,:CURLAUTH_NTLM=>8,:CURLAUTH_DIGEST_IE=>16}definitialize@method=:get@post_dat_set=nil@headers={}enddefheaders=(hash)@headers=hashenddefauth=(authinfo)set_option(OPTION_VALUES[:CURLOPT_USERPWD],"#{authinfo[:username]}:#{authinfo[:password]}")set_option(OPTION_VALUES[:CURLOPT_HTTPAUTH],authinfo[:method])ifauthinfo[:method]enddefauth_methodsget_info_long(INFO_VALUES[:CURLINFO_HTTPAUTH_AVAIL])enddefverbose=(boolean)set_option(OPTION_VALUES[:CURLOPT_VERBOSE],!!boolean?1:0)enddeftotal_time_takenget_info_double(INFO_VALUES[:CURLINFO_TOTAL_TIME])enddefresponse_codeget_info_long(INFO_VALUES[:CURLINFO_RESPONSE_CODE])enddeffollow_location=(boolean)ifbooleanset_option(OPTION_VALUES[:CURLOPT_FOLLOWLOCATION],1)elseset_option(OPTION_VALUES[:CURLOPT_FOLLOWLOCATION],0)endenddefmax_redirects=(redirects)set_option(OPTION_VALUES[:CURLOPT_MAXREDIRS],redirects)enddeftimeout=(milliseconds)@timeout=millisecondsset_option(OPTION_VALUES[:CURLOPT_NOSIGNAL],1)set_option(OPTION_VALUES[:CURLOPT_TIMEOUT_MS],milliseconds)enddeftimed_out?@timeout&&total_time_taken>@timeout&&response_code==0enddefrequest_body=(request_body)@request_body=request_bodyif@method==:puteasy_set_request_body(@request_body)headers["Transfer-Encoding"]=""headers["Expect"]=""elseself.post_data=request_bodyendenddefuser_agent=(user_agent)set_option(OPTION_VALUES[:CURLOPT_USERAGENT],user_agent)enddefurl=(url)@url=urlset_option(OPTION_VALUES[:CURLOPT_URL],url)enddefmethod=(method)@method=methodifmethod==:getset_option(OPTION_VALUES[:CURLOPT_HTTPGET],1)elsifmethod==:postset_option(OPTION_VALUES[:CURLOPT_HTTPPOST],1)self.post_data=""elsifmethod==:putset_option(OPTION_VALUES[:CURLOPT_UPLOAD],1)self.request_body=""unless@request_bodyelseset_option(OPTION_VALUES[:CURLOPT_CUSTOMREQUEST],"DELETE")endenddefpost_data=(data)@post_data_set=trueset_option(OPTION_VALUES[:CURLOPT_POSTFIELDS],data)set_option(OPTION_VALUES[:CURLOPT_POSTFIELDSIZE],data.length)enddefparams=(params)params_string=params.keys.collectdo|k|value=params[k]ifvalue.is_a?Hashvalue.keys.collect{|sk|Rack::Utils.escape("#{k}[#{sk}]")+"="+Rack::Utils.escape(value[sk].to_s)}elsifvalue.is_a?Arraykey=Rack::Utils.escape(k.to_s)value.collect{|v|"#{key}=#{Rack::Utils.escape(v.to_s)}"}.join('&')else"#{Rack::Utils.escape(k.to_s)}=#{Rack::Utils.escape(params[k].to_s)}"endend.flatten.join("&")ifmethod==:postself.post_data=params_stringelseself.url="#{url}?#{params_string}"endenddefset_option(option,value)ifvalue.class==Stringeasy_setopt_string(option,value)elseeasy_setopt_long(option,value)endenddefperformset_headers()easy_perform()response_code()enddefset_headersheaders.each_pairdo|key,value|easy_add_header("#{key}: #{value}")endeasy_set_headers()unlessheaders.empty?end# gets called when finished and response code is 200-299defsuccess@success.call(self)if@successenddefon_success(&block)@success=blockenddefon_success=(block)@success=blockend# gets called when finished and response code is 300-599deffailure@failure.call(self)if@failureenddefon_failure(&block)@failure=blockenddefon_failure=(block)@failure=blockenddefretries@retries||=0enddefincrement_retries@retries||=0@retries+=1enddefmax_retries@max_retries||=40enddefmax_retries?retries>=max_retriesenddefreset@retries=0@response_code=0@response_header=""@response_body=""easy_reset()enddefget_info_string(option)easy_getinfo_string(option)enddefget_info_long(option)easy_getinfo_long(option)enddefget_info_double(option)easy_getinfo_double(option)enddefcurl_versionversionendendend