Class: Osakana::DNPedia

Inherits:
Object
  • Object
show all
Defined in:
lib/osakana/dnpedia.rb

Constant Summary collapse

BASE_URL =
"https://dnpedia.com/tlds/ajax.php"
DEFAULT_HEADERS =
{
  "Accept-Encoding" => "gzip",
  "Referer" => "https://dnpedia.com/tlds/search.php",
  "X-Requested-With" => "XMLHttpRequest",
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.search(keyword) ⇒ Object



63
64
65
# File 'lib/osakana/dnpedia.rb', line 63

def self.search(keyword)
  new.search(keyword)
end

Instance Method Details

#parse(body) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/osakana/dnpedia.rb', line 45

def parse(body)
  begin
    json = JSON.parse(body)
  rescue StandardError => _
    return { domains: [] }
  end

  rows = json["rows"]
  rows.map do |row|
    name = row.dig("name")
    zoneid = row.dig("zoneid")
    domain = [name, zoneid].join(".")

    date = row["thedate"]
    Website.new(domain: domain, date: date)
  end
end

#payload(keyword) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/osakana/dnpedia.rb', line 17

def payload(keyword)
  {
    cmd: "search",
    columns: "id,name,zoneid,length,idn,thedate,ipv4,ipasname,ipasnumber,ipchecked,",
    ecf: "name",
    ecv: "~%#{keyword}%",
    days: "1",
    mode: "added",
    _search: "false",
    nd: "1547680980461",
    rows: "500",
    page: "1",
    sidx: "length",
    sord: "asc"
  }
end

#search(keyword) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/osakana/dnpedia.rb', line 34

def search(keyword)
  res = HTTP.headers(DEFAULT_HEADERS).get(BASE_URL, params: payload(keyword))
  return {} unless res.code == 200

  sio = StringIO.new(res.body)
  gz = Zlib::GzipReader.new(sio)
  body = gz.read

  parse body
end