Class: NHK::Easy::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/nhk-easy-ruby.rb

Instance Method Summary collapse

Instance Method Details

#news_listObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/nhk-easy-ruby.rb', line 10

def news_list
  # Encode ascii -> utf-8 and remove bom
  data = Net::HTTP
    .get(BASE_URI+"news-list.json")
    .force_encoding('UTF-8')
    .gsub("\xEF\xBB\xBF", '')

  json = Parser.new(data).parse!
  news_list = NewsList.new
  json.map do |list|
    list.keys.each do |date|
      list[date].each do |item|
        news_list.entries << News.new(date: date, item: item)
      end
    end
  end

  return news_list
end