Class: Osakana::Ayashige

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

Constant Summary collapse

BASE_URL =
"https://ayashige.herokuapp.com/feed"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.lookup(keyword) ⇒ Object



26
27
28
# File 'lib/osakana/ayashige.rb', line 26

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

Instance Method Details

#lookup(keyword) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/osakana/ayashige.rb', line 10

def lookup(keyword)
  res = HTTP.get(BASE_URL)
  return [] unless res.code == 200

  websites = []
  json = JSON.parse(res.body.to_s)
  json.each do |item|
    domain = item.dig("domain") || ""
    updated_on = item.dig("updated_on") || ""
    next unless domain.include?(keyword)

    websites << Website.new(domain: domain, date: updated_on)
  end
  websites
end