Module: Moocher::Domain

Included in:
Resource
Defined in:
lib/moocher/domains.rb

Instance Method Summary collapse

Instance Method Details

#domain_blacklisted?(domain_name, details: false) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/moocher/domains.rb', line 6

def domain_blacklisted?(domain_name, details: false)
  return "Domain doesn't seem to be valid." if (domain_name =~ /^((http|https):\/\/)?[a-z0-9]*(\.?[a-z0-9]+)\.[a-z]{2,5}(:[0-9]{1,5})?(\/.)?$/ix).nil?
  base_url = 'https://api.moocher.io/baddomain/'
  unless details
    response = HTTParty.get(base_url + domain_name)
    response.success?
  else
    if details == true
      response = HTTParty.get("https://api.moocher.io/baddomain/#{domain_name}", headers: {"Content-Type": "application/json"})
      return response.parsed_response
    else
      "'details:' is by default set to false. You can only be set it to true."
    end
  end
end