Class: UrlVerifier::RunCurler
- Inherits:
-
Object
- Object
- UrlVerifier::RunCurler
- Defined in:
- lib/url_verifier/run_curler.rb
Instance Method Summary collapse
- #check_for_redirect(url_hash) ⇒ Object
- #evaluate_curl_err(curl_err) ⇒ Object
- #evaluate_formatted_url(url_hash) ⇒ Object
-
#initialize(args = {}) ⇒ RunCurler
constructor
A new instance of RunCurler.
- #merge_url_hash(url_hash) ⇒ Object
- #process_valid_curl_response(url_hash, curl_result) ⇒ Object
- #send_to_curl(url_hash) ⇒ Object
- #verify_url(url) ⇒ Object
- #verify_urls(urls = []) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ RunCurler
Returns a new instance of RunCurler.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/url_verifier/run_curler.rb', line 5 def initialize(args={}) @timeout_limit = args.fetch(:timeout_limit, 60) @web_formatter = CrmFormatter::Web.new @curler = UrlVerifier::Curler.new # @dj_on = false # @dj_count_limit = 0 # @dj_workers = 3 # @obj_in_grp = 10 # @dj_refresh_interval = 10 # @cut_off = 10.days.ago # @current_process = "VerUrl" # @url_hash = {} end |
Instance Method Details
#check_for_redirect(url_hash) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/url_verifier/run_curler.rb', line 56 def check_for_redirect(url_hash) ver = url_hash[:verified_url] form = url_hash[:url_f] url_hash[:url_redirected] = ver.present? && ver != form url_hash end |
#evaluate_curl_err(curl_err) ⇒ Object
76 77 78 |
# File 'lib/url_verifier/run_curler.rb', line 76 def evaluate_curl_err(curl_err) curl_err == "Error: Timeout" || curl_err == "Error: Host" ? timeout = @timeout_limit : timeout = 0 end |
#evaluate_formatted_url(url_hash) ⇒ Object
52 53 54 |
# File 'lib/url_verifier/run_curler.rb', line 52 def evaluate_formatted_url(url_hash) url_hash = url_hash.merge({url_sts: 'Invalid', wx_date: Time.now }) end |
#merge_url_hash(url_hash) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/url_verifier/run_curler.rb', line 39 def merge_url_hash(url_hash) url_hash_fields = { verified_url: nil, url_redirected: false, response_code: nil, url_sts: nil, url_date: Time.now, wx_date: nil, timeout: 0 } url_hash.merge(url_hash_fields) end |
#process_valid_curl_response(url_hash, curl_result) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/url_verifier/run_curler.rb', line 80 def process_valid_curl_response(url_hash, curl_result) curl_result[:verified_url].present? ? url_sts = 'Valid' : url_sts = "Error: Nil" valid_hash = { verified_url: curl_result[:verified_url], url_sts: url_sts, response_code: curl_result[:response_code], timeout: 0 } url_hash = url_hash.merge(valid_hash) end |
#send_to_curl(url_hash) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/url_verifier/run_curler.rb', line 63 def send_to_curl(url_hash) curl_result = @curler.start_curl(url_hash[:url_f], @timeout_limit) curl_err = curl_result[:curl_err] if curl_err.present? url_hash = url_hash.merge({ url_sts: curl_err, timeout: evaluate_curl_err(curl_err) }) else url_hash = process_valid_curl_response(url_hash, curl_result) end url_hash end |
#verify_url(url) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/url_verifier/run_curler.rb', line 24 def verify_url(url) url_hash = @web_formatter.format_url(url) url_hash = merge_url_hash(url_hash) if url_hash[:url_f].present? url_hash = send_to_curl(url_hash) url_hash = check_for_redirect(url_hash) else url_hash = evaluate_formatted_url(url_hash) end puts url_hash.inspect url_hash end |
#verify_urls(urls = []) ⇒ Object
20 21 22 |
# File 'lib/url_verifier/run_curler.rb', line 20 def verify_urls(urls=[]) url_hashes = urls.map { |url| verify_url(url) } end |